Skip to content

Commit 6074595

Browse files
committed
Use OpenAI Config
1 parent b809b38 commit 6074595

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/llm/litellm.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ use async_openai::Client as OpenAIClient;
44
pub use super::openai::Client;
55

66
impl Client {
7-
pub async fn new(spec: super::LlmSpec) -> anyhow::Result<Self> {
7+
pub async fn new_litellm(spec: super::LlmSpec) -> anyhow::Result<Self> {
88
let address = spec.address.clone().unwrap_or_else(|| "http://127.0.0.1:4000".to_string());
99
let api_key = std::env::var("LITELLM_API_KEY").ok();
1010
let mut config = OpenAIConfig::new().with_api_base(address);
1111
if let Some(api_key) = api_key {
1212
config = config.with_api_key(api_key);
1313
}
14-
Ok(Self {
15-
client: OpenAIClient::with_config(config),
16-
model: spec.model,
17-
})
14+
Ok(Client::from_parts(OpenAIClient::with_config(config), spec.model))
1815
}
1916
}

src/llm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub async fn new_llm_generation_client(spec: LlmSpec) -> Result<Box<dyn LlmGener
7474
Box::new(anthropic::Client::new(spec).await?) as Box<dyn LlmGenerationClient>
7575
}
7676
LlmApiType::LiteLlm => {
77-
Box::new(litellm::Client::new(spec).await?) as Box<dyn LlmGenerationClient>
77+
Box::new(litellm::Client::new_litellm(spec).await?) as Box<dyn LlmGenerationClient>
7878
}
7979
};
8080
Ok(client)

src/llm/openai.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ pub struct Client {
2020
}
2121

2222
impl Client {
23+
pub(crate) fn from_parts(client: async_openai::Client<OpenAIConfig>, model: String) -> Self {
24+
Self { client, model }
25+
}
26+
2327
pub async fn new(spec: super::LlmSpec) -> Result<Self> {
2428
if let Some(address) = spec.address {
2529
api_bail!("OpenAI doesn't support custom API address: {address}");

0 commit comments

Comments
 (0)