Skip to content

Add reasoning_content to ChatCompletions #415

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
xsoutline opened this issue Apr 2, 2025 · 2 comments
Open

Add reasoning_content to ChatCompletions #415

xsoutline opened this issue Apr 2, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@xsoutline
Copy link

xsoutline commented Apr 2, 2025

delta = chunk.choices[0].delta
# Handle text
if delta.content:

在以上代码的位置需要添加处理reasoning_content的流式响应信息事件,或者添加能够添加自定义事件处理程序
示例:

                delta = chunk.choices[0].delta

                # 尝试获取 reasoning_content(模型思考部分),防止属性不存在使用 getattr
                reasoning = getattr(delta, "reasoning_content", None)
                if reasoning:
                    print(reasoning, end='', flush=True)

                # Handle text
                if delta.content:
@rm-openai rm-openai added the enhancement New feature or request label Apr 2, 2025
@rm-openai rm-openai changed the title 添加ChatCompletion中的reasoning_content事件支持 Add reasoning_content to ChatCompletions Apr 2, 2025
@weixiewen
Copy link

While...delta is from ChoiceDelta, which is from openai types chat...

@Ddper
Copy link
Contributor

Ddper commented Apr 15, 2025

Hi @rm-openai I create a PR to solve this issue.
If using reasoning model, it will yield reasoning_content before yield content. It'll yield a title before yield the real content so the user can split the content and reasoning content. Another way is add a <think></think> tag.
Need your opinion.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants