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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Every screenshot is RustGIS itself, rendered offscreen by `cargo run -p rustgis-
| **Imagery** | Ortho and reality mapping, pixel classification (k-means, minimum distance, a trainable neural network), mensuration, hosted imagery tiles |
| **Layouts and reports** | Page layouts with map frames, legends, scale bars, grids, bar and column charts and map series; publication sheets and figures in one command, format panes, guides, snapping and element locks; reports with groups, statistics, charts and subreports; vector PDF and SVG, and GeoPDF with [supported map frames](docs/user-guide/layouts.md#layouts) georeferenced; presentations (HTML slideshow, PDF); notebooks (Jupyter in and out) |
| **Sharing** | PNG export at up to 600 DPI; PDF; web map pages, OGC API Features collections, MapLibre styles, glTF and STL scenes, vector and raster PMTiles, the map view as a GeoTIFF placed on the ground (desktop), locators; the web app embedded in a page (`?embed`); project, map and mobile map packages; offline areas with sync |
| **AI Assistant** | Ask about your data or tell the map what to do in plain language, attaching pictures and letting it look at the map and layouts, with Anthropic, OpenAI (a key, or your ChatGPT plan by signing in on the desktop or command line), Gemini, Mistral, OpenRouter and other gateways, Ollama or any OpenAI-compatible model; also `rustgis-cli ask`, and an [MCP server](docs/mcp.md) (`rustgis-cli mcp`) for Claude Code, Cursor, VS Code and other agents; skills; on the desktop, agents such as Claude Code and Codex started from the app, and external AI clients driving the open app; keys optionally remembered in the system keychain on the desktop (in the web app, unencrypted in the browser's storage) |
| **AI Assistant** | Ask about your data or tell the map what to do in plain language, attaching pictures and letting it look at the map and layouts, with Anthropic, OpenAI (a key, or your ChatGPT plan by signing in on the desktop or command line), Gemini, Mistral, OpenRouter and other gateways, Ollama (on your computer or Ollama Cloud) or any OpenAI-compatible model; also `rustgis-cli ask`, and an [MCP server](docs/mcp.md) (`rustgis-cli mcp`) for Claude Code, Cursor, VS Code and other agents; skills; on the desktop, agents such as Claude Code and Codex started from the app, and external AI clients driving the open app; keys optionally remembered in the system keychain on the desktop (in the web app, unencrypted in the browser's storage) |
| **Plugins** | Sandboxed WebAssembly [plugins](docs/plugins.md) add commands, tools and ribbon tabs; install them from [plugins.rustgis.app](https://plugins.rustgis.app) on the desktop, command line and web. Process plugins (desktop and command line) run as programs (with Python environments RustGIS makes), in the background or for the whole session; panels offer trees, dropdowns, date pickers and sliders |
| **Python** | The [`rustgis` package](docs/python.md) on PyPI: the engine in-process, `rustgis.Map` in Jupyter and `rustgis.qt.MapWidget` in Qt applications |
| **Interface** | Layers, Browser and Data Sources panes as tabs, command search (Ctrl+K), keyboard shortcuts, dark mode, custom themes (desktop) and an interface scale, a customizable ribbon and Quick Access Toolbar, linked side-by-side maps, a History pane of tool runs and the session log, autosave and crash recovery (desktop), Check for Updates (desktop), 22 languages |
Expand Down
2 changes: 1 addition & 1 deletion apps/rustgis-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! rustgis-cli run … --strict [--allow dropped.ring] # exit 3 when a command loses data (see the guide's loss codes)
//! rustgis-cli run … --threads 4 # the most threads one piece of work uses (default: the cores, up to 16)
//! rustgis-cli ask [--sample | --project p.rgis | --data f.geojson …] "Which cities have over 10 million people?" \
//! [--provider anthropic|openai|chatgpt|gemini|openrouter|ollama|custom|requesty|trustedrouter|opper|mistral] [--model M] [--base-url URL] [--yes] [--save out.rgis] [--trace log.txt]
//! [--provider anthropic|openai|chatgpt|gemini|openrouter|ollama|custom|requesty|trustedrouter|opper|mistral|ollama-cloud] [--model M] [--base-url URL] [--yes] [--save out.rgis] [--trace log.txt]
//! rustgis-cli ask --sample "Style the countries like this map" --image reference.png # pictures go with the request (up to 4)
//! rustgis-cli ask --models [--provider P] # list the provider's models
//! rustgis-cli ask --accounts | --account CLIENT_ID # list or select a saved registration
Expand Down
20 changes: 18 additions & 2 deletions crates/assistant/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ pub const PRESETS: &[Preset] = &[
key_url: "https://console.mistral.ai/api-keys",
login: false,
},
Preset {
id: "ollama-cloud",
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
description: "Open models that Ollama runs in its cloud, mainly in the United States and at times in Europe. Ollama says it doesn't store or log prompts and responses and doesn't train on them; it keeps usage metadata.",
label: "Ollama Cloud",
api: Api::OpenAi,
base_url: "https://ollama.com/v1",
// In the cloud catalog with tools; direct requests use the catalog's names, without `-cloud`.
model: "gpt-oss:120b",
key_env: &["OLLAMA_API_KEY"],
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
url_env: "",
keyless: false,
key_url: "https://ollama.com/settings/keys",
login: false,
},
];

/// The preset with this id.
Expand Down Expand Up @@ -335,9 +349,11 @@ pub fn saved_provider(prefs: &Map<String, Value>) -> Option<&'static str> {
}

/// The first key-using provider whose API key `config` finds (the environment's, for
/// `Config::from_env`). A sign-in is chosen, not assumed.
/// `Config::from_env`). A sign-in is chosen, not assumed, and so is Ollama Cloud: its
/// `OLLAMA_API_KEY` is often set where only a local Ollama server runs, and alone it must not send
/// requests to ollama.com instead.
pub fn first_keyed(config: impl Fn(&str) -> Config) -> Option<&'static str> {
PRESETS.iter().find(|p| !p.login && !config(p.id).key.is_empty()).map(|p| p.id)
PRESETS.iter().find(|p| !p.login && p.id != "ollama-cloud" && !config(p.id).key.is_empty()).map(|p| p.id)
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
}

/// The provider a command-line run uses: the explicit choice, then the environment's choice, then
Expand Down
58 changes: 58 additions & 0 deletions crates/assistant/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5586,6 +5586,64 @@ fn mistral_lists_models_with_a_bearer_key() {
assert!(req.headers.contains(&("Authorization".into(), "Bearer k".into())));
}

#[test]
fn ollama_cloud_needs_a_key_from_ollama_api_key_and_is_never_chosen_by_it_alone() {
let p = preset("ollama-cloud").expect("the Ollama Cloud preset");
assert_eq!((p.api, p.base_url, p.key_env, p.url_env), (Api::OpenAi, "https://ollama.com/v1", &["OLLAMA_API_KEY"][..], ""));
assert!(!p.keyless && !p.login && p.key_url.starts_with("https://ollama.com/"));
let mut c = cfg("ollama-cloud");
c.key.clear();
assert_eq!(c.missing(), Some("Enter an API key."));
// The local server stays keyless, and an Ollama Cloud key never takes another provider's place.
assert!(preset("ollama").is_some_and(|p| p.keyless && p.key_env.is_empty()));
let keyed = |ids: &'static [&'static str]| {
move |id: &str| Config { key: if ids.contains(&id) { "k".into() } else { String::new() }, ..cfg(id) }
};
assert_eq!(first_keyed(keyed(&["ollama-cloud", "mistral"])), Some("mistral"));
// `OLLAMA_API_KEY` is often set where only a local server runs: on its own it must not move
// requests to ollama.com, so the command line keeps the local default.
assert_eq!(first_keyed(keyed(&["ollama-cloud"])), None);
assert_eq!(choose(None, None, first_keyed(keyed(&["ollama-cloud"])), None), "ollama");
assert_eq!(choose(Some("ollama-cloud"), None, None, None), "ollama-cloud");
}

#[test]
fn ollama_cloud_sends_chat_and_model_requests_to_ollama_com_with_a_bearer_key() {
let s = sample();
let mut a = Agent::new(cfg("ollama-cloud"), &s);
let Step::Send(req) = a.ask("what layers?", &s) else { panic!("expected a request") };
assert_eq!(req.url, "https://ollama.com/v1/chat/completions");
assert!(req.headers.contains(&("Authorization".into(), "Bearer k".into())));
let b = body(&req);
assert_eq!(b["model"], "gpt-oss:120b");
assert!(b["tools"].as_array().is_some_and(|t| t.iter().any(|t| t["function"]["name"] == "list_layers")));
let models = models_request(&cfg("ollama-cloud"));
assert_eq!(models.url, "https://ollama.com/v1/models");
assert!(models.headers.contains(&("Authorization".into(), "Bearer k".into())));
// ollama.com lists its catalog in OpenAI's format.
let listed =
ok(json!({"object": "list", "data": [{"id": "gpt-oss:120b", "object": "model"}, {"id": "gemma4:31b", "object": "model"}]}));
assert_eq!(parse_models(Api::OpenAi, &listed.unwrap()), Ok(vec!["gemma4:31b".to_string(), "gpt-oss:120b".to_string()]));
}

#[test]
fn ollama_cloud_runs_a_tool_call_and_answers() {
let mut s = sample();
let mut a = Agent::new(cfg("ollama-cloud"), &s);
let Step::Send(_) = a.ask("what layers?", &s) else { panic!("expected a request") };
// A reply as ollama.com sends it: empty content, reasoning beside the call.
let mut reply = call("call_1", "list_layers", json!({}));
reply["choices"][0]["message"]["content"] = json!("");
reply["choices"][0]["message"]["reasoning"] = json!("List them.");
let Step::Send(req) = a.receive(a.generation(), ok(reply), &mut s) else { panic!("expected a follow-up") };
assert_eq!(req.url, "https://ollama.com/v1/chat/completions");
let msgs = body(&req)["messages"].as_array().cloned().unwrap_or_default();
let result = msgs.iter().find(|m| m["role"] == "tool").expect("the tool result is sent back");
assert_eq!(result["tool_call_id"], "call_1");
assert!(result["content"].to_string().contains("Cities"));
assert_eq!(a.receive(a.generation(), ok(say("Two layers.")), &mut s), Step::Done);
}

#[test]
fn mistral_typed_stream_preserves_visible_text_thinking_and_signatures_for_replay() {
let thinking = json!({"type":"thinking", "thinking":[{"type":"text","text":"private thought"}], "signature":"signed"});
Expand Down
9 changes: 5 additions & 4 deletions crates/ui-egui/src/assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! Requests go out off the frame: on a thread on the desktop, through `Services::http` (the
//! browser's fetch) on the web. Their replies are taken in by [`RustGisApp::logic`] each frame.

use rustgis_assistant::{Agent, Config, Entry, HttpRequest, HttpResponse, PRESETS, Step, chatgpt, provider};
use rustgis_assistant::{Agent, Config, Entry, HttpRequest, HttpResponse, Step, chatgpt, provider};

use crate::{RustGisApp, Slot};

Expand Down Expand Up @@ -297,8 +297,9 @@ pub(crate) fn ensure_loaded(app: &mut RustGisApp, ctx: &egui::Context) {
let provider = pref(app, provider::PROVIDER_PREF)
.or_else(|| std::env::var("RUSTGIS_ASSISTANT_PROVIDER").ok())
.filter(|p| provider::preset(p).is_some())
// The first provider with a key in the environment (a ChatGPT sign-in is chosen, not assumed).
.or_else(|| PRESETS.iter().find(|p| !p.login && !Config::from_env(p.id).key.is_empty()).map(|p| p.id.to_string()))
// 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))
.unwrap_or_else(|| "anthropic".into());
let mut cfg = load_config(app, &provider, ctx);
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -368,7 +369,7 @@ fn migrate_keys(app: &mut RustGisApp, ctx: &egui::Context) {
if !provider::remembers_keys(pref(app, provider::REMEMBER_KEY_PREF).as_deref()) {
return;
}
for p in PRESETS.iter().filter(|p| !p.login) {
for p in rustgis_assistant::PRESETS.iter().filter(|p| !p.login) {
if let Some(legacy) = pref(app, &format!("assistant_key_{}", p.id)) {
app.assistant.keys.load(p.id, "", Some(legacy), true, app.services.secrets.clone(), ctx);
}
Expand Down
5 changes: 3 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ rustgis-cli ask --login # sign in with ChatGPT to us
rustgis-cli ask --sample --provider chatgpt "Zoom to Tokyo"
```

The provider is `--provider` (`anthropic`, `openai`, `chatgpt`, `gemini`, `openrouter`, `ollama`, `custom`, `requesty`, `trustedrouter`, `opper`, `mistral`),
else `RUSTGIS_ASSISTANT_PROVIDER`, else the first with a key in the environment, else the app's
The provider is `--provider` (`anthropic`, `openai`, `chatgpt`, `gemini`, `openrouter`, `ollama`, `custom`, `requesty`, `trustedrouter`, `opper`, `mistral`, `ollama-cloud`),
else `RUSTGIS_ASSISTANT_PROVIDER`, else the first with a key in the environment (not Ollama Cloud,
which `OLLAMA_API_KEY` alone never selects), else the app's
saved provider when `--use-saved-secrets` is set, else Ollama. ChatGPT sign-in is used only when
that provider is selected. Account management and `--models` do not read saved API keys:
model listing uses environment API keys (or the selected ChatGPT sign-in), whereas a prompt
Expand Down
14 changes: 9 additions & 5 deletions docs/user-guide/assistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ Click the model name or the gear to open the settings. The assistant works with:
| ChatGPT (sign in) | OpenAI's models, billed to your ChatGPT plan. On a personal plan, ChatGPT's "Improve the model" setting decides whether requests are used for training; Business, Enterprise and Edu plans aren't trained on by default. | the first model in your account’s current catalog | none: **Continue with ChatGPT** to use your ChatGPT plan (desktop app and command line) |
| Google Gemini | Google's own API. With a free key, Google may use requests to improve its products and people may read them; a Cloud project with billing turns that off. In the EEA, Switzerland and the UK, paid-service data terms also cover free use. | `gemini-3.8-flash` | [aistudio.google.com](https://aistudio.google.com/apikey), or `GEMINI_API_KEY` / `GOOGLE_API_KEY` |
| OpenRouter | A US gateway to hundreds of models. OpenRouter doesn't keep request content by default. With Private routing on (the default), RustGIS asks it to skip endpoints that may train on requests. | `openrouter/auto` | [openrouter.ai](https://openrouter.ai/keys), or `OPENROUTER_API_KEY` |
| Ollama (local) | Models you run with Ollama on this computer or a server of your own. Requests go to the server at the chosen address; its models and configuration determine any onward use. | `qwen3` | none; the server from `OLLAMA_BASE_URL` (default `http://localhost:11434`) |
| Ollama (local) | Models you run with Ollama on this computer or a server of your own. Requests go to the server at the chosen address; its models and configuration determine any onward use. | `qwen3` | none; the server from `OLLAMA_BASE_URL` (default `http://localhost:11434`). Signed in with `ollama signin`, it also runs the `:cloud` models it lists |
| OpenAI-compatible | Any service or local server that speaks OpenAI's API. What happens to requests is up to the service at the chosen address. | — | LM Studio, vLLM, llama.cpp…: `OPENAI_COMPATIBLE_BASE_URL` (default `http://localhost:1234/v1`), with an optional `OPENAI_COMPATIBLE_API_KEY` |
| Requesty | A UK gateway to hundreds of models, which can move to another service when one fails. It logs requests up to 30 days by default; you can turn that off for each key. Some upstreams train on requests on paid plans too; Requesty may also train on free-plan requests. | `anthropic/claude-sonnet-5-5` | [app.requesty.ai](https://app.requesty.ai/api-keys), or `REQUESTY_API_KEY`; for the EU, set the **Address** to `https://router.eu.requesty.ai/v1` |
| TrustedRouter | A US gateway to models from many services, run on servers whose software can be checked independently. The gateway doesn't keep request content; each service behind it follows its own policy and may keep or train on requests. | `trustedrouter/auto` | [trustedrouter.com](https://trustedrouter.com), or `TRUSTEDROUTER_API_KEY` |
| Opper | A Swedish gateway to hundreds of models, built for keeping data in the EU. It doesn't store request content by default, but a model name without a route prefix may run outside the EU. | `claude-sonnet-5-5` | [platform.opper.ai](https://platform.opper.ai), or `OPPER_API_KEY` |
| Mistral | Mistral AI's own API, from France. Paid API requests aren't used for training by default; on a free account, turn training off under Privacy in the admin panel. Labs and Preview models may train regardless of that setting. | `mistral-small-2603` | [console.mistral.ai](https://console.mistral.ai/api-keys), or `MISTRAL_API_KEY`; for [EU inference](https://docs.mistral.ai/inference/regional-inference), set **Address** to `https://api.eu.mistral.ai/v1` (supported models only; 10% surcharge) |
| Ollama Cloud | Open models that Ollama runs in its cloud, mainly in the United States and at times in Europe. Ollama says it doesn't store or log prompts and responses and doesn't train on them; it keeps usage metadata. | `gpt-oss:120b` | [ollama.com](https://ollama.com/settings/keys), or `OLLAMA_API_KEY`; model names are the cloud catalog's, without `-cloud` |

Last checked: November 2026. These descriptions apply to the presets' default addresses.
If **Address** is changed, the chosen service's policy applies. These summaries aren't guarantees
Expand All @@ -126,13 +127,14 @@ as OpenAI documents for Codex. See the providers' own policies: [Anthropic](http
[ChatGPT/Codex](https://help.openai.com/en/articles/7730893-data-controls-in-chatgpt),
[Gemini](https://ai.google.dev/gemini-api/terms), [OpenRouter](https://openrouter.ai/privacy),
[Requesty privacy](https://www.requesty.ai/privacy) and [training terms](https://www.requesty.ai/terms), [TrustedRouter](https://trustedrouter.com/privacy),
[Opper](https://opper.ai/security-overview), and
[Mistral](https://legal.mistral.ai/terms/commercial-terms-of-service/).
[Opper](https://opper.ai/security-overview),
[Mistral](https://legal.mistral.ai/terms/commercial-terms-of-service/), and
[Ollama privacy](https://ollama.com/privacy) and [hosting](https://ollama.com/pricing).

The ↻ button lists the provider's models. The provider and model you last chose in the settings
are used at start. Until you choose one, `RUSTGIS_ASSISTANT_PROVIDER` and
`RUSTGIS_ASSISTANT_MODEL` pick them, and otherwise the desktop uses the first provider with a key
in the environment, falling back to Anthropic when none has a key. ChatGPT sign-in is used
in the environment (`OLLAMA_API_KEY` alone never selects Ollama Cloud), falling back to Anthropic when none has a key. ChatGPT sign-in is used
only when you choose that provider. Saved settings win over the environment. The **Address**
field changes the endpoint for providers other than ChatGPT; use the OpenAI-compatible API
path (usually `/v1`) for local servers. Models that call tools well give the best results;
Expand Down Expand Up @@ -438,7 +440,9 @@ 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_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`.

## Retries and long conversations

Expand Down
Loading