-
Notifications
You must be signed in to change notification settings - Fork 11.3k
feat: Add <think> at the beginning #1629
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,26 @@ | ||
| # 渠道而外设置说明 | ||
| # 渠道额外设置说明 | ||
|
|
||
| 该配置用于设置一些额外的渠道参数,可以通过 JSON 对象进行配置。主要包含以下两个设置项: | ||
| 该配置用于设置一些额外的渠道参数,可以通过前端页面进行配置。主要包含以下设置项: | ||
|
|
||
| 1. force_format | ||
| 1. 强制格式化 | ||
| - 用于标识是否对数据进行强制格式化为 OpenAI 格式 | ||
| - 类型为布尔值,设置为 true 时启用强制格式化 | ||
|
|
||
| 2. proxy | ||
| - 用于配置网络代理 | ||
| - 类型为字符串,填写代理地址(例如 socks5 协议的代理地址) | ||
|
|
||
| 3. thinking_to_content | ||
| - 用于标识是否将思考内容`reasoning_content`转换为`<think>`标签拼接到内容中返回 | ||
| - 类型为布尔值,设置为 true 时启用思考内容转换 | ||
| 2. 思考内容转换 | ||
| - 用于标识是否将思考内容`reasoning_content`转换为`<think>`标签拼接到内容中返回 | ||
|
|
||
| -------------------------------------------------------------- | ||
| 3. 透传请求体 | ||
| - 用于将自定义请求体发送到上游 | ||
|
|
||
| ## JSON 格式示例 | ||
| 4. 代理地址 | ||
| - 用于配置网络代理,需要填写代理地址(支持socks5协议) | ||
|
|
||
| 以下是一个示例配置,启用强制格式化并设置了代理地址: | ||
| 5. 系统提示词 | ||
| - 输入系统提示词,用户的系统提示词将优先于此设置 | ||
| - 用户优先:如果用户在请求中指定了系统提示词,将优先使用用户的设置 | ||
|
|
||
| ```json | ||
| { | ||
| "force_format": true, | ||
| "thinking_to_content": true, | ||
| "proxy": "socks5://xxxxxxx" | ||
| } | ||
| ``` | ||
| 6. 系统提示词拼接 | ||
| - 如果用户请求中包含系统提示词,则使用此设置拼接到用户的系统提示词前面 | ||
|
|
||
| -------------------------------------------------------------- | ||
|
|
||
| 通过调整上述 JSON 配置中的值,可以灵活控制渠道的额外行为,比如是否进行格式化以及使用特定的网络代理。 | ||
| 7. add_think_first | ||
| - 在通过vllm和sglang自部署模型使用一些自带`<think>\n`的`chat_template`时,将`<think>\n`标签拼接到响应的开头 |
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
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
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Single-chunk streaming bug: prefix not applied to the only chunk.
When the stream consists of a single data chunk, the first (and only) chunk is flushed in the “last response” block with addThink=false, so “\n” is never prepended. Fix by reusing the same firstChunk&&addThinkFirst logic for the final flush.
📝 Committable suggestion
🤖 Prompt for AI Agents
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.
The last chunk doesn't need
<think>\n.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.
@jiajunly Thank you for the clarification! You're absolutely right.
Looking at the streaming logic more carefully, I can see that the
<think>\nprefix is only intended for the very first chunk of the stream, and the final flush withaddThink=falseis correct by design. Even in single-chunk scenarios, the prefix would have been applied during the normal scanner processing loop, not during the final response handling.My analysis was incorrect - the current implementation properly ensures only the first chunk gets the prefix, and the last chunk (whether it's part of a multi-chunk or single-chunk stream) correctly doesn't receive the prefix.
✏️ Learnings added
🧠 Learnings used