summaryrefslogtreecommitdiffstats
path: root/src/client/common.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-23 18:14:47 +0800
committerGitHub <noreply@github.com>2024-04-23 18:14:47 +0800
commit9c6c9f10a27d0993636b453f39d8934c95c5c2b2 (patch)
tree268598294b234c7eac87fc70d1e2d1b32ac88a78 /src/client/common.rs
parentd1aafa11153ab689c21c2c57c47da52337d8e8d1 (diff)
downloadaichat-9c6c9f10a27d0993636b453f39d8934c95c5c2b2.tar.gz
feat: builtin models can be overwrited by models config (#429)
Diffstat (limited to 'src/client/common.rs')
-rw-r--r--src/client/common.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/client/common.rs b/src/client/common.rs
index 2206d21..b6ccce7 100644
--- a/src/client/common.rs
+++ b/src/client/common.rs
@@ -86,7 +86,7 @@ macro_rules! register_client {
pub fn ensure_model_capabilities(client: &mut dyn Client, capabilities: $crate::client::ModelCapabilities) -> anyhow::Result<()> {
if !client.model().capabilities.contains(capabilities) {
- let models = client.models();
+ let models = client.list_models();
if let Some(model) = models.into_iter().find(|v| v.capabilities.contains(capabilities)) {
client.set_model(model);
} else {
@@ -137,7 +137,7 @@ macro_rules! client_common_fns {
(&self.global_config, &self.config.extra)
}
- fn models(&self) -> Vec<Model> {
+ fn list_models(&self) -> Vec<Model> {
Self::list_models(&self.config)
}
@@ -197,11 +197,31 @@ macro_rules! config_get_fn {
};
}
+#[macro_export]
+macro_rules! list_models_fn {
+ ($config:ident) => {
+ pub fn list_models(local_config: &$config) -> Vec<Model> {
+ let client_name = Self::name(local_config);
+ Model::from_config(client_name, &local_config.models)
+ }
+ };
+ ($config:ident, $models:expr) => {
+ pub fn list_models(local_config: &$config) -> Vec<Model> {
+ let client_name = Self::name(local_config);
+ if local_config.models.is_empty() {
+ Model::from_static(client_name, $models)
+ } else {
+ Model::from_config(client_name, &local_config.models)
+ }
+ }
+ };
+}
+
#[async_trait]
pub trait Client: Sync + Send {
fn config(&self) -> (&GlobalConfig, &Option<ExtraConfig>);
- fn models(&self) -> Vec<Model>;
+ fn list_models(&self) -> Vec<Model>;
fn model(&self) -> &Model;