Skip to content
Merged
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
4 changes: 2 additions & 2 deletions pageindex/local_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,8 @@ def _cut_text(output) -> list:

def _drop_repeated_thinking(chunk, streamed: list) -> None:
"""Blank a closing thinking block's text that repeats what streamed:
LiteLLM's Anthropic stream sends the whole text again beside the
signature. A test fails once it stops; this goes then."""
LiteLLM's Anthropic stream below our floor sends the whole text again
beside the signature, and an install can still land there."""
choices = getattr(chunk, "choices", None)
delta = getattr(choices[0], "delta", None) if choices else None
for block in getattr(delta, "thinking_blocks", None) or ():
Expand Down
4 changes: 2 additions & 2 deletions pageindex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ def _is_unrecoverable(exc: BaseException) -> bool:


# Claude's own ways to turn thinking off, then its lowest effort: the ladder
# down a Claude model's thinking, as LiteLLM sends no thinking field for
# reasoning_effort "none" (BerriAI/litellm#47924, #44298).
# down a Claude model's thinking, as LiteLLM below 1.110 sends no thinking
# field for reasoning_effort "none" (BerriAI/litellm#47924, #44298).
_CLAUDE_LADDER = ({"thinking": {"type": "disabled"}}, {"thinking": {"type": "between_tools"}},
{"reasoning_effort": "low"})
_CLAUDE_ROUTES = ("anthropic", "bedrock", "vertex_ai", "azure_ai", "databricks")
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ openai = ">=2.45.0"
# loses its empty content (0.18.1), Claude thinking fails validation (<0.20).
openai-agents = ">=0.20.0"
mcp = ">=1.19.0,<3"
# <1.106: from 1.106 a call with tools imports LiteLLM's proxy MCP handler,
# which needs mcp>=2.2 (BerriAI/litellm#46045). The fix (#45961) is in the
# 1.107 line: lift the cap at its first clean release (1.107.0 was malware).
litellm = ">=1.105.1,<1.106"
litellm = ">=1.109.0"
PyPDF2 = ">=3.0.0"
pypdfium2 = ">=5"
sortedcontainers = ">=2.4.0"
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# <1.106 until LiteLLM ships its mcp import fix: see pyproject.toml.
litellm>=1.105.1,<1.106
litellm>=1.109.0
openai>=2.45.0
requests>=2.28.0
# MCP retries use Retry(allowed_methods=...), added in urllib3 1.26.
Expand Down
31 changes: 2 additions & 29 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4226,33 +4226,6 @@ def test_a_refusal_is_one_litellm_puts_on_no_cause_or_on_a_param():
assert not _refusal(litellm.AuthenticationError(**args))


def test_litellm_still_drops_a_databricks_switch_beside_none():
"""Fails once LiteLLM keeps a thinking switch sent beside
reasoning_effort "none" on Databricks, as it does on Claude's other
routes: then the fill hook (local_chat._register_fill) needn't take the
"none" off any more."""
pytest.importorskip("litellm")
from litellm.utils import get_optional_params
assert "thinking" not in get_optional_params(
model="databricks-claude-sonnet-5", custom_llm_provider="databricks",
reasoning_effort="none", thinking={"type": "disabled"})


@pytest.mark.parametrize("model", ["claude-haiku-5-5", "claude-sonnet-5", "claude-opus-5",
"claude-sonnet-5-5"])
def test_litellm_still_sends_claude_no_thinking_for_none(model):
"""Fails once LiteLLM itself turns the model's thinking off for "none"
(BerriAI/litellm#47924, #44298), which can show only after the
litellm <1.106 cap is lifted: then the LiteLLM routes no longer need
_claude_none for it. Keep its _CLAUDE_NONE row: the Messages lane
still needs it, as Anthropic's effort takes no "none"."""
pytest.importorskip("litellm")
from litellm.utils import get_optional_params
assert "thinking" not in get_optional_params(
model=model, custom_llm_provider="anthropic", reasoning_effort="none",
drop_params=True)


def test_parse_pages_keeps_whitespace_tolerance():
"""0.2.10 accepted whitespace around parts (int() tolerance); the SDK
surface keeps that while the tool layer stays on the strict pattern."""
Expand Down Expand Up @@ -5122,7 +5095,7 @@ def test_summary_effort_ladder_is_what_litellm_would_send():
"""On LiteLLM's real map: a level LiteLLM would drop is skipped, read
as LiteLLM reads it (azure/gpt-5-nano as gpt-5-nano); a model it
doesn't know on an OpenAI-format API gets the effort as is, on any
other none it would drop; no rung LiteLLM sends as thinking turned on
other only what LiteLLM would send; no rung LiteLLM sends as thinking turned on
(off stays); a Claude model, as LiteLLM tells one, goes down Claude's own
switches, from its known one on, past disabled where LiteLLM's map says
it always thinks; a rung this process saw refused is left out."""
Expand All @@ -5142,7 +5115,7 @@ def efforts(*levels, forced=False):
("azure/my-gpt-deployment", efforts("none", "low", forced=True)),
("fireworks_ai/accounts/fireworks/models/test-unknown",
efforts("none", "low", forced=True)),
("bedrock/qwen.test-unknown-v9", []),
("bedrock/qwen.test-unknown-v9", efforts("none", "low")),
("bedrock/arn:aws:bedrock:us-east-1:123456789012:"
"application-inference-profile/test", []),
("bedrock/us.amazon.nova-2-lite-v1:0", []),
Expand Down
36 changes: 21 additions & 15 deletions tests/test_local_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1786,21 +1786,15 @@ def _model_key_missing():


@needs_agents
@pytest.mark.parametrize("stream, blank", [(False, True), (True, True),
(True, False)])
@pytest.mark.parametrize("stream", [False, True])
def test_claude_thinking_reaches_the_anthropic_wire_once(client, store_path,
monkeypatch, stream,
blank):
monkeypatch, stream):
"""Through LiteLLM's own Anthropic parsing and request building, with
no effort set: the run's next request carries the signed thinking
block once, a stream's closing repeat of its text blanked. Without the
blanking LiteLLM's stream must still repeat it, or the blanking goes."""
block once."""
pytest.importorskip("litellm")
from litellm.llms.custom_httpx.http_handler import (AsyncHTTPHandler,
HTTPHandler)
if not blank:
monkeypatch.setattr(local_chat, "_drop_repeated_thinking",
lambda chunk, streamed: None)
monkeypatch.setenv("ANTHROPIC_API_KEY", "sk-ant-test")
doc_id = seed_doc(store_path, "pi-a", "report.pdf")
thinking = {"type": "thinking", "thinking": "plan step",
Expand Down Expand Up @@ -1838,15 +1832,27 @@ async def fake_apost(self, url=None, *args, **kwargs):
assert not {"thinking", "output_config"} & set(bodies[0])
turn = next(m for m in bodies[1]["messages"] if m["role"] == "assistant")
sent = [b for b in turn["content"] if b["type"] == "thinking"]
if not blank:
assert sent == [{**thinking, "thinking": "plan stepplan step"}], (
"LiteLLM stopped repeating streamed thinking: drop "
"_drop_repeated_thinking")
return
assert sent == [thinking]
assert result["messages"][0]["thinking_blocks"] == [thinking]


def test_a_closing_thinking_block_repeating_the_stream_is_blanked():
"""LiteLLM below our floor repeats the streamed text in the signed
closing block; only that repeat is blanked."""
for parts, closing, kept in ((["plan ", "step"], "plan step", ""),
(["plan ", "step"], "", ""),
([], "plan step", "plan step")):
streamed = []
blocks = [{"type": "thinking", "thinking": part} for part in parts]
blocks.append({"type": "thinking", "thinking": closing, "signature": "SIG1"})
for block in blocks:
chunk = types.SimpleNamespace(choices=[types.SimpleNamespace(
delta=types.SimpleNamespace(thinking_blocks=[block]))])
local_chat._drop_repeated_thinking(chunk, streamed)
assert blocks[-1]["thinking"] == kept
assert streamed == []


def test_repeated_answers_keep_their_own_fields():
"""Records keep conversation order: a repeated answer (or a reused call
id) gets its own reply's fields back, not the latest one's."""
Expand Down Expand Up @@ -4391,7 +4397,7 @@ def test_litellm_model_settings_list_matches_litellm_model(monkeypatch):
"response_include": ["reasoning.encrypted_content"],
"top_logprobs": 2, "extra_query": {"q": "1"}, "extra_body": {"x": 1},
"extra_headers": {"X-Probe": "1"}, "extra_args": {"y": 2},
"retry": {"max_retries": 1},
"retry": {"max_retries": 1}, "timeout": 5.0,
"context_management": [{"type": "compaction",
"compact_threshold": 1000}],
"prompt_cache_options": {"mode": "explicit", "ttl": "30m"},
Expand Down
Loading