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:
+11
-4
@@ -2255,8 +2255,8 @@ def _send_grok(md_content: str, user_message: str, base_dir: str,
|
||||
patch_callback: Optional[Callable[[str, str], Optional[str]]] = None) -> str:
|
||||
from src.openai_compatible import OpenAICompatibleRequest
|
||||
client = _ensure_grok_client()
|
||||
client = _ensure_grok_client()
|
||||
tools: list[dict[str, Any]] | None = _get_deepseek_tools() or None
|
||||
caps = get_capabilities("grok", _model)
|
||||
with _grok_history_lock:
|
||||
user_content = user_message
|
||||
if file_items:
|
||||
@@ -2267,17 +2267,22 @@ def _send_grok(md_content: str, user_message: str, base_dir: str,
|
||||
_grok_history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"})
|
||||
else:
|
||||
_grok_history.append({"role": "user", "content": user_content})
|
||||
_grok_history.append({"role": "user", "content": user_content})
|
||||
def _build_grok_request(_round_idx: int) -> OpenAICompatibleRequest:
|
||||
with _grok_history_lock:
|
||||
messages: list[dict[str, Any]] = [{"role": "system", "content": f"{_get_combined_system_prompt()}\n\n<context>\n{md_content}\n</context>"}]
|
||||
messages.extend(_grok_history)
|
||||
extra_body: dict[str, Any] = {}
|
||||
if caps.web_search:
|
||||
extra_body["search_parameters"] = {"mode": "auto"}
|
||||
if caps.x_search:
|
||||
extra_body.setdefault("search_parameters", {})
|
||||
extra_body["search_parameters"]["sources"] = [{"type": "x"}]
|
||||
return OpenAICompatibleRequest(
|
||||
messages=messages, model=_model, temperature=_temperature, top_p=_top_p,
|
||||
max_tokens=_max_tokens, stream=stream, stream_callback=stream_callback,
|
||||
tools=tools, tool_choice="auto" if tools else "auto",
|
||||
extra_body=extra_body or None,
|
||||
)
|
||||
caps = get_capabilities("grok", _model)
|
||||
return run_with_tool_loop(
|
||||
client, _build_grok_request, capabilities=caps,
|
||||
pre_tool_callback=pre_tool_callback, qa_callback=qa_callback, stream_callback=stream_callback,
|
||||
@@ -2295,9 +2300,11 @@ def _send_minimax(md_content: str, user_message: str, base_dir: str,
|
||||
stream: bool = False,
|
||||
pre_tool_callback: Optional[Callable[[str, str, Optional[Callable[[str], str]]], Optional[str]]] = None,
|
||||
qa_callback: Optional[Callable[[str], str]] = None,
|
||||
stream_callback: Optional[Callable[[str], None]] = None,
|
||||
patch_callback: Optional[Callable[[str, str], Optional[str]]] = None) -> str:
|
||||
from src.openai_compatible import OpenAICompatibleRequest
|
||||
_ensure_minimax_client()
|
||||
tools: list[dict[str, Any]] | None = _get_deepseek_tools() or None
|
||||
_repair_minimax_history(_minimax_history)
|
||||
if discussion_history and not _minimax_history:
|
||||
_minimax_history.append({"role": "user", "content": f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"})
|
||||
@@ -2325,7 +2332,7 @@ def _send_minimax(md_content: str, user_message: str, base_dir: str,
|
||||
patch_callback=patch_callback, base_dir=base_dir, vendor_name="minimax",
|
||||
history_lock=_minimax_history_lock, history=_minimax_history,
|
||||
trim_func=lambda h: _trim_minimax_history(_build_minimax_request(0).messages, h),
|
||||
reasoning_extractor=_extract_minimax_reasoning,
|
||||
reasoning_extractor=_extract_minimax_reasoning if caps.reasoning else None,
|
||||
)
|
||||
|
||||
#endregion: MiniMax Provider
|
||||
|
||||
@@ -25,7 +25,7 @@ class OpenAICompatibleRequest:
|
||||
tool_choice: str = "auto"
|
||||
stream: bool = False
|
||||
stream_callback: Optional[Callable[[str], None]] = None
|
||||
|
||||
extra_body: Optional[dict[str, Any]] = None
|
||||
def _to_dict_tool_call(tc: Any) -> dict[str, Any]:
|
||||
return {
|
||||
"id": getattr(tc, "id", None),
|
||||
@@ -75,6 +75,8 @@ def send_openai_compatible(
|
||||
if request.tools is not None:
|
||||
kwargs["tools"] = request.tools
|
||||
kwargs["tool_choice"] = request.tool_choice
|
||||
if request.extra_body:
|
||||
kwargs["extra_body"] = request.extra_body
|
||||
try:
|
||||
if request.stream:
|
||||
return _send_streaming(client, kwargs, request.stream_callback)
|
||||
|
||||
Reference in New Issue
Block a user