-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Docs] Fix the example code of streaming chat completions in reasoning #21825
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
Conversation
…g_outputs.md Signed-off-by: wangzi <[email protected]>
[Docs] Fix the example code of streaming chat completions in reasonin…
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.
Code Review
This pull request correctly fixes a bug in the example code for streaming chat completions with reasoning, where empty reasoning_content
could cause the actual content
to be missed. The proposed change is logically sound and addresses the issue.
docs/features/reasoning_outputs.md
Outdated
if ( | ||
hasattr(chunk.choices[0].delta, "reasoning_content") | ||
and chunk.choices[0].delta.reasoning_content |
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 added checks for chunk.choices[0].delta.reasoning_content
and chunk.choices[0].delta.content
are necessary to avoid errors when these attributes are not present in the response. This ensures the code handles different response formats gracefully.
if ( | |
hasattr(chunk.choices[0].delta, "reasoning_content") | |
and chunk.choices[0].delta.reasoning_content | |
if ( | |
hasattr(chunk.choices[0].delta, "reasoning_content") | |
and chunk.choices[0].delta.reasoning_content | |
): |
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
reasoning_content = None | ||
content = None | ||
# Check the content is reasoning_content or content | ||
if hasattr(chunk.choices[0].delta, "reasoning_content"): | ||
if ( | ||
hasattr(chunk.choices[0].delta, "reasoning_content") | ||
and chunk.choices[0].delta.reasoning_content | ||
): | ||
reasoning_content = chunk.choices[0].delta.reasoning_content | ||
elif hasattr(chunk.choices[0].delta, "content"): | ||
elif ( | ||
hasattr(chunk.choices[0].delta, "content") | ||
and chunk.choices[0].delta.content | ||
): |
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.
reasoning_content = None | |
content = None | |
# Check the content is reasoning_content or content | |
if hasattr(chunk.choices[0].delta, "reasoning_content"): | |
if ( | |
hasattr(chunk.choices[0].delta, "reasoning_content") | |
and chunk.choices[0].delta.reasoning_content | |
): | |
reasoning_content = chunk.choices[0].delta.reasoning_content | |
elif hasattr(chunk.choices[0].delta, "content"): | |
elif ( | |
hasattr(chunk.choices[0].delta, "content") | |
and chunk.choices[0].delta.content | |
): | |
reasoning_content = getattr(chunk.choices[0].delta, "reasoning_content", None) or None | |
content = getattr(chunk.choices[0].delta, "content", None) or None |
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.
Thanks for the advice! The code has been simplified.
Signed-off-by: wangzi <[email protected]>
[Docs] Fix the example code of streaming chat completions in reasoning_outputs.md
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.
LGTM, thanks for the improvement!
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]> Signed-off-by: shuw <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]> Signed-off-by: shuw <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]> Signed-off-by: x22x22 <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]> Signed-off-by: x22x22 <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]> Signed-off-by: Jinzhen Lin <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]> Signed-off-by: Noam Gat <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]> Signed-off-by: Paul Pak <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]> Signed-off-by: Boyuan Feng <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]> Signed-off-by: Diego-Castan <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]>
vllm-project#21825) Signed-off-by: wangzi <[email protected]> Co-authored-by: wangzi <[email protected]> Co-authored-by: Zi Wang <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.