fix(openai-compatible): preserve non-stream reasoning content#3099
Open
Epochex wants to merge 1 commit into
Open
fix(openai-compatible): preserve non-stream reasoning content#3099Epochex wants to merge 1 commit into
Epochex wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds support for handling reasoning traces in non-streaming responses for OpenAI-compatible models, such as those from vLLM or SGLang. A new method, _wrap_non_stream_reasoning_content, was implemented to extract reasoning data from the reasoning or reasoning_content fields and wrap it in tags if not already present in the main content. Additionally, the version was bumped to 0.0.51, and several unit tests were added to ensure correct handling of reasoning content alongside tool calls and existing thinking blocks. I have no feedback to provide.
2c15474 to
2d06469
Compare
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
Related to #2945.
The OpenAI-compatible streaming path already normalizes both
delta.reasoninganddelta.reasoning_contentinto Dify's<think>...</think>format. The non-streaming chat response path still only usedmessage.content, so vLLM/SGLang-style responses that put the reasoning trace inmessage.reasoningdropped that trace before Dify could render or filter it.This PR applies the same normalization to non-streaming chat responses:
message.reasoningandmessage.reasoning_contentbefore the final answer<think>unchanged to avoid double wrappingThis is separate from the earlier streaming fix in #2741 and the
extensions/openai_compatibleendpoint fix in #2676; it covers the model plugin's non-streamingchoices[].messagehandler.Change Type
Screenshots / Videos
N/A. This is a response-normalization fix covered by unit and package tests.
message.reasoningonly surfacedmessage.content.<think>...</think>before the final answer, matching the streaming path.LLM Plugin Checklist
Areas affected by this change (check all that apply)
Version
versioninmanifest.yaml(not the one undermeta)dify_plugin>=0.5.0is declared inpyproject.tomland locked inuv.lockNote: this PR bumps
openai_api_compatibleto0.0.51because open PRs #3091 and #3092 already use the pending0.0.50bump for the same plugin.Testing
uv run --project models/openai_api_compatible --frozen --with pytest pytest models/openai_api_compatible/testsuv run --project models/openai_api_compatible --frozen python -m py_compile models/openai_api_compatible/models/llm/llm.py models/openai_api_compatible/tests/test_handle_response.pyuv run --with requests --with dify_plugin python .scripts/toolkit/uploader/upload-package.py -d models/openai_api_compatible -t dummy-token --plugin-daemon-path .scripts/dify-plugin-windows-amd64.exe -u https://marketplace.dify.ai -f --test.\.scripts\dify-plugin-windows-amd64.exe plugin package models/openai_api_compatible --output_path test-openai-api-compatible-package.difypkguv run --frozen --with pytest pytestLocal result: 28 passed, 2 warnings from existing dependencies.