@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 5c8fe389d6
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 14, 22:35 UTC

[Docs] Fix the example code of streaming chat completions in reasoning (#21825)

Signed-off-by: wangzi <3220100013@zju.edu.cn> Co-authored-by: wangzi <3220100013@zju.edu.cn> Co-authored-by: Zi Wang <66560864+BruceW-07@users.noreply.github.com>

Hongsheng Liu committed Jul 30, 2025 at 20:11 UTC 5c8fe389d6fb2b8776d4113d8334d8dd09f78733
2 files changed +12 -14
docs/features/reasoning_outputs.md
+6 -7
@@ -123,13 +123,12 @@ OpenAI Python client library does not officially support `reasoning_content` att
123 printed_content = False
124
125 for chunk in stream:
126 - reasoning_content = None
127 - content = None
128 - # Check the content is reasoning_content or content
129 - if hasattr(chunk.choices[0].delta, "reasoning_content"):
130 - reasoning_content = chunk.choices[0].delta.reasoning_content
131 - elif hasattr(chunk.choices[0].delta, "content"):
132 - content = chunk.choices[0].delta.content
126 + # Safely extract reasoning_content and content from delta,
127 + # defaulting to None if attributes don't exist or are empty strings
128 + reasoning_content = (
129 + getattr(chunk.choices[0].delta, "reasoning_content", None) or None
130 + )
131 + content = getattr(chunk.choices[0].delta, "content", None) or None
132
133 if reasoning_content is not None:
134 if not printed_reasoning_content:
examples/online_serving/openai_chat_completion_with_reasoning_streaming.py
+6 -7
@@ -51,13 +51,12 @@ def main():
51 printed_content = False
52
53 for chunk in stream:
54 - reasoning_content = None
55 - content = None
56 - # Check the content is reasoning_content or content
57 - if hasattr(chunk.choices[0].delta, "reasoning_content"):
58 - reasoning_content = chunk.choices[0].delta.reasoning_content
59 - elif hasattr(chunk.choices[0].delta, "content"):
60 - content = chunk.choices[0].delta.content
54 + # Safely extract reasoning_content and content from delta,
55 + # defaulting to None if attributes don't exist or are empty strings
56 + reasoning_content = (
57 + getattr(chunk.choices[0].delta, "reasoning_content", None) or None
58 + )
59 + content = getattr(chunk.choices[0].delta, "content", None) or None
60
61 if reasoning_content is not None:
62 if not printed_reasoning_content: