MCPcopy Create free account
hub / github.com/GCWing/BitFun / show_model_selector

Method show_model_selector

src/apps/cli/src/modes/chat.rs:2083–2139  ·  view source on GitHub ↗

Show model selector popup with all available models

(
        &self,
        chat_view: &mut ChatView,
        chat_state: &mut ChatState,
        rt_handle: &tokio::runtime::Handle,
    )

Source from the content-addressed store, hash-verified

2081
2082 /// Show model selector popup with all available models
2083 fn show_model_selector(
2084 &self,
2085 chat_view: &mut ChatView,
2086 chat_state: &mut ChatState,
2087 rt_handle: &tokio::runtime::Handle,
2088 ) {
2089 let agent_type = self.agent_type.clone();
2090 let result = tokio::task::block_in_place(|| {
2091 rt_handle.block_on(async {
2092 let config_service = match GlobalConfigManager::get_service().await {
2093 Ok(s) => s,
2094 Err(e) => {
2095 tracing::error!("Failed to get config service: {}", e);
2096 return None;
2097 }
2098 };
2099
2100 let models: Vec<bitfun_core::service::config::AIModelConfig> =
2101 config_service.get_ai_models().await.ok()?;
2102 let global_config: bitfun_core::service::config::GlobalConfig =
2103 config_service.get_config(None).await.ok()?;
2104
2105 // Get current model ID
2106 let current_model_id = global_config
2107 .ai
2108 .agent_models
2109 .get(&agent_type)
2110 .cloned()
2111 .or_else(|| global_config.ai.default_models.primary.clone());
2112
2113 // Convert to ModelItem list (only enabled models)
2114 let model_items: Vec<ModelItem> = models
2115 .into_iter()
2116 .filter(|m| m.enabled)
2117 .map(|m| ModelItem {
2118 id: m.id,
2119 name: m.name,
2120 provider: m.provider,
2121 model_name: m.model_name,
2122 })
2123 .collect();
2124
2125 Some((model_items, current_model_id))
2126 })
2127 });
2128
2129 match result {
2130 Some((models, current_id)) if !models.is_empty() => {
2131 chat_view.show_model_selector(models, current_id);
2132 }
2133 _ => {
2134 chat_state.add_system_message(
2135 "No available models found. Please configure models first.".to_string(),
2136 );
2137 }
2138 }
2139 }
2140

Callers 2

handle_palette_actionMethod · 0.45
handle_commandMethod · 0.45

Calls 8

get_ai_modelsMethod · 0.80
collectMethod · 0.80
add_system_messageMethod · 0.80
cloneMethod · 0.45
okMethod · 0.45
get_configMethod · 0.45
getMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected