fix: respect DashScope v1 runtime mode for alibaba (#2459)
Remove the hardcoded Alibaba branch from resolve_runtime_provider() that forced api_mode='anthropic_messages' regardless of the base URL. Alibaba now goes through the generic API-key provider path, which auto-detects the protocol from the URL: - /apps/anthropic → anthropic_messages (via endswith check) - /v1 → chat_completions (default) This fixes Alibaba setup with OpenAI-compatible DashScope endpoints (e.g. coding-intl.dashscope.aliyuncs.com/v1) that were broken because runtime always forced Anthropic mode even when setup saved a /v1 URL. Based on PR #2024 by @kshitijk4poor. Co-authored-by: kshitijk4poor <kshitijk4poor@users.noreply.github.com>
This commit is contained in:
parent
c0c13e4ed4
commit
56b0104154
2 changed files with 28 additions and 13 deletions
|
|
@ -381,19 +381,6 @@ def resolve_runtime_provider(
|
||||||
"requested_provider": requested_provider,
|
"requested_provider": requested_provider,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Alibaba Cloud / DashScope (Anthropic-compatible endpoint)
|
|
||||||
if provider == "alibaba":
|
|
||||||
creds = resolve_api_key_provider_credentials(provider)
|
|
||||||
base_url = creds.get("base_url", "").rstrip("/") or "https://dashscope-intl.aliyuncs.com/apps/anthropic"
|
|
||||||
return {
|
|
||||||
"provider": "alibaba",
|
|
||||||
"api_mode": "anthropic_messages",
|
|
||||||
"base_url": base_url,
|
|
||||||
"api_key": creds.get("api_key", ""),
|
|
||||||
"source": creds.get("source", "env"),
|
|
||||||
"requested_provider": requested_provider,
|
|
||||||
}
|
|
||||||
|
|
||||||
# API-key providers (z.ai/GLM, Kimi, MiniMax, MiniMax-CN)
|
# API-key providers (z.ai/GLM, Kimi, MiniMax, MiniMax-CN)
|
||||||
pconfig = PROVIDER_REGISTRY.get(provider)
|
pconfig = PROVIDER_REGISTRY.get(provider)
|
||||||
if pconfig and pconfig.auth_type == "api_key":
|
if pconfig and pconfig.auth_type == "api_key":
|
||||||
|
|
|
||||||
|
|
@ -534,6 +534,34 @@ def test_minimax_explicit_api_mode_respected(monkeypatch):
|
||||||
assert resolved["api_mode"] == "chat_completions"
|
assert resolved["api_mode"] == "chat_completions"
|
||||||
|
|
||||||
|
|
||||||
|
def test_alibaba_default_anthropic_endpoint_uses_anthropic_messages(monkeypatch):
|
||||||
|
"""Alibaba with default /apps/anthropic URL should use anthropic_messages mode."""
|
||||||
|
monkeypatch.setattr(rp, "resolve_provider", lambda *a, **k: "alibaba")
|
||||||
|
monkeypatch.setattr(rp, "_get_model_config", lambda: {})
|
||||||
|
monkeypatch.setenv("DASHSCOPE_API_KEY", "test-dashscope-key")
|
||||||
|
monkeypatch.delenv("DASHSCOPE_BASE_URL", raising=False)
|
||||||
|
|
||||||
|
resolved = rp.resolve_runtime_provider(requested="alibaba")
|
||||||
|
|
||||||
|
assert resolved["provider"] == "alibaba"
|
||||||
|
assert resolved["api_mode"] == "anthropic_messages"
|
||||||
|
assert resolved["base_url"] == "https://dashscope-intl.aliyuncs.com/apps/anthropic"
|
||||||
|
|
||||||
|
|
||||||
|
def test_alibaba_openai_compatible_v1_endpoint_stays_chat_completions(monkeypatch):
|
||||||
|
"""Alibaba with /v1 coding endpoint should use chat_completions mode."""
|
||||||
|
monkeypatch.setattr(rp, "resolve_provider", lambda *a, **k: "alibaba")
|
||||||
|
monkeypatch.setattr(rp, "_get_model_config", lambda: {})
|
||||||
|
monkeypatch.setenv("DASHSCOPE_API_KEY", "test-dashscope-key")
|
||||||
|
monkeypatch.setenv("DASHSCOPE_BASE_URL", "https://coding-intl.dashscope.aliyuncs.com/v1")
|
||||||
|
|
||||||
|
resolved = rp.resolve_runtime_provider(requested="alibaba")
|
||||||
|
|
||||||
|
assert resolved["provider"] == "alibaba"
|
||||||
|
assert resolved["api_mode"] == "chat_completions"
|
||||||
|
assert resolved["base_url"] == "https://coding-intl.dashscope.aliyuncs.com/v1"
|
||||||
|
|
||||||
|
|
||||||
def test_named_custom_provider_anthropic_api_mode(monkeypatch):
|
def test_named_custom_provider_anthropic_api_mode(monkeypatch):
|
||||||
"""Custom providers should accept api_mode: anthropic_messages."""
|
"""Custom providers should accept api_mode: anthropic_messages."""
|
||||||
monkeypatch.setattr(rp, "resolve_provider", lambda *a, **k: "my-anthropic-proxy")
|
monkeypatch.setattr(rp, "resolve_provider", lambda *a, **k: "my-anthropic-proxy")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue