diff options
| author | sigoden <sigoden@gmail.com> | 2024-04-29 15:34:24 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-29 15:34:24 +0800 |
| commit | c752ba9b272ddf8186f7786ac32a88a410e6eee8 (patch) | |
| tree | cf3058037e13eb2226e5041ddcf3a7f0c5f44a42 /src/client/common.rs | |
| parent | 3a00fb283e4f503901ce198ead65aebc46ae1875 (diff) | |
| download | aichat-c752ba9b272ddf8186f7786ac32a88a410e6eee8.tar.gz | |
feat: `.model` repl completions show max tokens and price (#462)
Diffstat (limited to 'src/client/common.rs')
| -rw-r--r-- | src/client/common.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/client/common.rs b/src/client/common.rs index 842741c..85255ee 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -147,17 +147,22 @@ macro_rules! register_client { anyhow::bail!("Unknown client '{}'", client) } - pub fn list_models(config: &$crate::config::Config) -> Vec<$crate::client::Model> { - config - .clients - .iter() - .flat_map(|v| match v { - $(ClientConfig::$config(c) => $client::list_models(c),)+ - ClientConfig::Unknown => vec![], - }) - .collect() + static mut ALL_CLIENTS: Option<Vec<$crate::client::Model>> = None; + + pub fn list_models(config: &$crate::config::Config) -> Vec<&$crate::client::Model> { + if unsafe { ALL_CLIENTS.is_none() } { + let models: Vec<_> = config + .clients + .iter() + .flat_map(|v| match v { + $(ClientConfig::$config(c) => $client::list_models(c),)+ + ClientConfig::Unknown => vec![], + }) + .collect(); + unsafe { ALL_CLIENTS = Some(models) }; + } + unsafe { ALL_CLIENTS.as_ref().unwrap().iter().collect() } } - }; } |
