Files
plyngent/tests/test_config/test_routing.py
T
NCBM e877df9d94 config: default DeepSeek to web_search and honour its provider_tools
``provider_tools`` reached the effective provider only for the OpenAI preset,
so a DeepSeek ``provider_tools`` in TOML was dropped on the way — and the preset
defaulted to none, leaving search unavailable for every convention.

DeepSeek now defaults to ``[{type="web_search"}]`` like OpenAI does (``[]``
turns it off) and its list reaches the agent: the Anthropic convention runs the
hosted search inside the response, the Responses and chat conventions get the
local ``web_search`` tool (see ``config.routing.local_web_search``).
2026-10-06 23:59:01 +08:00

54 lines
2.0 KiB
Python

"""The routing decisions around a provider's API surface."""
from __future__ import annotations
from dataclasses import replace
from plyngent.config.models import DeepseekProvider
from plyngent.config.routing import (
EffectiveProvider,
deepseek_search_base_url,
local_web_search,
resolve_effective_provider,
wants_web_search,
)
SEARCH_TOOLS: list[dict[str, object]] = [{"type": "web_search"}]
def _effective(
*,
convention: str = "",
url: str = "",
tools: list[dict[str, object]] | None = None,
) -> EffectiveProvider:
provider = DeepseekProvider(access_key_or_token="sk-test", convention=convention, url=url)
effective = resolve_effective_provider(provider, model="deepseek-flash")
return effective if tools is None else replace(effective, provider_tools=tools)
def test_a_deepseek_provider_asks_for_a_search_tool_like_openai_does() -> None:
# ``provider_tools`` defaults to web_search for both presets; ``[]`` disables.
assert wants_web_search(_effective()) is True
assert wants_web_search(_effective(tools=[])) is False
def test_chat_and_responses_conventions_use_the_local_tool() -> None:
# Only the Anthropic surface hosts a search; the others ignore a hosted tool,
# so the default web_search becomes plyngent's own tool there.
assert local_web_search(_effective(convention="")) is True
assert local_web_search(_effective(convention="responses")) is True
assert local_web_search(_effective(convention="anthropic")) is False
def test_without_provider_tools_there_is_no_search() -> None:
assert local_web_search(_effective(convention="responses", tools=[])) is False
def test_search_base_url_prefers_an_anthropic_endpoint() -> None:
assert deepseek_search_base_url(_effective(convention="responses")) == "https://api.deepseek.com/anthropic"
assert (
deepseek_search_base_url(_effective(convention="responses", url="https://gateway.example/anthropic"))
== "https://gateway.example/anthropic"
)