Let the gateway target non-OpenAI upstreams and allow client model passthrough

gateway_thinking_dialect overrides the URL-sniffed protocol dialect for a
reverse-proxied upstream (e.g. Ollama) whose URL carries no identifying
token; upstream_capabilities() uses the same effective dialect to stop
sending stream_options to upstreams that don't support it. gateway_allow_client_model
lets a client-requested model name through even with force-model on, for
an upstream that serves many models with no single stable alias.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XjW4qocnaJxhugUi5ca8Wo
This commit is contained in:
2026-09-07 13:36:42 +02:00
co-authored by Claude Sonnet 5
parent 54f06a957d
commit d9ff99c4a0
7 changed files with 239 additions and 12 deletions
+38 -1
View File
@@ -1,5 +1,6 @@
# retoor <retoor@molodetz.nl>
from dataclasses import dataclass
from typing import Any, Optional
CLIENT_THINKING_KEYS = (
@@ -26,6 +27,40 @@ def thinking_dialect(url: str) -> str:
return "deepseek"
def _resolve_dialect(url: str, dialect: str) -> str:
effective = dialect.strip().lower()
if effective in ("", "auto"):
return thinking_dialect(url)
return effective
@dataclass(frozen=True)
class UpstreamCapabilities:
dialect: str
supports_stream_options: bool
supports_stream_usage: bool
supports_thinking_field: bool
def upstream_capabilities(
url: str, dialect: str = ""
) -> UpstreamCapabilities:
effective = _resolve_dialect(url, dialect)
if effective == "ollama":
return UpstreamCapabilities(
dialect=effective,
supports_stream_options=False,
supports_stream_usage=False,
supports_thinking_field=True,
)
return UpstreamCapabilities(
dialect=effective,
supports_stream_options=True,
supports_stream_usage=True,
supports_thinking_field=True,
)
def _as_text(value: Any) -> str:
if isinstance(value, str):
return value.strip().lower()
@@ -118,8 +153,10 @@ def apply_thinking(
payload: dict,
upstream_url: str,
default_enabled: bool = False,
dialect: str = "",
) -> dict:
effective = _resolve_dialect(upstream_url, dialect)
specified = client_thinking_enabled(payload)
enabled = default_enabled if specified is None else specified
write_thinking(payload, thinking_dialect(upstream_url), enabled)
write_thinking(payload, effective, enabled)
return payload