mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-29 01:42:19 +00:00
fix(adapter): gate thinking blocks by target
This commit is contained in:
parent
4bf2196a57
commit
29126ea4de
2 changed files with 54 additions and 2 deletions
|
|
@ -625,11 +625,15 @@ class LiteLLMAnthropicMessagesAdapter:
|
|||
assistant_message = ChatCompletionAssistantMessage(
|
||||
role="assistant",
|
||||
content=assistant_content,
|
||||
thinking_blocks=(thinking_blocks if len(thinking_blocks) > 0 else None),
|
||||
)
|
||||
if len(tool_calls) > 0:
|
||||
assistant_message["tool_calls"] = tool_calls
|
||||
if len(thinking_blocks) > 0:
|
||||
if len(thinking_blocks) > 0 and (
|
||||
model is None
|
||||
or LiteLLMAnthropicMessagesAdapter.is_anthropic_claude_model(
|
||||
model
|
||||
)
|
||||
):
|
||||
assistant_message["thinking_blocks"] = thinking_blocks
|
||||
reasoning_content = reasoning_content_from_thinking_blocks(thinking_blocks)
|
||||
if reasoning_content:
|
||||
|
|
|
|||
|
|
@ -481,6 +481,54 @@ def test_translate_anthropic_messages_to_openai_thinking_blocks():
|
|||
assert result[1]["tool_calls"][0]["id"] == "toolu_01234"
|
||||
|
||||
|
||||
def test_translate_anthropic_messages_to_openai_keeps_thinking_blocks_for_claude():
|
||||
anthropic_messages = [
|
||||
AnthopicMessagesAssistantMessageParam(
|
||||
role="assistant",
|
||||
content=[
|
||||
{
|
||||
"type": "thinking",
|
||||
"thinking": "My reasoning here.",
|
||||
"signature": "sig123",
|
||||
},
|
||||
{"type": "text", "text": "Answer text."},
|
||||
],
|
||||
)
|
||||
]
|
||||
|
||||
result = LiteLLMAnthropicMessagesAdapter().translate_anthropic_messages_to_openai(
|
||||
messages=anthropic_messages,
|
||||
model="anthropic/claude-sonnet-4-5",
|
||||
)
|
||||
|
||||
assert result[0]["thinking_blocks"][0]["thinking"] == "My reasoning here."
|
||||
assert result[0]["reasoning_content"] == "My reasoning here."
|
||||
|
||||
|
||||
def test_translate_anthropic_messages_to_openai_omits_thinking_blocks_for_non_claude():
|
||||
anthropic_messages = [
|
||||
AnthopicMessagesAssistantMessageParam(
|
||||
role="assistant",
|
||||
content=[
|
||||
{
|
||||
"type": "thinking",
|
||||
"thinking": "My reasoning here.",
|
||||
"signature": "sig123",
|
||||
},
|
||||
{"type": "text", "text": "Answer text."},
|
||||
],
|
||||
)
|
||||
]
|
||||
|
||||
result = LiteLLMAnthropicMessagesAdapter().translate_anthropic_messages_to_openai(
|
||||
messages=anthropic_messages,
|
||||
model="openai/my-vllm-model",
|
||||
)
|
||||
|
||||
assert "thinking_blocks" not in result[0]
|
||||
assert result[0]["reasoning_content"] == "My reasoning here."
|
||||
|
||||
|
||||
def test_translate_anthropic_messages_to_openai_drops_bridge_encrypted_reasoning_blocks():
|
||||
"""A session that moves from an OpenAI reasoning model to a chat provider replays reasoning only OpenAI can read.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue