Repository navigation
feat(assistant): disclose provider policies and filter OpenRouter routing #3171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1bc3054
bea8b3d
0d2fe03
ef9559a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ pub enum Api { | |
| /// A provider the settings offer, with its defaults. | ||
| pub struct Preset { | ||
| pub id: &'static str, | ||
| /// Who operates the service and the privacy considerations for its default account. | ||
| pub description: &'static str, | ||
| pub label: &'static str, | ||
| pub api: Api, | ||
| pub base_url: &'static str, | ||
|
|
@@ -47,6 +49,7 @@ pub struct Preset { | |
| pub const PRESETS: &[Preset] = &[ | ||
| Preset { | ||
| id: "anthropic", | ||
| description: "Anthropic's own API, from the makers of Claude. API requests aren't used for training; content may be kept for safety checks, with exceptions to the standard 30-day deletion period.", | ||
| label: "Anthropic", | ||
| api: Api::Anthropic, | ||
| base_url: "https://api.anthropic.com", | ||
|
|
@@ -59,6 +62,7 @@ pub const PRESETS: &[Preset] = &[ | |
| }, | ||
| Preset { | ||
| id: "openai", | ||
| description: "OpenAI's own API, from the makers of GPT. API requests aren't used for training by default; abuse monitoring logs may be kept up to 30 days, with legal and safety exceptions.", | ||
| label: "OpenAI", | ||
| api: Api::OpenAi, | ||
| base_url: "https://api.openai.com/v1", | ||
|
|
@@ -71,6 +75,7 @@ pub const PRESETS: &[Preset] = &[ | |
| }, | ||
| Preset { | ||
| id: "chatgpt", | ||
| description: "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.", | ||
| label: "ChatGPT (sign in)", | ||
| api: Api::Responses, | ||
| base_url: crate::chatgpt::API, | ||
|
|
@@ -85,6 +90,7 @@ pub const PRESETS: &[Preset] = &[ | |
| }, | ||
| Preset { | ||
| id: "gemini", | ||
| description: "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.", | ||
| label: "Google Gemini", | ||
| api: Api::Gemini, | ||
| base_url: "https://generativelanguage.googleapis.com/v1beta", | ||
|
|
@@ -97,6 +103,7 @@ pub const PRESETS: &[Preset] = &[ | |
| }, | ||
| Preset { | ||
| id: "openrouter", | ||
| description: "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.", | ||
| label: "OpenRouter", | ||
| api: Api::OpenAi, | ||
| base_url: "https://openrouter.ai/api/v1", | ||
|
|
@@ -109,6 +116,7 @@ pub const PRESETS: &[Preset] = &[ | |
| }, | ||
| Preset { | ||
| id: "ollama", | ||
| description: "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.", | ||
| label: "Ollama (local)", | ||
| api: Api::OpenAi, | ||
| base_url: "http://localhost:11434/v1", | ||
|
|
@@ -121,6 +129,7 @@ pub const PRESETS: &[Preset] = &[ | |
| }, | ||
| Preset { | ||
| id: "custom", | ||
| description: "Any service or local server that speaks OpenAI's API. What happens to requests is up to the service at the chosen address.", | ||
| label: "OpenAI-compatible", | ||
| api: Api::OpenAi, | ||
| base_url: "http://localhost:1234/v1", | ||
|
|
@@ -133,6 +142,7 @@ pub const PRESETS: &[Preset] = &[ | |
| }, | ||
| Preset { | ||
| id: "requesty", | ||
| description: "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.", | ||
| label: "Requesty", | ||
| api: Api::OpenAi, | ||
| base_url: "https://router.requesty.ai/v1", | ||
|
|
@@ -145,6 +155,7 @@ pub const PRESETS: &[Preset] = &[ | |
| }, | ||
| Preset { | ||
| id: "trustedrouter", | ||
| description: "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.", | ||
| label: "TrustedRouter", | ||
| api: Api::OpenAi, | ||
| base_url: "https://api.trustedrouter.com/v1", | ||
|
|
@@ -157,6 +168,7 @@ pub const PRESETS: &[Preset] = &[ | |
| }, | ||
| Preset { | ||
| id: "opper", | ||
| description: "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.", | ||
| label: "Opper", | ||
| api: Api::OpenAi, | ||
| base_url: "https://api.opper.ai/v3/compat", | ||
|
|
@@ -192,6 +204,8 @@ pub struct Config { | |
| /// Whether the catalog offers reasoning for the selected model (`Some(false)` also turns it off | ||
| /// for a Chat Completions model that refused it alongside tools: see [`refuses_reasoning_with_tools`]). | ||
| pub reasoning: Option<bool>, | ||
| /// OpenRouter routing excludes endpoints that collect request data by default. | ||
| pub openrouter_private: bool, | ||
| /// Requested tool output token estimate (default 10,000); the 24,000-token hard limit still applies. | ||
| pub tool_output_token_limit: usize, | ||
| } | ||
|
|
@@ -224,6 +238,7 @@ impl Config { | |
| client_id: String::new(), | ||
| session: String::new(), | ||
| reasoning: None, | ||
| openrouter_private: env("RUSTGIS_OPENROUTER_DATA_COLLECTION").as_deref() != Some("allow"), | ||
| tool_output_token_limit: env("RUSTGIS_ASSISTANT_TOOL_OUTPUT_TOKEN_LIMIT") | ||
| .and_then(|s| s.parse().ok()) | ||
| .filter(|n| *n > 0) | ||
|
|
@@ -276,6 +291,9 @@ impl Config { | |
| } | ||
| } | ||
|
|
||
| /// OpenRouter-only routing preference; missing values keep the privacy filter enabled. | ||
| pub const OPENROUTER_PRIVATE_PREF: &str = "assistant_openrouter_private"; | ||
|
|
||
| /// The desktop preference naming the provider it uses (`prefs.json`). | ||
| pub const PROVIDER_PREF: &str = "assistant_provider"; | ||
|
|
||
|
|
@@ -678,6 +696,7 @@ impl Note { | |
|
|
||
| /// Every [`Note`] template RustGIS writes (the interface's catalogs translate each). | ||
| pub const NOTE_TEMPLATES: &[&str] = &[ | ||
| "OpenRouter found no endpoint matching your data policy. Check Private routing in the Assistant settings or your OpenRouter privacy settings.", | ||
| "The reply reached its length limit.", | ||
| "The provider's content filter stopped the reply.", | ||
| "The reply stopped early ({reason}).", | ||
|
|
@@ -1103,6 +1122,7 @@ fn header(k: &str, v: &str) -> (String, String) { | |
| // --------------------------------------------------------------------------------------------- | ||
| // OpenAI Chat Completions | ||
|
|
||
| /// Builds the OpenAI-shaped request; the OpenRouter privacy filter travels with every turn. | ||
| fn openai_request(cfg: &Config, system: &str, turns: &[Turn], tools: &[ToolDef]) -> HttpRequest { | ||
| let mut messages = vec![json!({"role": "system", "content": system})]; | ||
| for t in turns { | ||
|
|
@@ -1138,6 +1158,9 @@ fn openai_request(cfg: &Config, system: &str, turns: &[Turn], tools: &[ToolDef]) | |
| .map(|t| json!({"type": "function", "function": {"name": t.name, "description": t.description, "parameters": t.schema}})) | ||
| .collect(); | ||
| let mut body = json!({"model": cfg.model.trim(), "messages": messages, "stream": true}); | ||
| if cfg.provider == "openrouter" && cfg.openrouter_private { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The filter is keyed on the provider name, not on the endpoint. If a user keeps the OpenRouter preset but changes Address to a different OpenAI-compatible server, Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The filter follows the selected OpenRouter preset, including an overridden address, so changing the address does not silently remove the requested privacy constraint. Clarifying that compatibility limit in the guide is left for the release quality pass. |
||
| body["provider"] = json!({"data_collection": "deny"}); | ||
| } | ||
| // Some servers refuse an empty tool list. | ||
| if !tools.is_empty() { | ||
| body["tools"] = json!(tools); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ fn sample() -> Session { | |
| s | ||
| } | ||
|
|
||
| /// Deterministic provider defaults with a synthetic key and private routing enabled. | ||
| fn cfg(provider: &str) -> Config { | ||
| let p = preset(provider).unwrap_or(&PRESETS[0]); | ||
| Config { | ||
|
|
@@ -47,6 +48,7 @@ fn cfg(provider: &str) -> Config { | |
| client_id: String::new(), | ||
| session: String::new(), | ||
| reasoning: None, | ||
| openrouter_private: true, | ||
| tool_output_token_limit: crate::tools::DEFAULT_OUTPUT_TOKENS, | ||
| } | ||
| } | ||
|
|
@@ -5428,3 +5430,30 @@ fn a_message_joining_one_left_unanswered_takes_no_more_than_four_pictures() { | |
| let said = "A message takes at most 4 pictures: a1.jpg, a2.jpg, a3.jpg, a4.jpg left out."; | ||
| assert!(a.transcript.iter().any(|e| matches!(e, Entry::Note(n) if n.to_string() == said))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn openrouter_private_routing_filters_only_openrouter_and_can_be_disabled() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new tests cover the request body and the refusal note, but nothing covers the two ways the setting is read: Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional environment-parsing and preference round-trip coverage is left for the release quality pass. The current regressions cover outgoing routing, refusal guidance and stopping a run when the UI policy changes; the parsing and saved-preference expressions retain the private default. |
||
| let mut c = cfg("openrouter"); | ||
| let body = |c: &Config| -> Value { serde_json::from_str(&chat_request(c, "system", &[], &[]).body.unwrap()).unwrap() }; | ||
| assert_eq!(body(&c)["provider"], json!({"data_collection":"deny"})); | ||
| c.openrouter_private = false; | ||
| assert!(body(&c).get("provider").is_none()); | ||
| for p in PRESETS.iter().filter(|p| p.api == Api::OpenAi && p.id != "openrouter") { | ||
| assert!(body(&cfg(p.id)).get("provider").is_none(), "{}", p.id); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn openrouter_data_policy_refusal_names_the_privacy_checkbox() { | ||
| let mut session = sample(); | ||
| let mut a = Agent::new(cfg("openrouter"), &session); | ||
| assert!(matches!(a.ask("hello", &session), Step::Send(_))); | ||
| let response = HttpResponse { | ||
| status: 404, | ||
| headers: vec![], | ||
| body: br#"{"error":{"message":"No endpoints found matching your data policy"}}"#.to_vec(), | ||
| }; | ||
| let generation = a.generation(); | ||
| assert!(matches!(a.receive(generation, Ok(response), &mut session), Step::Done)); | ||
| assert!(a.transcript.iter().any(|e| matches!(e, Entry::Note(n) if n.template.contains("Check Private routing")))); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -181,6 +181,9 @@ fn load_config(app: &mut RustGisApp, provider: &str, ctx: &egui::Context) -> Con | |||||||||
| if let Some(u) = pref(app, &provider::url_pref(provider)).filter(|_| !c.login()) { | ||||||||||
| c.base_url = u; | ||||||||||
| } | ||||||||||
| if provider == "openrouter" { | ||||||||||
| c.openrouter_private = pref(app, provider::OPENROUTER_PRIVATE_PREF).as_deref() != Some("off"); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the desktop, this line overrides the value
Suggested change
Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The CLI-only scope is intentional. Inheriting |
||||||||||
| } | ||||||||||
| if !c.login() { | ||||||||||
| let legacy = pref(app, &format!("assistant_key_{provider}")); | ||||||||||
| #[cfg(not(target_arch = "wasm32"))] | ||||||||||
|
|
@@ -416,6 +419,9 @@ pub(crate) fn save_config(app: &mut RustGisApp, c: &Config, ctx: &egui::Context) | |||||||||
| save_pref(app, provider::PROVIDER_PREF, &c.provider); | ||||||||||
| save_pref(app, &format!("assistant_model_{}", c.provider), c.model.trim()); | ||||||||||
| save_pref(app, &provider::url_pref(&c.provider), c.base_url.trim()); | ||||||||||
| if c.provider == "openrouter" { | ||||||||||
| save_pref(app, provider::OPENROUTER_PRIVATE_PREF, provider::remember_key_value(c.openrouter_private)); | ||||||||||
| } | ||||||||||
| // A key from the environment stays there; a sign-in's tokens live in their own file. | ||||||||||
| let from_env = Config::from_env(&c.provider).key; | ||||||||||
| if c.login() { | ||||||||||
|
|
@@ -552,12 +558,13 @@ pub(crate) fn list_models(app: &mut RustGisApp, cfg: &Config, ctx: &egui::Contex | |||||||||
| app.assistant.models_slot = Some(dispatch(app, req, cfg.login().then(|| cfg.binding()), None, ctx)); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /// Replaces provider settings and stops work bound to a different provider or sign-in. | ||||||||||
| /// Replaces settings, stopping work when its provider, sign-in or OpenRouter privacy policy changes. | ||||||||||
| pub(crate) fn apply_config(app: &mut RustGisApp, cfg: Config) { | ||||||||||
| let another = app | ||||||||||
| .assistant | ||||||||||
| .config() | ||||||||||
| .is_some_and(|c| c.provider != cfg.provider || (c.login() && (c.binding() != cfg.binding() || c.key != cfg.key))); | ||||||||||
| let another = app.assistant.config().is_some_and(|c| { | ||||||||||
| c.provider != cfg.provider | ||||||||||
| || (c.provider == "openrouter" && c.openrouter_private != cfg.openrouter_private) | ||||||||||
| || (c.login() && (c.binding() != cfg.binding() || c.key != cfg.key)) | ||||||||||
| }); | ||||||||||
| if another { | ||||||||||
| stop(app); | ||||||||||
| } | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONTRIBUTING.md (added in this PR) requires that where the API has no per-request training control, the description "says when training can happen and how users can turn it off". This text says training can happen on paid plans and free plans, but gives no way to turn it off. The same gap is in TrustedRouter's description (line 158: "may keep or train on requests", no opt-out given) and Opper's (line 171) says nothing about training at all. Either state the opt-out (the account or key setting, if one exists) or say that no control is documented, so the preset meets the criterion this PR sets. This is a policy-wording point rather than a code defect, so it can be settled with the maintainer's review of the sources.
Category: quality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The descriptions retain the upstream-training warnings. Further opt-out detail for these gateways is left for the release quality pass and the maintainer’s review of the proposed preset policy. The PR retains its policy-agreement hold before landing.