Skip to content

Commit

Permalink
support gemini pro 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
neowu committed Apr 12, 2024
1 parent 643ea79 commit e1f9259
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/gcloud/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
};
Expand Down
16 changes: 11 additions & 5 deletions src/openai/chatgpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,7 +104,7 @@ impl ChatGPT {
Ok(())
}

async fn process(&mut self, handler: &dyn ChatHandler) -> Result<Option<InternalEvent>, Box<dyn Error>> {
async fn process(&mut self, handler: &dyn ChatHandler) -> Result<Option<InternalEvent>, Exception> {
let source = self.call_api().await?;

let (tx, mut rx) = channel(64);
Expand Down Expand Up @@ -135,7 +135,7 @@ impl ChatGPT {
Ok(None)
}

async fn call_api(&mut self) -> Result<EventSource, Box<dyn Error>> {
async fn call_api(&mut self) -> Result<EventSource, Exception> {
let has_function = !self.function_implementations.is_empty();

let request = ChatRequest {
Expand All @@ -154,7 +154,7 @@ impl ChatGPT {
Ok(source)
}

async fn post_sse<Request>(&self, request: &Request) -> Result<EventSource, Box<dyn Error>>
async fn post_sse<Request>(&self, request: &Request) -> Result<EventSource, Exception>
where
Request: Serialize + fmt::Debug,
{
Expand All @@ -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<CannotCloneRequestError> for Exception {
fn from(err: CannotCloneRequestError) -> Self {
Exception::new(&err.to_string())
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/util/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit e1f9259

Please sign in to comment.