diff options
| author | sigoden <sigoden@gmail.com> | 2024-04-23 18:14:47 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 18:14:47 +0800 |
| commit | 9c6c9f10a27d0993636b453f39d8934c95c5c2b2 (patch) | |
| tree | 268598294b234c7eac87fc70d1e2d1b32ac88a78 /src/client/openai.rs | |
| parent | d1aafa11153ab689c21c2c57c47da52337d8e8d1 (diff) | |
| download | aichat-9c6c9f10a27d0993636b453f39d8934c95c5c2b2.tar.gz | |
feat: builtin models can be overwrited by models config (#429)
Diffstat (limited to 'src/client/openai.rs')
| -rw-r--r-- | src/client/openai.rs | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/client/openai.rs b/src/client/openai.rs index 535e739..7925ec6 100644 --- a/src/client/openai.rs +++ b/src/client/openai.rs @@ -1,4 +1,4 @@ -use super::{ExtraConfig, Model, OpenAIClient, PromptType, ReplyHandler, SendData}; +use super::{ExtraConfig, Model, ModelConfig, OpenAIClient, PromptType, ReplyHandler, SendData}; use crate::utils::PromptKind; @@ -30,30 +30,21 @@ pub struct OpenAIConfig { pub api_key: Option<String>, pub api_base: Option<String>, pub organization_id: Option<String>, + #[serde(default)] + pub models: Vec<ModelConfig>, pub extra: Option<ExtraConfig>, } openai_compatible_client!(OpenAIClient); impl OpenAIClient { + list_models_fn!(OpenAIConfig, &MODELS); config_get_fn!(api_key, get_api_key); config_get_fn!(api_base, get_api_base); pub const PROMPTS: [PromptType<'static>; 1] = [("api_key", "API Key:", true, PromptKind::String)]; - pub fn list_models(local_config: &OpenAIConfig) -> Vec<Model> { - let client_name = Self::name(local_config); - MODELS - .into_iter() - .map(|(name, max_input_tokens, capabilities)| { - Model::new(client_name, name) - .set_capabilities(capabilities.into()) - .set_max_input_tokens(Some(max_input_tokens)) - }) - .collect() - } - fn request_builder(&self, client: &ReqwestClient, data: SendData) -> Result<RequestBuilder> { let api_key = self.get_api_key()?; let api_base = self.get_api_base().unwrap_or_else(|_| API_BASE.to_string()); |
