allow openai to be used to name named compatible providers

This commit is contained in:
Michael Neale
2025-11-10 16:12:33 +11:00
parent 7bb36618d8
commit 81cd956c20
4 changed files with 61 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ pub struct OpenAIProvider {
base_url: String,
max_tokens: Option<u32>,
_temperature: Option<f32>,
name: String,
}
impl OpenAIProvider {
@@ -31,6 +32,24 @@ impl OpenAIProvider {
base_url: Option<String>,
max_tokens: Option<u32>,
temperature: Option<f32>,
) -> Result<Self> {
Self::new_with_name(
"openai".to_string(),
api_key,
model,
base_url,
max_tokens,
temperature,
)
}
pub fn new_with_name(
name: String,
api_key: String,
model: Option<String>,
base_url: Option<String>,
max_tokens: Option<u32>,
temperature: Option<f32>,
) -> Result<Self> {
Ok(Self {
client: Client::new(),
@@ -39,6 +58,7 @@ impl OpenAIProvider {
base_url: base_url.unwrap_or_else(|| "https://api.openai.com/v1".to_string()),
max_tokens,
_temperature: temperature,
name,
})
}
@@ -353,7 +373,7 @@ impl LLMProvider for OpenAIProvider {
}
fn name(&self) -> &str {
"openai"
&self.name
}
fn model(&self) -> &str {
@@ -492,4 +512,4 @@ struct OpenAIDeltaToolCall {
struct OpenAIDeltaFunction {
name: Option<String>,
arguments: Option<String>,
}
}