GH-6026: Pass reasoning_content back to DeepSeek API in multi-turn conversations#6189
Open
suryateja-g13 wants to merge 1 commit into
Open
Conversation
…sations When DeepSeek reasoning models (e.g. deepseek-reasoner) return reasoning_content, the API requires that field to be echoed back in subsequent request messages. The previous createRequest() always passed null as the last argument of ChatCompletionMessage for ASSISTANT turns, silently dropping the stored reasoning_content and causing HTTP 400 errors on second and later turns. Fix: when mapping an AssistantMessage back to a ChatCompletionMessage, check whether it is a DeepSeekAssistantMessage and, if so, forward its getReasoningContent() value. Plain AssistantMessage instances (non-reasoning models) are unaffected and still emit null reasoning_content. Fixes: spring-projects#6026 Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>
Contributor
Author
|
The CI failure is the pre-existing flaky test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DeepSeekChatModel.createRequest()to forwardreasoning_contentfromDeepSeekAssistantMessagewhen rebuilding conversation history for subsequent API callsdeepseek-reasoner) require thereasoning_contentfield to be echoed back in ASSISTANT messages in the conversation history — without it, the API returns HTTP 400:"The reasoning_content in the thinking mode must be passed back to the API."createRequest()always passednullasreasoning_contentinChatCompletionMessagefor ASSISTANT turns, silently dropping the stored valueAssistantMessageis actually aDeepSeekAssistantMessageand, if so, readsgetReasoningContent()and passes it forwardAssistantMessage(non-reasoning models likedeepseek-chat) still emitnullreasoning_content and are unaffectedTest plan
./mvnw -pl models/spring-ai-deepseek test -Dtest="DeepSeekChatCompletionRequestTests"— 3 tests pass (1 existing + 2 new)reasoningContentIsPassedBackForDeepSeekAssistantMessageverifies the reasoning content is forwardednullReasoningContentIsOmittedForPlainAssistantMessageverifies non-reasoning models are unaffectedFixes: #6026