From e1f92595f54b0e7f6e052fd6d8787b093ee29ff0 Mon Sep 17 00:00:00 2001 From: neo <1100909+neowu@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:06:32 +0800 Subject: [PATCH] support gemini pro 1.5 --- src/gcloud/vertex.rs | 6 +++--- src/openai/chatgpt.rs | 16 +++++++++++----- src/util/exception.rs | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/gcloud/vertex.rs b/src/gcloud/vertex.rs index ae7e67c..04b777d 100644 --- a/src/gcloud/vertex.rs +++ b/src/gcloud/vertex.rs @@ -131,9 +131,9 @@ impl Vertex { let request = StreamGenerateContent { contents: Cow::from(&self.messages), generation_config: GenerationConfig { - temperature: 0.8, - top_p: 1.0, - max_output_tokens: 800, + temperature: 1.0, + top_p: 0.95, + max_output_tokens: 2048, }, tools: has_function.then(|| Cow::from(&self.tools)), }; diff --git a/src/openai/chatgpt.rs b/src/openai/chatgpt.rs index 25db863..d573745 100644 --- a/src/openai/chatgpt.rs +++ b/src/openai/chatgpt.rs @@ -7,10 +7,10 @@ use std::sync::Arc; use futures::future::join_all; use futures::stream::StreamExt; +use reqwest_eventsource::CannotCloneRequestError; use reqwest_eventsource::Event; use reqwest_eventsource::EventSource; use serde::Serialize; -use serde_json::Value; use tokio::sync::mpsc::channel; use tokio::sync::mpsc::Sender; use tokio::task::JoinHandle; @@ -104,7 +104,7 @@ impl ChatGPT { Ok(()) } - async fn process(&mut self, handler: &dyn ChatHandler) -> Result, Box> { + async fn process(&mut self, handler: &dyn ChatHandler) -> Result, Exception> { let source = self.call_api().await?; let (tx, mut rx) = channel(64); @@ -135,7 +135,7 @@ impl ChatGPT { Ok(None) } - async fn call_api(&mut self) -> Result> { + async fn call_api(&mut self) -> Result { let has_function = !self.function_implementations.is_empty(); let request = ChatRequest { @@ -154,7 +154,7 @@ impl ChatGPT { Ok(source) } - async fn post_sse(&self, request: &Request) -> Result> + async fn post_sse(&self, request: &Request) -> Result where Request: Serialize + fmt::Debug, { @@ -169,7 +169,13 @@ impl ChatGPT { .header("api-key", &self.api_key) .body(body); - Ok(EventSource::new(request).unwrap()) + Ok(EventSource::new(request)?) + } +} + +impl From for Exception { + fn from(err: CannotCloneRequestError) -> Self { + Exception::new(&err.to_string()) } } diff --git a/src/util/exception.rs b/src/util/exception.rs index a86d757..c852d7f 100644 --- a/src/util/exception.rs +++ b/src/util/exception.rs @@ -18,7 +18,8 @@ impl Exception { impl fmt::Debug for Exception { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Exception: {}\ntrace:\n{}", self.message, self.trace) + write!(f, "Exception: {}\n", self.message); + write!(f, "Trace:\n{}", self.trace) } }