fix(provider): honor explicit local provider names

This commit is contained in:
fangliquan
2026-09-19 18:35:03 +08:00
committed by Teknium
parent 204ebafb3d
commit 8658d15957
2 changed files with 5 additions and 3 deletions

View File

@@ -5374,10 +5374,11 @@ def resolve_provider_client(
explicit_base_url, explicit_api_key, api_mode, main_runtime, is_vision, task,
)
branch = _EXPLICIT_PROVIDER_BRANCHES.get(provider)
alias_identity = original_provider.removeprefix("custom:")
# A configured provider whose name collides with a local-server alias is still a named
# provider. Resolve it before the alias's generic ``custom`` branch, which otherwise loses
# the configured base_url and can fall through to an unrelated credentialed provider.
if branch is None or original_provider in _LOCAL_SERVER_ALIASES:
if branch is None or alias_identity in _LOCAL_SERVER_ALIASES:
try:
result = _resolve_named_custom_branch(req)
except ImportError:

View File

@@ -394,7 +394,8 @@ class TestCustomProviderAliasCollision:
# Built-in kimi-coding points at api.moonshot.ai
assert "moonshot" in base_url or "kimi" in base_url, f"unexpected base_url {base_url!r}"
def test_named_llamacpp_wins_over_local_server_alias(self, tmp_path):
@pytest.mark.parametrize("provider", ["llamacpp", "custom:llamacpp"])
def test_named_llamacpp_wins_over_local_server_alias(self, tmp_path, provider):
_write_config(tmp_path, {
"model": {"provider": "openrouter", "default": "anthropic/claude-sonnet-4.6"},
"providers": {
@@ -407,7 +408,7 @@ class TestCustomProviderAliasCollision:
from agent.auxiliary_client import resolve_provider_client
from openai import OpenAI
client, model = resolve_provider_client("llamacpp", model="local-model", raw_codex=True)
client, model = resolve_provider_client(provider, model="local-model", raw_codex=True)
assert isinstance(client, OpenAI)
assert str(client.base_url).rstrip("/") == "http://127.0.0.1:8081/v1"