fix(vision): preserve explicit provider auth with custom base_url

Keep the configured vision provider when base_url is overridden so credential-pool lookup still resolves provider-specific API keys (e.g. ZAI_API_KEY), and add a regression test for this path.
This commit is contained in:
陈运波0668001438 2026-04-27 10:43:52 +08:00 committed by Teknium
parent b7bbc62503
commit 6cf7a9e330
2 changed files with 40 additions and 13 deletions

View file

@ -13,16 +13,13 @@ def test_vision_call_uses_resolved_provider_args():
usage=MagicMock(prompt_tokens=10, completion_tokens=5),
)
with (
patch(
"agent.auxiliary_client._resolve_task_provider_model",
return_value=("my-resolved-provider", "my-resolved-model", "http://resolved", "resolved-key", "chat_completions"),
),
patch(
"agent.auxiliary_client.resolve_vision_provider_client",
return_value=("my-resolved-provider", fake_client, "my-resolved-model"),
) as mock_vision,
):
with patch(
"agent.auxiliary_client._resolve_task_provider_model",
return_value=("my-resolved-provider", "my-resolved-model", "http://resolved", "resolved-key", "chat_completions"),
), patch(
"agent.auxiliary_client.resolve_vision_provider_client",
return_value=("my-resolved-provider", fake_client, "my-resolved-model"),
) as mock_vision:
call_llm(
"vision",
provider="raw-provider",
@ -38,3 +35,30 @@ def test_vision_call_uses_resolved_provider_args():
assert call_args.kwargs["model"] == "my-resolved-model"
assert call_args.kwargs["base_url"] == "http://resolved"
assert call_args.kwargs["api_key"] == "resolved-key"
def test_vision_base_url_override_keeps_explicit_provider():
"""Explicit provider should still drive credential resolution with custom base_url."""
from agent.auxiliary_client import resolve_vision_provider_client
fake_client = MagicMock()
with patch(
"agent.auxiliary_client._resolve_task_provider_model",
return_value=(
"zai",
"glm-4v",
"https://open.bigmodel.cn/api/paas/v4",
None,
"chat_completions",
),
), patch(
"agent.auxiliary_client.resolve_provider_client",
return_value=(fake_client, "glm-4v"),
) as mock_resolve:
provider, client, model = resolve_vision_provider_client()
assert provider == "zai"
assert client is fake_client
assert model == "glm-4v"
assert mock_resolve.call_args.args[0] == "zai"
assert mock_resolve.call_args.kwargs["explicit_base_url"] == "https://open.bigmodel.cn/api/paas/v4"