From 918293e63e3ae5dd397246fd8d89311c5bfa83c6 Mon Sep 17 00:00:00 2001 From: neo <1100909+neowu@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:13:00 +0800 Subject: [PATCH] tweak uneccessary clone --- src/azure/chatgpt.rs | 2 +- src/azure/chatgpt_api.rs | 2 +- src/gcloud/gemini_api.rs | 2 +- src/llm/function.rs | 7 ++++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/azure/chatgpt.rs b/src/azure/chatgpt.rs index 0611c2d..2ded42a 100644 --- a/src/azure/chatgpt.rs +++ b/src/azure/chatgpt.rs @@ -53,7 +53,7 @@ impl ChatGPT { .iter() .map(|f| Tool { r#type: "function".to_string(), - function: f.clone(), + function: Rc::clone(f), }) .collect(), ); diff --git a/src/azure/chatgpt_api.rs b/src/azure/chatgpt_api.rs index 2a67494..8a259e1 100644 --- a/src/azure/chatgpt_api.rs +++ b/src/azure/chatgpt_api.rs @@ -130,7 +130,7 @@ impl ChatRequestMessage { #[derive(Debug, Serialize)] pub struct Tool { pub r#type: String, - pub function: Function, + pub function: Rc, } #[derive(Debug, Serialize, Deserialize)] diff --git a/src/gcloud/gemini_api.rs b/src/gcloud/gemini_api.rs index 0fe6aee..b820c56 100644 --- a/src/gcloud/gemini_api.rs +++ b/src/gcloud/gemini_api.rs @@ -82,7 +82,7 @@ impl Content { #[derive(Debug, Serialize)] pub struct Tool { #[serde(rename = "functionDeclarations")] - pub function_declarations: Vec, + pub function_declarations: Vec>, } #[derive(Debug, Serialize, Deserialize)] diff --git a/src/llm/function.rs b/src/llm/function.rs index 9ab605e..b1f2787 100644 --- a/src/llm/function.rs +++ b/src/llm/function.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::rc::Rc; use std::sync::Arc; use serde::Serialize; @@ -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, @@ -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, + pub declarations: Vec>, pub implementations: HashMap>>, } @@ -33,7 +34,7 @@ impl FunctionStore { pub fn add(&mut self, function: Function, implementation: Box) { let name = function.name.to_string(); - self.declarations.push(function); + self.declarations.push(Rc::new(function)); self.implementations.insert(name, Arc::new(implementation)); }