test: update for kind-based dispatch and remove ResponsesChatClient references

This commit is contained in:
2026-07-29 00:46:08 +08:00
parent f0c27bf366
commit f60fd876c6
2 changed files with 18 additions and 58 deletions
+1 -45
View File
@@ -1,7 +1,4 @@
from __future__ import annotations
import msgspec import msgspec
import pytest
from plyngent.agent.responses_bridge import ( from plyngent.agent.responses_bridge import (
chat_messages_to_responses_input, chat_messages_to_responses_input,
@@ -11,8 +8,7 @@ from plyngent.agent.responses_bridge import (
responses_status_to_finish_reason, responses_status_to_finish_reason,
tool_items_to_response_tools, tool_items_to_response_tools,
) )
from plyngent.agent.responses_client import ResponsesChatClient from plyngent.lmproto.openai.model import Response
from plyngent.lmproto.openai.model import Response, ResponsesCreateParam
from plyngent.lmproto.openai_compatible.model import ( from plyngent.lmproto.openai_compatible.model import (
AssistantChatMessage, AssistantChatMessage,
AssistantFunctionTool, AssistantFunctionTool,
@@ -158,43 +154,3 @@ def test_provider_tools_merged_after_local_functions() -> None:
assert tools[0].name == "local_tool" assert tools[0].name == "local_tool"
assert tools[1]["type"] == "web_search" assert tools[1]["type"] == "web_search"
assert tools[2]["vector_store_ids"] == ["vs_1"] assert tools[2]["vector_store_ids"] == ["vs_1"]
@pytest.mark.asyncio
async def test_responses_chat_client_non_stream(monkeypatch: pytest.MonkeyPatch) -> None:
from plyngent.lmproto.openai.client import OpenAIClient
from plyngent.lmproto.openai_compatible.config import OpenAIConfig
platform = OpenAIClient(OpenAIConfig(access_key_or_token="sk", base_url="https://example/v1"))
body = {
"id": "resp_x",
"object": "response",
"created_at": 1,
"model": "gpt-test",
"status": "completed",
"output": [
{
"id": "msg_1",
"type": "message",
"role": "assistant",
"status": "completed",
"content": [{"type": "output_text", "text": "hello", "annotations": []}],
}
],
"usage": {"input_tokens": 3, "output_tokens": 1, "total_tokens": 4},
}
async def fake_responses(param: ResponsesCreateParam, *, stream: bool = False):
assert stream is False
assert param.model == "gpt-test"
assert param.store is False
return msgspec.convert(body, Response)
monkeypatch.setattr(platform, "responses", fake_responses)
client = ResponsesChatClient(platform)
result = await client.chat_completions(
ChatCompletionsParam(model="gpt-test", messages=[UserChatMessage(content="hi")]),
stream=False,
)
assert result.choices[0].message.content == "hello"
+17 -13
View File
@@ -20,24 +20,22 @@ def test_openai_provider_defaults_base_url() -> None:
config = provider_to_openai_config(provider) config = provider_to_openai_config(provider)
assert config.access_key_or_token == "sk-test" assert config.access_key_or_token == "sk-test"
assert config.base_url == "https://api.openai.com/v1" assert config.base_url == "https://api.openai.com/v1"
from plyngent.agent.responses_client import ResponsesChatClient from plyngent.lmproto.openai import OpenAIClient
client = create_client(provider) client = create_client(provider)
assert isinstance(client, ResponsesChatClient) assert isinstance(client, OpenAIClient)
assert hasattr(client, "chat_completions") assert client.kind == "responses"
assert client._provider_tools == [{"type": "web_search"}]
def test_openai_provider_tools_passed_to_wrapper() -> None: def test_openai_provider_tools_passed_to_wrapper() -> None:
from plyngent.agent.responses_client import ResponsesChatClient from plyngent.lmproto.openai import OpenAIClient
provider = OpenAIProvider( provider = OpenAIProvider(
access_key_or_token="sk-test", access_key_or_token="sk-test",
provider_tools=[{"type": "web_search"}], provider_tools=[{"type": "web_search"}],
) )
client = create_client(provider) client = create_client(provider)
assert isinstance(client, ResponsesChatClient) assert isinstance(client, OpenAIClient)
assert client._provider_tools == [{"type": "web_search"}]
def test_openai_compatible_requires_url() -> None: def test_openai_compatible_requires_url() -> None:
@@ -76,9 +74,12 @@ def test_deepseek_ignores_legacy_convention_extra() -> None:
def test_anthropic_not_implemented() -> None: def test_anthropic_not_implemented() -> None:
from plyngent.lmproto.anthropic import AnthropicClient
provider = AnthropicProvider(access_key_or_token="sk-test") provider = AnthropicProvider(access_key_or_token="sk-test")
with pytest.raises(ProviderNotSupportedError, match="anthropic"): client = create_client(provider)
_ = create_client(provider) assert isinstance(client, AnthropicClient)
assert client.kind == "messages"
def test_model_level_preset_url_overrides_parent() -> None: def test_model_level_preset_url_overrides_parent() -> None:
@@ -91,7 +92,7 @@ def test_model_level_preset_url_overrides_parent() -> None:
}, },
) )
openai_client = create_client(provider, model="gpt") openai_client = create_client(provider, model="gpt")
assert openai_client.__class__.__name__ == "ResponsesChatClient" assert openai_client.kind == "responses"
assert provider_to_openai_config(provider, model="gpt").base_url == "https://api.openai.com/v1" assert provider_to_openai_config(provider, model="gpt").base_url == "https://api.openai.com/v1"
compat_client = create_client(provider, model="qwen") compat_client = create_client(provider, model="qwen")
@@ -99,11 +100,14 @@ def test_model_level_preset_url_overrides_parent() -> None:
assert provider_to_openai_config(provider, model="qwen").base_url == "https://gateway.example/v1" assert provider_to_openai_config(provider, model="qwen").base_url == "https://gateway.example/v1"
def test_model_level_anthropic_preset_not_implemented() -> None: def test_model_level_anthropic_preset() -> None:
from plyngent.lmproto.anthropic import AnthropicClient
provider = OpenAICompatibleProvider( provider = OpenAICompatibleProvider(
access_key_or_token="sk-test", access_key_or_token="sk-test",
url="https://gateway.example/v1", url="https://gateway.example/v1",
models={"claude": ModelConfig(preset="anthropic", url="https://api.anthropic.com/v1")}, models={"claude": ModelConfig(preset="anthropic", url="https://api.anthropic.com/v1")},
) )
with pytest.raises(ProviderNotSupportedError, match="anthropic"): client = create_client(provider, model="claude")
_ = create_client(provider, model="claude") assert isinstance(client, AnthropicClient)
assert client.kind == "messages"