diff options
| author | sigoden <sigoden@gmail.com> | 2024-09-02 08:23:21 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-02 08:23:21 +0800 |
| commit | 2cba09c064b366ad91c7eda3acbc2030215a1842 (patch) | |
| tree | 467d550c12b2cab8172da7cc3af01903a5b5477a /src/client/common.rs | |
| parent | 6462a587428c38c17cbb6bce440cbf10c966eecc (diff) | |
| download | aichat-2cba09c064b366ad91c7eda3acbc2030215a1842.tar.gz | |
feat: migrate `cloudflare` client to `openai-compatible` (#821)
Diffstat (limited to 'src/client/common.rs')
| -rw-r--r-- | src/client/common.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/client/common.rs b/src/client/common.rs index 684d10e..9d6480a 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -364,7 +364,7 @@ pub fn create_config(prompts: &[PromptAction], client: &str) -> Result<(String, pub fn create_openai_compatible_client_config(client: &str) -> Result<Option<(String, Value)>> { match super::OPENAI_COMPATIBLE_PLATFORMS - .iter() + .into_iter() .find(|(name, _)| client == *name) { None => Ok(None), @@ -372,13 +372,16 @@ pub fn create_openai_compatible_client_config(client: &str) -> Result<Option<(St let mut config = json!({ "type": OpenAICompatibleClient::NAME, "name": name, - "api_base": api_base, }); - let prompts = if ALL_MODELS.iter().any(|v| &v.platform == name) { - vec![("api_key", "API Key:", false, PromptKind::String)] + let mut prompts = vec![]; + if api_base.is_empty() { + prompts.push(("api_base", "API Base:", true, PromptKind::String)); } else { - vec![ - ("api_key", "API Key:", false, PromptKind::String), + config["api_base"] = api_base.into(); + } + prompts.push(("api_key", "API Key:", false, PromptKind::String)); + if !ALL_MODELS.iter().any(|v| v.platform == name) { + prompts.extend([ ("models[].name", "Model Name:", true, PromptKind::String), ( "models[].max_input_tokens", @@ -386,7 +389,7 @@ pub fn create_openai_compatible_client_config(client: &str) -> Result<Option<(St false, PromptKind::Integer, ), - ] + ]); }; let mut model = client.to_string(); set_client_config(&prompts, &mut model, &mut config)?; |
