Skip to content

Commit 1ecd84e

Browse files
committed
fix: fetch models before opening model picker
The /models command was showing 'No models available' even when the user was logged in because available_models() only returns cached models. The cache was never populated because fetch_models() was not called before opening the picker. This fix ensures fetch_models() is called first to populate the cache from the backend API before the model picker modal is opened.
1 parent a06e511 commit 1ecd84e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

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)