Skip to content

Commit a0ac1d8

Browse files
authored
Merge pull request #16 from CortexLM/fix/models-command-fetch-before-pick
fix: /models command shows 'No models available' even when logged in
2 parents a06e511 + 1ecd84e commit a0ac1d8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/cortex-tui/src/runner/event_loop/commands.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,24 @@ impl EventLoop {
391391
self.handle_history();
392392
}
393393
"models:fetch-and-pick" => {
394+
// First, fetch models from the backend to populate the cache
395+
if let Some(pm) = &self.provider_manager {
396+
// Need to acquire write lock to call fetch_models()
397+
match pm.try_write() {
398+
Ok(mut manager) => {
399+
if let Err(e) = manager.fetch_models().await {
400+
tracing::warn!("Failed to fetch models: {}", e);
401+
self.app_state
402+
.toasts
403+
.warning("Could not fetch models, showing cached list");
404+
}
405+
}
406+
Err(_) => {
407+
tracing::warn!("Could not acquire write lock for provider manager");
408+
}
409+
}
410+
}
411+
// Now open the modal with freshly fetched (or cached) models
394412
self.handle_open_modal(ModalType::ModelPicker).await;
395413
}
396414
_ => {

0 commit comments

Comments
 (0)