7622eb0402
providers.py had been holding two jobs: the registry of what each provider looks like, and the decisions made from those declarations. Adding response-side judgement would have made it the module for everything about reasoning, so the decisions move to thinking.py and the registry keeps only profiles and their lookup. Moving a module breaks any deep-path import of what moved, so the six public symbols are promoted to the package root at the same time. The top level is this library's stated API surface; giving downstream a stable name to import is what makes the next reorganisation harmless. observe_thinking stays unexported — downstream reads the verdict off LLMResponse, and exporting it would be a permanent promise for nothing.
72 lines
2.9 KiB
Python
72 lines
2.9 KiB
Python
"""providers.py 注册表测试(M1 设计 §7;register_provider 为纯函数,无可变全局)。"""
|
|
|
|
import pytest
|
|
|
|
from polygateway.providers import (
|
|
DEFAULT_PROFILES,
|
|
ProviderProfile,
|
|
get_provider,
|
|
register_provider,
|
|
)
|
|
|
|
|
|
class TestDefaultProfiles:
|
|
def test_qwen_profile(self):
|
|
p = get_provider("qwen")
|
|
assert p.thinking_on == {"enable_thinking": True}
|
|
assert p.thinking_off == {"enable_thinking": False}
|
|
assert p.strip_think_tags is True
|
|
assert p.supports_native_schema is False
|
|
|
|
def test_deepseek_profile(self):
|
|
p = get_provider("deepseek")
|
|
assert p.thinking_on == {"thinking": {"type": "enabled"}}
|
|
assert p.thinking_off == {"thinking": {"type": "disabled"}}
|
|
assert p.strip_think_tags is False
|
|
|
|
def test_openai_slots_are_unknown_not_empty(self):
|
|
"""issue #5: 该段名实践中被复用为任意兼容厂商的兜底(下游把 kimi 挂在此),
|
|
|
|
故不能下发任何厂商方言参数。None = 形态未知 → 配了 enable_thinking 即报错,
|
|
而不是空字典那种"注入了个寂寞"的静默失效。
|
|
"""
|
|
p = get_provider("openai")
|
|
assert p.thinking_on is None and p.thinking_off is None
|
|
assert p.strip_think_tags is False
|
|
|
|
def test_minimax_profile_uses_reasoning_effort(self):
|
|
"""2026-08-02 实测: reasoning_effort 才是 MiniMax 认的开关。"""
|
|
p = get_provider("minimax")
|
|
assert p.thinking_off == {"reasoning_effort": "none"}
|
|
assert p.thinking_on == {"reasoning_effort": "medium"}
|
|
assert p.strip_think_tags is False
|
|
|
|
def test_unknown_provider_fails_loudly(self):
|
|
"""消灭子串猜测: 未注册 provider 装配期即报错,不做模糊匹配。"""
|
|
with pytest.raises(ValueError, match="glm"):
|
|
get_provider("glm")
|
|
with pytest.raises(ValueError):
|
|
get_provider("qwen2") # 子串相似也不放行
|
|
|
|
|
|
class TestPureFunctionRegistration:
|
|
def test_register_returns_new_mapping(self):
|
|
glm = ProviderProfile(name="glm", thinking_on={}, thinking_off={}, strip_think_tags=False)
|
|
table = register_provider(glm)
|
|
assert get_provider("glm", registry=table) is glm
|
|
# 默认表未被污染(无可变全局状态铁律)
|
|
with pytest.raises(ValueError):
|
|
get_provider("glm")
|
|
|
|
def test_register_on_custom_base_and_override(self):
|
|
custom_qwen = ProviderProfile(
|
|
name="qwen", thinking_on={"x": 1}, thinking_off={}, strip_think_tags=False
|
|
)
|
|
table = register_provider(custom_qwen, base=DEFAULT_PROFILES)
|
|
assert get_provider("qwen", registry=table).thinking_on == {"x": 1}
|
|
assert get_provider("qwen").thinking_on == {"enable_thinking": True}
|
|
|
|
def test_default_profiles_mapping_is_read_only(self):
|
|
with pytest.raises(TypeError):
|
|
DEFAULT_PROFILES["hack"] = None # type: ignore[index]
|