-
-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: 移除流式响应中MiniMax思考内容的输出 #7314
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
3374629
53fd579
129875f
21c922c
5a8332b
13ade24
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -537,6 +537,10 @@ async def _query_stream( | |||||||||||||||||||||||||||||||||
| llm_response = LLMResponse("assistant", is_chunk=True) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| state = ChatCompletionStreamState() | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Track partial thinking tags across chunks for MiniMax-style reasoning | ||||||||||||||||||||||||||||||||||
| thinking_buffer = "" | ||||||||||||||||||||||||||||||||||
| in_thinking_block = False | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| async for chunk in stream: | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+550
to
555
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 variable # Track partial thinking tags across chunks for MiniMax-style reasoning
thinking_buffer = ""
thinking_pattern = re.compile(r"<think>(.*?)</think>", re.DOTALL)
async for chunk in stream:
llm_response.result_chain = None |
||||||||||||||||||||||||||||||||||
| if not chunk.choices: | ||||||||||||||||||||||||||||||||||
|
|
@@ -568,10 +572,49 @@ async def _query_stream( | |||||||||||||||||||||||||||||||||
| if delta and delta.content: | ||||||||||||||||||||||||||||||||||
| # Don't strip streaming chunks to preserve spaces between words | ||||||||||||||||||||||||||||||||||
| completion_text = self._normalize_content(delta.content, strip=False) | ||||||||||||||||||||||||||||||||||
| llm_response.result_chain = MessageChain( | ||||||||||||||||||||||||||||||||||
| chain=[Comp.Plain(completion_text)], | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| _y = True | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Handle partial think... think tags that may span multiple chunks (MiniMax) | ||||||||||||||||||||||||||||||||||
| # Prepend any leftover thinking content from previous chunk | ||||||||||||||||||||||||||||||||||
| if thinking_buffer: | ||||||||||||||||||||||||||||||||||
| completion_text = thinking_buffer + completion_text | ||||||||||||||||||||||||||||||||||
| thinking_buffer = "" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Find all thinking blocks in this chunk | ||||||||||||||||||||||||||||||||||
| thinking_pattern = re.compile(r"<think>(.*?)</think>", re.DOTALL) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Extract complete thinking blocks | ||||||||||||||||||||||||||||||||||
| for match in thinking_pattern.finditer(completion_text): | ||||||||||||||||||||||||||||||||||
| think_content = match.group(1).strip() | ||||||||||||||||||||||||||||||||||
| if think_content: | ||||||||||||||||||||||||||||||||||
| if llm_response.reasoning_content: | ||||||||||||||||||||||||||||||||||
| llm_response.reasoning_content += "\n" + think_content | ||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||
| llm_response.reasoning_content = think_content | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| for match in thinking_pattern.finditer(completion_text): | |
| think_content = match.group(1).strip() | |
| if think_content: | |
| if llm_response.reasoning_content: | |
| llm_response.reasoning_content += "\n" + think_content | |
| else: | |
| llm_response.reasoning_content = think_content | |
| # Extract complete thinking blocks | |
| for match in thinking_pattern.finditer(completion_text): | |
| think_content = match.group(1).strip() | |
| if think_content: | |
| if llm_response.reasoning_content: | |
| llm_response.reasoning_content += "\n" + think_content | |
| else: | |
| llm_response.reasoning_content = think_content | |
| _y = True |
Outdated
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.
Calling strip() on every chunk will remove leading and trailing spaces that are essential for correctly joining words split across chunk boundaries. This negates the strip=False setting used in _normalize_content and will cause words to be merged incorrectly (e.g., "Hello " and "world" becoming "Helloworld").
Uh oh!
There was an error while loading. Please reload this page.