Skip to content

Commit

Permalink
tweak uneccessary clone
Browse files Browse the repository at this point in the history
  • Loading branch information
neowu committed Jul 16, 2024
1 parent edeec99 commit 918293e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/azure/chatgpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<L: ChatListener> ChatGPT<L> {
.iter()
.map(|f| Tool {
r#type: "function".to_string(),
function: f.clone(),
function: Rc::clone(f),
})
.collect(),
);
Expand Down
2 changes: 1 addition & 1 deletion src/azure/chatgpt_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl ChatRequestMessage {
#[derive(Debug, Serialize)]
pub struct Tool {
pub r#type: String,
pub function: Function,
pub function: Rc<Function>,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion src/gcloud/gemini_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Content {
#[derive(Debug, Serialize)]
pub struct Tool {
#[serde(rename = "functionDeclarations")]
pub function_declarations: Vec<Function>,
pub function_declarations: Vec<Rc<Function>>,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
7 changes: 4 additions & 3 deletions src/llm/function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::Arc;

use serde::Serialize;
Expand All @@ -8,7 +9,7 @@ use tracing::info;
use crate::util::exception::Exception;

// both openai and gemini shares same openai schema
#[derive(Debug, Serialize, Clone)]
#[derive(Debug, Serialize)]
pub struct Function {
pub name: String,
pub description: String,
Expand All @@ -19,7 +20,7 @@ pub struct Function {
pub type FunctionImplementation = dyn Fn(serde_json::Value) -> serde_json::Value + Send + Sync;

pub struct FunctionStore {
pub declarations: Vec<Function>,
pub declarations: Vec<Rc<Function>>,
pub implementations: HashMap<String, Arc<Box<FunctionImplementation>>>,
}

Expand All @@ -33,7 +34,7 @@ impl FunctionStore {

pub fn add(&mut self, function: Function, implementation: Box<FunctionImplementation>) {
let name = function.name.to_string();
self.declarations.push(function);
self.declarations.push(Rc::new(function));
self.implementations.insert(name, Arc::new(implementation));
}

Expand Down

0 comments on commit 918293e

Please sign in to comment.