From e0417e8d5bebe25476aaafa22a9ee23d9bd61457 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 22 Jan 2025 20:51:10 +0800 Subject: feat: add `--sync-models` cli option (#1114) --- src/client/common.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/client/common.rs') 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 = serde_yaml::from_str(MODELS_YAML).unwrap(); + pub static ref ALL_PROVIDER_MODELS: Vec = { + Config::loal_models_override().ok().unwrap_or_else(|| serde_yaml::from_str(MODELS_YAML).unwrap()) + }; static ref ESCAPE_SLASH_RE: Regex = Regex::new(r"(? Result<(String, } pub fn create_openai_compatible_client_config(client: &str) -> Result> { - 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(()); } -- cgit v1.2.3