Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/assistant/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,18 @@ pub fn first_keyed(config: impl Fn(&str) -> Config) -> Option<&'static str> {
PRESETS.iter().find(|p| !p.login && p.id != "ollama-cloud" && !config(p.id).key.is_empty()).map(|p| p.id)
}

/// Whether the web app can use the provider: a sign-in needs a server on this computer, and
/// ollama.com refuses requests from web pages (its CORS preflight).
pub fn works_in_browser(p: &Preset) -> bool {
!p.login && p.id != "ollama-cloud"
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
}

/// Whether a saved or environment choice of provider can be used: one that exists and, in the web
/// app (`web`), [`works_in_browser`]. A choice that can't falls back to the default.
pub fn usable_choice(id: &str, web: bool) -> bool {
preset(id).is_some_and(|p| !web || works_in_browser(p))
}

/// The provider a command-line run uses: the explicit choice, then the environment's choice, then
/// the first provider with an environment key, then (only when `saved` has the desktop's
/// preferences) the one the desktop app uses, else `ollama`. Environment credentials win over the
Expand Down
17 changes: 17 additions & 0 deletions crates/assistant/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5626,6 +5626,23 @@ fn ollama_cloud_sends_chat_and_model_requests_to_ollama_com_with_a_bearer_key()
assert_eq!(parse_models(Api::OpenAi, &listed.unwrap()), Ok(vec!["gemma4:31b".to_string(), "gpt-oss:120b".to_string()]));
}

#[test]
fn the_web_app_offers_only_providers_a_web_page_can_reach() {
// ollama.com refuses the browser's CORS preflight, and a ChatGPT sign-in needs the desktop.
let offered: Vec<&str> = PRESETS.iter().filter(|p| works_in_browser(p)).map(|p| p.id).collect();
assert!(!offered.contains(&"ollama-cloud") && !offered.contains(&"chatgpt"), "{offered:?}");
assert!(["anthropic", "openai", "gemini", "openrouter", "ollama", "custom", "mistral"].iter().all(|id| offered.contains(id)));
}

#[test]
fn a_saved_choice_the_web_app_cannot_use_is_not_restored_there() {
// Saved before the web app stopped listing it: the web app falls back instead.
assert!(!usable_choice("ollama-cloud", true) && !usable_choice("chatgpt", true));
assert!(usable_choice("ollama-cloud", false) && usable_choice("chatgpt", false));
assert!(usable_choice("mistral", true) && usable_choice("ollama", true));
assert!(!usable_choice("retired", false) && !usable_choice("retired", true));
}

#[test]
fn ollama_cloud_runs_a_tool_call_and_answers() {
let mut s = sample();
Expand Down
3 changes: 2 additions & 1 deletion crates/ui-egui/src/assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ pub(crate) fn ensure_loaded(app: &mut RustGisApp, ctx: &egui::Context) {
app.assistant.remember_key = provider::remembers_keys(pref(app, provider::REMEMBER_KEY_PREF).as_deref());
let provider = pref(app, provider::PROVIDER_PREF)
.or_else(|| std::env::var("RUSTGIS_ASSISTANT_PROVIDER").ok())
.filter(|p| provider::preset(p).is_some())
// One saved before the web app stopped offering it (Ollama Cloud) falls back there.
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
.filter(|p| provider::usable_choice(p, cfg!(target_arch = "wasm32")))
// The first provider with a key in the environment (a ChatGPT sign-in and Ollama Cloud are
// chosen, not assumed).
.or_else(|| provider::first_keyed(Config::from_env).map(str::to_string))
Expand Down
5 changes: 3 additions & 2 deletions crates/ui-egui/src/assistantpane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ fn provider_settings(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, cfg: &mut Co
.width(180.0)
.show_ui(ui, |ui| {
for p in PRESETS {
// Signing in needs the browser and a server on this computer: the desktop app.
if p.login && cfg!(target_arch = "wasm32") {
// Signing in needs the browser and a server on this computer, and ollama.com
// refuses web pages: the desktop app.
if !provider::usable_choice(p.id, cfg!(target_arch = "wasm32")) {
continue;
}
if ui.selectable_label(cfg.provider == p.id, tl!(p.label)).clicked() && cfg.provider != p.id {
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/assistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ Plain HTTP is only used for servers on your computer or local network.
In the web app, the browser calls the provider directly. Anthropic, OpenAI, Gemini,
OpenRouter, Requesty, TrustedRouter, Opper and Mistral accept that; a local Ollama server must allow the page's origin
(`OLLAMA_ORIGINS=https://web.rustgis.app ollama serve`). Ollama Cloud refuses requests from
web pages, so in the web app use its models through a local Ollama server signed in with
`ollama signin`.
web pages, so the web app doesn't list it: use its models there through a local Ollama server
signed in with `ollama signin`.

## Retries and long conversations

Expand Down
Loading