Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Fontanier committed Dec 9, 2024
1 parent 4cdbf97 commit 55c1ed3
Show file tree
Hide file tree
Showing 11 changed files with 615 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub mod providers {
}
pub mod anthropic;
pub mod google_ai_studio;
pub mod togetherai;
}
pub mod http {
pub mod request;
Expand Down
6 changes: 6 additions & 0 deletions core/src/providers/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,13 +1482,17 @@ pub async fn chat_completion(

let req = req.json(&body);

println!("\n\nREQBODY: {:?}\n\n", body);
println!("\n\nURI: {:?}\n\n", uri);

let res = match timeout(Duration::new(180, 0), req.send()).await {
Ok(Ok(res)) => res,
Ok(Err(e)) => Err(e)?,
Err(_) => Err(anyhow!("Timeout sending request to OpenAI after 180s"))?,
};

let res_headers = res.headers();
println!("\n\nRESHEADERS: {:?}\n\n", res_headers);
let request_id = match res_headers.get("x-request-id") {
Some(request_id) => Some(request_id.to_str()?.to_string()),
None => None,
Expand All @@ -1500,6 +1504,8 @@ pub async fn chat_completion(
Err(_) => Err(anyhow!("Timeout reading response from OpenAI after 180s"))?,
};

println!("RESBODY: {:?}", body);

let mut b: Vec<u8> = vec![];
body.reader().read_to_end(&mut b)?;
let c: &[u8] = &b;
Expand Down
6 changes: 6 additions & 0 deletions core/src/providers/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use std::fmt;
use std::str::FromStr;
use std::time::Duration;

use super::togetherai::TogetherAIProvider;

#[derive(Debug, Clone, Copy, Serialize, PartialEq, ValueEnum, Deserialize)]
#[serde(rename_all = "lowercase")]
#[clap(rename_all = "lowercase")]
Expand All @@ -26,6 +28,7 @@ pub enum ProviderID {
Mistral,
#[serde(rename = "google_ai_studio")]
GoogleAiStudio,
TogetherAI,
}

impl fmt::Display for ProviderID {
Expand All @@ -36,6 +39,7 @@ impl fmt::Display for ProviderID {
ProviderID::Anthropic => write!(f, "anthropic"),
ProviderID::Mistral => write!(f, "mistral"),
ProviderID::GoogleAiStudio => write!(f, "google_ai_studio"),
ProviderID::TogetherAI => write!(f, "togetherai"),
}
}
}
Expand All @@ -49,6 +53,7 @@ impl FromStr for ProviderID {
"anthropic" => Ok(ProviderID::Anthropic),
"mistral" => Ok(ProviderID::Mistral),
"google_ai_studio" => Ok(ProviderID::GoogleAiStudio),
"togetherai" => Ok(ProviderID::TogetherAI),
_ => Err(ParseError::with_message(
"Unknown provider ID \
(possible values: openai, azure_openai, anthropic, mistral, google_ai_studio)",
Expand Down Expand Up @@ -151,5 +156,6 @@ pub fn provider(t: ProviderID) -> Box<dyn Provider + Sync + Send> {
ProviderID::GoogleAiStudio => Box::new(GoogleAiStudioProvider::new()),
ProviderID::Mistral => Box::new(MistralProvider::new()),
ProviderID::OpenAI => Box::new(OpenAIProvider::new()),
ProviderID::TogetherAI => Box::new(TogetherAIProvider::new()),
}
}
Loading

0 comments on commit 55c1ed3

Please sign in to comment.