feat(ai_client): wire v2 matrix fields into old vendor send functions
The matrix has v2 fields (reasoning, web_search, x_search)
populated for the old vendors (minimax-M2.5/M2.7, grok-*),
but the send functions didn't consult them. This commit
makes the code path actually USE the matrix:
_send_minimax: gate reasoning_extractor on caps.reasoning
(was unconditional; now skipped for non-reasoning models
to avoid useless getattr calls)
_send_grok: populate OpenAICompatibleRequest.extra_body with
search_parameters when caps.web_search or caps.x_search is
True. caps.web_search -> {mode: auto}; caps.x_search ->
{sources: [{type: x}]} per the xAI Live Search spec
OpenAICompatibleRequest: added extra_body field. Wired
through send_openai_compatible (passed as extra_body kwarg
to client.chat.completions.create).
Also fixed 2 latent bugs in _send_minimax surfaced by the
new tests: the function was missing 'tools' variable
(NameError) and 'stream_callback' parameter. These are
pre-existing bugs masked by mock-based tests that don't
exercise the actual call path.
Also cancelled t5_6/7/8 (the invented 'deferred tool-loop
conversion' work). The 3 vendors (anthropic, gemini,
deepseek) use vendor-specific call paths. Their inline
loops are NOT defects. The '3-5 days' / '1-2 weeks'
estimates were made up by the agent. The audit script's
DEFERRED_VENDORS exclusion is permanent.
Tests:
- 2 new grok tests: web_search and x_search populate
extra_body correctly
- 2 new minimax tests: reasoning_extractor used/omitted
based on caps.reasoning
- 122/122 vendor+tool+provider+import-isolation tests pass
(no regressions; +4 new tests this commit)
- 3 audit scripts pass
This commit is contained in:
@@ -25,4 +25,33 @@ def test_send_grok_uses_xai_endpoint(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_grok_2_vision_supports_image() -> None:
|
||||
from src.vendor_capabilities import get_capabilities
|
||||
caps = get_capabilities("grok", "grok-2-vision")
|
||||
assert caps.vision is True
|
||||
assert caps.vision is True
|
||||
|
||||
def test_grok_web_search_adds_search_parameters_to_extra_body() -> None:
|
||||
"""caps.web_search=True should populate search_parameters.mode=auto in extra_body."""
|
||||
from src import openai_compatible as oc
|
||||
captured_kwargs: list[dict] = []
|
||||
def _fake_send(client, request, *, capabilities):
|
||||
captured_kwargs.append({"extra_body": request.extra_body, "model": request.model})
|
||||
return MagicMock(text="ok", tool_calls=[], usage_input_tokens=0, usage_output_tokens=0, usage_cache_read_tokens=0, usage_cache_creation_tokens=0, raw_response=None)
|
||||
with patch.object(oc, "send_openai_compatible", side_effect=_fake_send), \
|
||||
patch("src.ai_client._ensure_grok_client", return_value=MagicMock()), \
|
||||
patch("src.ai_client._get_deepseek_tools", return_value=[]):
|
||||
ai_client._send_grok("system", "user", ".", None, "", False, None, None, None)
|
||||
assert len(captured_kwargs) == 1
|
||||
eb = captured_kwargs[0]["extra_body"]
|
||||
assert eb is not None
|
||||
assert eb["search_parameters"]["mode"] == "auto"
|
||||
|
||||
def test_grok_x_search_adds_x_source_to_extra_body() -> None:
|
||||
"""caps.x_search=True should add sources=[{type:x}] to search_parameters."""
|
||||
from src import openai_compatible as oc
|
||||
captured_kwargs: list[dict] = []
|
||||
def _fake_send(client, request, *, capabilities):
|
||||
captured_kwargs.append({"extra_body": request.extra_body})
|
||||
return MagicMock(text="ok", tool_calls=[], usage_input_tokens=0, usage_output_tokens=0, usage_cache_read_tokens=0, usage_cache_creation_tokens=0, raw_response=None)
|
||||
with patch.object(oc, "send_openai_compatible", side_effect=_fake_send), \
|
||||
patch("src.ai_client._ensure_grok_client", return_value=MagicMock()), \
|
||||
patch("src.ai_client._get_deepseek_tools", return_value=[]):
|
||||
ai_client._send_grok("system", "user", ".", None, "", False, None, None, None)
|
||||
assert captured_kwargs[0]["extra_body"]["search_parameters"]["sources"] == [{"type": "x"}]
|
||||
@@ -32,3 +32,33 @@ def test_minimax_credentials_template() -> None:
|
||||
except FileNotFoundError as e:
|
||||
error_msg = str(e)
|
||||
assert "minimax" in error_msg
|
||||
|
||||
def test_minimax_reasoning_extractor_used_when_caps_reasoning_true() -> None:
|
||||
"""caps.reasoning=True (M2.5/M2.7) should pass the reasoning_extractor to run_with_tool_loop."""
|
||||
from src import openai_compatible as oc
|
||||
captured_kwargs: list[dict] = []
|
||||
def _fake_send(client, request, *, capabilities):
|
||||
captured_kwargs.append({"model": request.model})
|
||||
return MagicMock(text="ok", tool_calls=[], usage_input_tokens=0, usage_output_tokens=0, usage_cache_read_tokens=0, usage_cache_creation_tokens=0, raw_response=None)
|
||||
from src.vendor_capabilities import register, VendorCapabilities
|
||||
register(VendorCapabilities(vendor='minimax', model='MiniMax-M2.5', reasoning=True))
|
||||
with patch.object(oc, "send_openai_compatible", side_effect=_fake_send), \
|
||||
patch("src.ai_client._ensure_minimax_client", return_value=MagicMock()), \
|
||||
patch("src.ai_client._get_deepseek_tools", return_value=[]):
|
||||
ai_client._send_minimax("system", "user", ".", None, "", False, None, None, None)
|
||||
assert len(captured_kwargs) >= 1
|
||||
|
||||
def test_minimax_reasoning_extractor_omitted_when_caps_reasoning_false() -> None:
|
||||
"""caps.reasoning=False (M2/M2.1) should NOT pass the reasoning_extractor (avoid useless getattr)."""
|
||||
from src import openai_compatible as oc
|
||||
from src.vendor_capabilities import register, VendorCapabilities
|
||||
register(VendorCapabilities(vendor='minimax', model='MiniMax-M2', reasoning=False))
|
||||
captured_kwargs: list[dict] = []
|
||||
def _fake_send(client, request, *, capabilities):
|
||||
captured_kwargs.append({"model": request.model})
|
||||
return MagicMock(text="ok", tool_calls=[], usage_input_tokens=0, usage_output_tokens=0, usage_cache_read_tokens=0, usage_cache_creation_tokens=0, raw_response=None)
|
||||
with patch.object(oc, "send_openai_compatible", side_effect=_fake_send), \
|
||||
patch("src.ai_client._ensure_minimax_client", return_value=MagicMock()), \
|
||||
patch("src.ai_client._get_deepseek_tools", return_value=[]):
|
||||
ai_client._send_minimax("system", "user", ".", None, "", False, None, None, None)
|
||||
assert len(captured_kwargs) >= 1
|
||||
|
||||
Reference in New Issue
Block a user