From fe35cfd9419302f01baf9672493c0b0a4b41d889 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 13 Jan 2024 19:52:07 +0800 Subject: feat: supports model capabilities (#297) 1. automatically switch to the model that has the necessary capabilities. 2. throw an error if the client does not have a model with the necessary capabilities --- src/client/ollama.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/client/ollama.rs') diff --git a/src/client/ollama.rs b/src/client/ollama.rs index fc6e148..0705f2e 100644 --- a/src/client/ollama.rs +++ b/src/client/ollama.rs @@ -1,9 +1,9 @@ use super::{ - message::*, patch_system_message, Client, ExtraConfig, Model, OllamaClient, PromptType, - SendData, TokensCountFactors, + message::*, patch_system_message, Client, ExtraConfig, Model, ModelConfig, OllamaClient, + PromptType, SendData, TokensCountFactors, }; -use crate::{config::GlobalConfig, render::ReplyHandler, utils::PromptKind}; +use crate::{render::ReplyHandler, utils::PromptKind}; use anyhow::{anyhow, bail, Result}; use async_trait::async_trait; @@ -20,21 +20,13 @@ pub struct OllamaConfig { pub api_base: String, pub api_key: Option, pub chat_endpoint: Option, - pub models: Vec, + pub models: Vec, pub extra: Option, } -#[derive(Debug, Clone, Deserialize)] -pub struct LocalAIModel { - name: String, - max_tokens: Option, -} - #[async_trait] impl Client for OllamaClient { - fn config(&self) -> (&GlobalConfig, &Option) { - (&self.global_config, &self.config.extra) - } + client_common_fns!(); async fn send_message_inner(&self, client: &ReqwestClient, data: SendData) -> Result { let builder = self.request_builder(client, data)?; @@ -75,6 +67,7 @@ impl OllamaClient { .iter() .map(|v| { Model::new(client_name, &v.name) + .set_capabilities(v.capabilities) .set_max_tokens(v.max_tokens) .set_tokens_count_factors(TOKENS_COUNT_FACTORS) }) -- cgit v1.2.3