mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-17 23:51:30 +00:00
fix(anthropic): drop empty reasoning sentinel
This commit is contained in:
parent
af42ce7209
commit
4eabe4367e
2 changed files with 31 additions and 1 deletions
|
|
@ -664,7 +664,9 @@ class LiteLLMAnthropicMessagesAdapter:
|
|||
if len(tool_calls) > 0:
|
||||
assistant_message["tool_calls"] = tool_calls # type: ignore
|
||||
assistant_message["reasoning_content"] = (
|
||||
"".join(reasoning_content_parts) if len(reasoning_content_parts) > 0 else " "
|
||||
"".join(reasoning_content_parts)
|
||||
if len(reasoning_content_parts) > 0
|
||||
else None
|
||||
) # type: ignore
|
||||
if len(thinking_blocks) > 0:
|
||||
assistant_message["thinking_blocks"] = thinking_blocks # type: ignore
|
||||
|
|
|
|||
|
|
@ -1007,6 +1007,34 @@ def test_translate_anthropic_messages_to_openai_tool_use_with_signature():
|
|||
)
|
||||
|
||||
|
||||
def test_translate_anthropic_messages_to_openai_tool_use_without_thinking_blocks():
|
||||
anthropic_messages = [
|
||||
AnthropicMessagesUserMessageParam(
|
||||
role="user",
|
||||
content=[{"type": "text", "text": "Use the weather tool."}],
|
||||
),
|
||||
AnthopicMessagesAssistantMessageParam(
|
||||
role="assistant",
|
||||
content=[
|
||||
{
|
||||
"type": "tool_use",
|
||||
"id": "toolu_01234",
|
||||
"name": "get_weather",
|
||||
"input": {"location": "Boston"},
|
||||
}
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
adapter = LiteLLMAnthropicMessagesAdapter()
|
||||
result = adapter.translate_anthropic_messages_to_openai(messages=anthropic_messages)
|
||||
|
||||
assert len(result) == 2
|
||||
assert result[1]["role"] == "assistant"
|
||||
assert len(result[1]["tool_calls"]) == 1
|
||||
assert result[1].get("reasoning_content") is None
|
||||
|
||||
|
||||
def test_translate_anthropic_messages_to_openai_tool_result_with_multiple_content_items():
|
||||
"""
|
||||
Test that tool_result with multiple content items creates a single tool message
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue