From 9c6c9f10a27d0993636b453f39d8934c95c5c2b2 Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 23 Apr 2024 18:14:47 +0800 Subject: feat: builtin models can be overwrited by models config (#429) --- src/client/cohere.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'src/client/cohere.rs') diff --git a/src/client/cohere.rs b/src/client/cohere.rs index bfea105..445c145 100644 --- a/src/client/cohere.rs +++ b/src/client/cohere.rs @@ -1,6 +1,6 @@ use super::{ json_stream, message::*, patch_system_message, Client, CohereClient, ExtraConfig, Model, - PromptType, ReplyHandler, SendData, + ModelConfig, PromptType, ReplyHandler, SendData, }; use crate::utils::PromptKind; @@ -23,6 +23,8 @@ const MODELS: [(&str, usize, &str); 2] = [ pub struct CohereConfig { pub name: Option, pub api_key: Option, + #[serde(default)] + pub models: Vec, pub extra: Option, } @@ -47,23 +49,12 @@ impl Client for CohereClient { } impl CohereClient { + list_models_fn!(CohereConfig, &MODELS); config_get_fn!(api_key, get_api_key); pub const PROMPTS: [PromptType<'static>; 1] = [("api_key", "API Key:", false, PromptKind::String)]; - pub fn list_models(local_config: &CohereConfig) -> Vec { - 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 { let api_key = self.get_api_key().ok(); @@ -182,7 +173,7 @@ pub(crate) fn build_body(data: SendData, model: &Model) -> Result { "model": &model.name, "message": message, }); - + if let Some(max_tokens) = model.max_output_tokens { body["max_tokens"] = max_tokens.into(); } -- cgit v1.2.3