Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions pageindex/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1830,19 +1830,22 @@ def chat(
given = extra_body or {}
# Anthropic's effort takes no "none": a Claude model's own
# thinking switch stands in, unless the caller sent one.
swap = (reasoning_effort == "none" and "thinking" not in given
swap = (reasoning_effort == "none"
and claude_none_switch(model or self.chat_model))
if swap and "reasoning_effort" in swap:
if swap and "thinking" in given:
body = given
elif swap and "reasoning_effort" in swap:
raise PageIndexAPIError(
f"{model or self.chat_model} can't turn thinking off, "
"so it can't honor reasoning_effort='none'; pass "
"'low' or leave it unset.")
# Anthropic's own effort field, beside the caller's other
# output_config keys — theirs still win.
body = {**given, **swap} if swap else {
**given, "output_config": {
"effort": reasoning_effort,
**given.get("output_config", {})}}
else:
# Anthropic's own effort field, beside the caller's other
# output_config keys — theirs still win.
body = {**given, **swap} if swap else {
**given, "output_config": {
"effort": reasoning_effort,
**given.get("output_config", {})}}
return self._messages(
messages, model=model, stream=stream, doc_id=doc_id,
folder_id=folder_id, collection_id=collection_id,
Expand Down
31 changes: 25 additions & 6 deletions tests/test_local_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5200,6 +5200,18 @@ def test_messages_thinking_passes_through(client, fake_anthropic):
assert "thinking" not in calls[0]


@needs_anthropic
def test_messages_explicit_thinking_uses_the_default_claude_effort(client, fake_anthropic):
calls = fake_anthropic([
_anthropic_message([{"type": "text", "text": "ok"}], "end_turn")])

client.chat("q", protocol="messages", model="anthropic/claude-haiku-5-5",
reasoning_effort="none", extra_body={"thinking": {"type": "adaptive"}})

assert calls[0]["thinking"] == {"type": "adaptive"}
assert "output_config" not in calls[0]


@needs_anthropic
def test_messages_extra_body_merges_into_the_wire_body(client, fake_anthropic):
"""The anthropic SDK merges extra_body keys into the request JSON —
Expand Down Expand Up @@ -6947,8 +6959,8 @@ def test_chat_protocol_messages_none_turns_claude_thinking_off(client, monkeypat
"""Anthropic's effort takes no "none": a Claude model gets its own
thinking switch instead, as the LiteLLM lane sends it (disabled where
the table lacks the model), one that can't turn thinking off raises, and
a caller's own thinking or a model that isn't Claude keeps the effort
field."""
explicit Claude thinking takes precedence. Non-Claude models keep
their own effort semantics."""
seen = []
monkeypatch.setattr(local_chat, "run_messages",
lambda c, messages, **kw: seen.append(kw) or "door")
Expand All @@ -6960,10 +6972,17 @@ def test_chat_protocol_messages_none_turns_claude_thinking_off(client, monkeypat
("kimi-k2-test", {"output_config": {"effort": "none"}})):
client.chat("q", protocol="messages", model=model, reasoning_effort="none")
assert seen[-1]["extra_body"] == body, model
client.chat("q", protocol="messages", model="claude-haiku-5-5",
reasoning_effort="none", extra_body={"thinking": {"type": "adaptive"}})
assert seen[-1]["extra_body"] == {"thinking": {"type": "adaptive"},
"output_config": {"effort": "none"}}
for explicit in (
{"thinking": {"type": "adaptive"}},
{"thinking": {"type": "adaptive"}, "output_config": {"effort": "low"}},
):
client.chat("q", protocol="messages", model="claude-haiku-5-5",
reasoning_effort="none", extra_body=explicit)
assert seen[-1]["extra_body"] == explicit
client.chat("q", protocol="messages", model="kimi-k2-test",
reasoning_effort="none", extra_body={"thinking": {"type": "disabled"}})
assert seen[-1]["extra_body"] == {
"thinking": {"type": "disabled"}, "output_config": {"effort": "none"}}
with pytest.raises(PageIndexAPIError, match="can't turn thinking off"):
client.chat("q", protocol="messages", model="claude-opus-5-5",
reasoning_effort="none")
Expand Down