summaryrefslogtreecommitdiffstats
path: root/src/client/common.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2025-01-22 20:51:10 +0800
committerGitHub <noreply@github.com>2025-01-22 20:51:10 +0800
commite0417e8d5bebe25476aaafa22a9ee23d9bd61457 (patch)
tree8edcd3aa9bcd1b012a3a429ad6240e6186caef36 /src/client/common.rs
parentdf4440a2a049d26c61a540d3254cd885345fbd6c (diff)
downloadaichat-e0417e8d5bebe25476aaafa22a9ee23d9bd61457.tar.gz
feat: add `--sync-models` cli option (#1114)
Diffstat (limited to 'src/client/common.rs')
-rw-r--r--src/client/common.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/client/common.rs b/src/client/common.rs
index b4d01ce..80f585d 100644
--- a/src/client/common.rs
+++ b/src/client/common.rs
@@ -1,7 +1,7 @@
use super::*;
use crate::{
- config::{GlobalConfig, Input},
+ config::{Config, GlobalConfig, Input},
function::{eval_tool_calls, FunctionDeclaration, ToolCall, ToolResult},
render::render_stream,
utils::*,
@@ -20,7 +20,9 @@ use tokio::sync::mpsc::unbounded_channel;
const MODELS_YAML: &str = include_str!("../../models.yaml");
lazy_static::lazy_static! {
- pub static ref ALL_PREDEFINED_MODELS: Vec<PredefinedModels> = serde_yaml::from_str(MODELS_YAML).unwrap();
+ pub static ref ALL_PROVIDER_MODELS: Vec<ProviderModels> = {
+ Config::loal_models_override().ok().unwrap_or_else(|| serde_yaml::from_str(MODELS_YAML).unwrap())
+ };
static ref ESCAPE_SLASH_RE: Regex = Regex::new(r"(?<!\\)/").unwrap();
}
@@ -338,14 +340,15 @@ pub fn create_config(prompts: &[PromptAction], client: &str) -> Result<(String,
}
pub fn create_openai_compatible_client_config(client: &str) -> Result<Option<(String, Value)>> {
- let api_base = super::OPENAI_COMPATIBLE_PLATFORMS
+ let api_base = super::OPENAI_COMPATIBLE_PROVIDERS
.into_iter()
.find(|(name, _)| client == *name)
.map(|(_, api_base)| api_base)
.unwrap_or("http(s)://{API_ADDR}/v1");
let name = if client == OpenAICompatibleClient::NAME {
- prompt_input_string("Provider Name", true, None)?
+ let value = prompt_input_string("Provider Name", true, None)?;
+ value.replace(' ', "-")
} else {
client.to_string()
};
@@ -548,7 +551,7 @@ fn set_client_config(list: &[PromptAction], client_config: &mut Value, client: &
}
fn set_client_models_config(client_config: &mut Value, client: &str) -> Result<()> {
- if ALL_PREDEFINED_MODELS.iter().any(|v| v.platform == client) {
+ if ALL_PROVIDER_MODELS.iter().any(|v| v.provider == client) {
return Ok(());
}