From 12d71b37bbf73a2f6fe3c9aa3aeddfa1a9db390e Mon Sep 17 00:00:00 2001
From: tidely <43219534+tidely@users.noreply.github.com>
Date: Fri, 31 Oct 2025 20:12:02 +0200
Subject: [PATCH] ollama: Add button for refreshing available models (#38181)
Closes #17524
This PR adds a button to the bottom right corner of the ollama settings
ui. It resets the available ollama models, also resets the "Connected"
state in the process. This means it can be used to check if the
connection is still valid as well. It's a question whether we should
clear the available models on ALL `fetch_models` calls, since these only
happen during auth anyway.
Ollama is a local model provider which means clicking the refresh button
often only flashes the "not connected" state because the latency of the
request is so low. This accentuates changes in the UI, however I don't
think there's a way around this without adding some rather cumbersome
deferred ui updates.
I've attached the refresh button to the "Connected" `ButtonLike`, since
I don't think automatic UI spacing should separate these elements. I
think this is okay because the "Connected" isn't actually something that
the user can interact with.
Before:
After:
Alternative approach: There was also a suggestion to simply add a entry
to the command palette, however none of the other providers have this
ability currently either so I went with this approach. The current
approach also makes it more discoverable to the user.
Release Notes:
- Added a button for refreshing available ollama models
---------
Co-authored-by: Bennet Bo Fenner 
---
 crates/language_models/src/provider/ollama.rs | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/crates/language_models/src/provider/ollama.rs b/crates/language_models/src/provider/ollama.rs
index 2150966c1af0fdb1bdcc028cba67bcb7b7cbf89f..6341baa6f36db36a180d14c957b49dadd901e9a0 100644
--- a/crates/language_models/src/provider/ollama.rs
+++ b/crates/language_models/src/provider/ollama.rs
@@ -906,6 +906,16 @@ impl Render for ConfigurationView {
                                             .child(Icon::new(IconName::Check).color(Color::Success))
                                             .child(Label::new("Connected"))
                                             .into_any_element(),
+                                    )
+                                    .child(
+                                        IconButton::new("refresh-models", IconName::RotateCcw)
+                                            .tooltip(Tooltip::text("Refresh models"))
+                                            .on_click(cx.listener(|this, _, _, cx| {
+                                                this.state.update(cx, |state, _| {
+                                                    state.fetched_models.clear();
+                                                });
+                                                this.retry_connection(cx);
+                                            })),
                                     ),
                             )
                         } else {