Skip to content

Commit 06ddf04

Browse files
fix(minimax): disable thinking by default (#2558)
1 parent d251fcb commit 06ddf04

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

hindsight-api-slim/hindsight_api/engine/providers/openai_compatible_llm.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,11 @@ def _max_tokens_param_name(self) -> str:
656656
# use the widely-supported max_tokens
657657
return "max_tokens"
658658

659+
def _apply_provider_extra_body_defaults(self, extra_body: dict[str, Any]) -> None:
660+
"""Apply provider-specific extra_body defaults while preserving user overrides."""
661+
if self.provider == "minimax":
662+
extra_body.setdefault("thinking", {"type": "disabled"})
663+
659664
async def call(
660665
self,
661666
messages: list[dict[str, str]],
@@ -743,6 +748,7 @@ async def call(
743748

744749
# Provider-specific parameters
745750
extra_body: dict[str, Any] = {**self._config_extra_body}
751+
self._apply_provider_extra_body_defaults(extra_body)
746752
if self.provider == "groq":
747753
call_params["seed"] = DEFAULT_LLM_SEED
748754
# Add service_tier if configured
@@ -1161,6 +1167,7 @@ async def call_with_tools(
11611167

11621168
# Provider-specific parameters
11631169
extra_body: dict[str, Any] = {**self._config_extra_body}
1170+
self._apply_provider_extra_body_defaults(extra_body)
11641171
if self.provider == "groq":
11651172
call_params["seed"] = DEFAULT_LLM_SEED
11661173
if extra_body:
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from types import SimpleNamespace
2+
from unittest.mock import AsyncMock, patch
3+
4+
import pytest
5+
6+
from hindsight_api.engine.providers.openai_compatible_llm import OpenAICompatibleLLM
7+
8+
9+
def _make_minimax(extra_body=None) -> OpenAICompatibleLLM:
10+
return OpenAICompatibleLLM(
11+
provider="minimax",
12+
api_key="test-key",
13+
base_url="",
14+
model="MiniMax-M3",
15+
extra_body=extra_body,
16+
)
17+
18+
19+
def _text_response(content: str = "ok"):
20+
return SimpleNamespace(
21+
error=None,
22+
usage=None,
23+
choices=[
24+
SimpleNamespace(
25+
finish_reason="stop",
26+
message=SimpleNamespace(content=content, tool_calls=None, refusal=None),
27+
)
28+
],
29+
)
30+
31+
32+
def _tool_response():
33+
tool_call = SimpleNamespace(
34+
id="call_minimax_123",
35+
function=SimpleNamespace(name="recall", arguments='{"query": "Project Rin"}'),
36+
)
37+
return SimpleNamespace(
38+
error=None,
39+
usage=None,
40+
choices=[
41+
SimpleNamespace(
42+
finish_reason="tool_calls",
43+
message=SimpleNamespace(content=None, tool_calls=[tool_call], refusal=None),
44+
)
45+
],
46+
)
47+
48+
49+
@pytest.mark.asyncio
50+
async def test_minimax_call_disables_thinking_by_default():
51+
llm = _make_minimax()
52+
llm._client.chat.completions.create = AsyncMock(return_value=_text_response())
53+
54+
with patch("hindsight_api.engine.providers.openai_compatible_llm.get_metrics_collector"):
55+
await llm.call(messages=[{"role": "user", "content": "hi"}], max_retries=0)
56+
57+
assert llm._client.chat.completions.create.call_args.kwargs["extra_body"] == {"thinking": {"type": "disabled"}}
58+
59+
60+
@pytest.mark.asyncio
61+
async def test_minimax_call_preserves_configured_thinking_extra_body():
62+
llm = _make_minimax(extra_body={"thinking": {"type": "enabled"}, "reasoning_split": True})
63+
llm._client.chat.completions.create = AsyncMock(return_value=_text_response())
64+
65+
with patch("hindsight_api.engine.providers.openai_compatible_llm.get_metrics_collector"):
66+
await llm.call(messages=[{"role": "user", "content": "hi"}], max_retries=0)
67+
68+
assert llm._client.chat.completions.create.call_args.kwargs["extra_body"] == {
69+
"thinking": {"type": "enabled"},
70+
"reasoning_split": True,
71+
}
72+
73+
74+
@pytest.mark.asyncio
75+
async def test_minimax_tool_call_disables_thinking_by_default():
76+
llm = _make_minimax()
77+
llm._client.chat.completions.create = AsyncMock(return_value=_tool_response())
78+
79+
with patch("hindsight_api.engine.providers.openai_compatible_llm.get_metrics_collector"):
80+
await llm.call_with_tools(
81+
messages=[{"role": "user", "content": "Search memory."}],
82+
tools=[
83+
{
84+
"type": "function",
85+
"function": {
86+
"name": "recall",
87+
"description": "Recall memories",
88+
"parameters": {
89+
"type": "object",
90+
"properties": {"query": {"type": "string"}},
91+
"required": ["query"],
92+
},
93+
},
94+
}
95+
],
96+
max_retries=0,
97+
)
98+
99+
assert llm._client.chat.completions.create.call_args.kwargs["extra_body"] == {"thinking": {"type": "disabled"}}

0 commit comments

Comments
 (0)