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
@@ -4,6 +4,7 @@ from devplacepy.services.openai_gateway.thinking import (
apply_thinking,
client_thinking_enabled,
thinking_dialect,
upstream_capabilities,
)
@@ -15,6 +16,38 @@ def test_dialect_from_upstream_url():
assert thinking_dialect("https://unknown.example/v1/chat/completions") == "deepseek"
def test_upstream_capabilities_openai_full_schema():
caps = upstream_capabilities("https://api.deepseek.com/chat/completions")
assert caps.dialect == "deepseek"
assert caps.supports_stream_options is True
assert caps.supports_stream_usage is True
def test_upstream_capabilities_ollama_lacks_stream_options():
caps = upstream_capabilities("http://127.0.0.1:11434/api/chat")
assert caps.dialect == "ollama"
assert caps.supports_stream_options is False
assert caps.supports_stream_usage is False
def test_upstream_capabilities_explicit_dialect_override():
caps = upstream_capabilities(
"https://ai.example.com/v1/chat/completions", dialect="ollama"
)
assert caps.dialect == "ollama"
assert caps.supports_stream_options is False
def test_apply_thinking_respects_explicit_dialect_override():
without = apply_thinking({}, "https://ai.example.com/v1/chat/completions")
assert without["thinking"] == {"type": "disabled"}
with_override = apply_thinking(
{}, "https://ai.example.com/v1/chat/completions", dialect="ollama"
)
assert with_override["think"] is False
assert "thinking" not in with_override
def test_client_intent_unspecified():
assert client_thinking_enabled({}) is None
assert client_thinking_enabled({"messages": []}) is None