Load current model name from global config for display
(
&self,
chat_state: &mut ChatState,
rt_handle: &tokio::runtime::Handle,
)
| 2005 | |
| 2006 | /// Load current model name from global config for display |
| 2007 | fn load_current_model_name( |
| 2008 | &self, |
| 2009 | chat_state: &mut ChatState, |
| 2010 | rt_handle: &tokio::runtime::Handle, |
| 2011 | ) { |
| 2012 | let agent_type = self.agent_type.clone(); |
| 2013 | let result: Option<String> = tokio::task::block_in_place(|| { |
| 2014 | rt_handle.block_on(async { |
| 2015 | let config_service = GlobalConfigManager::get_service().await.ok()?; |
| 2016 | let models: Vec<bitfun_core::service::config::AIModelConfig> = |
| 2017 | config_service.get_ai_models().await.ok()?; |
| 2018 | let global_config: bitfun_core::service::config::GlobalConfig = |
| 2019 | config_service.get_config(None).await.ok()?; |
| 2020 | |
| 2021 | // Resolve model ID for the current agent |
| 2022 | let model_id = global_config |
| 2023 | .ai |
| 2024 | .agent_models |
| 2025 | .get(&agent_type) |
| 2026 | .cloned() |
| 2027 | .or_else(|| global_config.ai.default_models.primary.clone()) |
| 2028 | .unwrap_or_else(|| "primary".to_string()); |
| 2029 | |
| 2030 | fn provider_display_name( |
| 2031 | model: &bitfun_core::service::config::AIModelConfig, |
| 2032 | ) -> String { |
| 2033 | let raw_name = model.name.trim(); |
| 2034 | let model_name = model.model_name.trim(); |
| 2035 | if !raw_name.is_empty() && !model_name.is_empty() { |
| 2036 | let dashed_suffix = format!(" - {}", model_name); |
| 2037 | let slash_suffix = format!("/{}", model_name); |
| 2038 | if let Some(provider) = raw_name.strip_suffix(&dashed_suffix) { |
| 2039 | return provider.trim().to_string(); |
| 2040 | } |
| 2041 | if let Some(provider) = raw_name.strip_suffix(&slash_suffix) { |
| 2042 | return provider.trim().to_string(); |
| 2043 | } |
| 2044 | } |
| 2045 | if raw_name.is_empty() { |
| 2046 | model.provider.clone() |
| 2047 | } else { |
| 2048 | raw_name.to_string() |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | fn model_display_name( |
| 2053 | model: &bitfun_core::service::config::AIModelConfig, |
| 2054 | ) -> String { |
| 2055 | format!("{} / {}", model.model_name, provider_display_name(model)) |
| 2056 | } |
| 2057 | |
| 2058 | // Find model name |
| 2059 | let model_name = if model_id == "primary" { |
| 2060 | // Resolve primary model |
| 2061 | let primary_id = global_config.ai.default_models.primary.as_deref()?; |
| 2062 | models |
| 2063 | .iter() |
| 2064 | .find(|m| m.id == primary_id) |
no test coverage detected