-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
fix(anthropic): add reasoning_content when converting thinking blocks to OpenAI format #27947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
410ce76
649eb2d
65d6ad8
a6494e6
867470f
de457ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -661,6 +661,15 @@ def translate_anthropic_messages_to_openai( # noqa: PLR0915 | |
| assistant_message["tool_calls"] = tool_calls # type: ignore | ||
| if len(thinking_blocks) > 0: | ||
| assistant_message["thinking_blocks"] = thinking_blocks # type: ignore | ||
| # DeepSeek / reasoning models require `reasoning_content` | ||
| # when assistant messages in conversation history contain | ||
| # thinking blocks. Without it, multi-turn requests fail with | ||
| # "The `reasoning_content` in the thinking mode must be | ||
| # passed back to the API". | ||
| first_thinking = thinking_blocks[0] | ||
| assistant_message["reasoning_content"] = first_thinking.get( # type: ignore | ||
| "thinking", "" | ||
| ) | ||
|
Comment on lines
662
to
+672
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR description says the fix was verified end-to-end, but there is no automated test that covers the Rule Used: What: Ensure that any PR claiming to fix an issue ... (source) |
||
| new_messages.append(assistant_message) | ||
|
|
||
| return new_messages | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reasoning_content, butthinking_blockscan contain multipleChatCompletionThinkingBlockentries (andChatCompletionRedactedThinkingBlockentries that have nothinkingfield). If the first block is redacted,.get("thinking", "")returns"", and if there are several real thinking blocks, the subsequent reasoning text is silently dropped. DeepSeek expectsreasoning_contentto reflect the full reasoning chain, so this produces incorrect context in both cases.