Skip to content

Commit

Permalink
Merge branch 'main' into fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Nov 29, 2024
2 parents c6e965c + a51cfde commit d7fbf83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/client/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/render/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,5 @@ fn split_line_tail(text: &str) -> (&str, &str) {

fn need_rows(text: &str, columns: u16) -> u16 {
let buffer_width = display_width(text).max(1) as u16;
(buffer_width + columns - 1) / columns
buffer_width.div_ceil(columns)
}

0 comments on commit d7fbf83

Please sign in to comment.