diff options
| author | sigoden <sigoden@gmail.com> | 2024-11-29 09:26:39 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-29 09:26:39 +0800 |
| commit | a51cfde28bd1664b55ea31686ac1def018fc0bd7 (patch) | |
| tree | a1a0b7c406ad1d4ffbb3465afb4c93cd4d412166 /src/client/macros.rs | |
| parent | 59df81b41cc91d93da465e32a9500ee614b18c11 (diff) | |
| download | aichat-a51cfde28bd1664b55ea31686ac1def018fc0bd7.tar.gz | |
chore: clippy for the new rust version (#1018)
Diffstat (limited to 'src/client/macros.rs')
| -rw-r--r-- | src/client/macros.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/client/macros.rs b/src/client/macros.rs index ee710c3..0543cd6 100644 --- a/src/client/macros.rs +++ b/src/client/macros.rs @@ -98,21 +98,20 @@ macro_rules! register_client { anyhow::bail!("Unknown client '{}'", client) } - static mut ALL_CLIENT_MODELS: Option<Vec<$crate::client::Model>> = None; + static ALL_CLIENT_MODELS: std::sync::OnceLock<Vec<$crate::client::Model>> = std::sync::OnceLock::new(); pub fn list_models(config: &$crate::config::Config) -> Vec<&'static $crate::client::Model> { - if unsafe { ALL_CLIENT_MODELS.is_none() } { - let models: Vec<_> = config + let models = ALL_CLIENT_MODELS.get_or_init(|| { + config .clients .iter() .flat_map(|v| match v { $(ClientConfig::$config(c) => $client::list_models(c),)+ ClientConfig::Unknown => vec![], }) - .collect(); - unsafe { ALL_CLIENT_MODELS = Some(models) }; - } - unsafe { ALL_CLIENT_MODELS.as_ref().unwrap().iter().collect() } + .collect() + }); + models.iter().collect() } pub fn list_chat_models(config: &$crate::config::Config) -> Vec<&'static $crate::client::Model> { |
