mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-10 04:15:01 +08:00
[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>
This commit is contained in:
parent
5bbaf492a6
commit
5c8fe389d6
@ -123,13 +123,12 @@ OpenAI Python client library does not officially support `reasoning_content` att
|
||||
printed_content = False
|
||||
|
||||
for chunk in stream:
|
||||
reasoning_content = None
|
||||
content = None
|
||||
# Check the content is reasoning_content or content
|
||||
if hasattr(chunk.choices[0].delta, "reasoning_content"):
|
||||
reasoning_content = chunk.choices[0].delta.reasoning_content
|
||||
elif hasattr(chunk.choices[0].delta, "content"):
|
||||
content = chunk.choices[0].delta.content
|
||||
# Safely extract reasoning_content and content from delta,
|
||||
# defaulting to None if attributes don't exist or are empty strings
|
||||
reasoning_content = (
|
||||
getattr(chunk.choices[0].delta, "reasoning_content", None) or None
|
||||
)
|
||||
content = getattr(chunk.choices[0].delta, "content", None) or None
|
||||
|
||||
if reasoning_content is not None:
|
||||
if not printed_reasoning_content:
|
||||
|
||||
@ -51,13 +51,12 @@ def main():
|
||||
printed_content = False
|
||||
|
||||
for chunk in stream:
|
||||
reasoning_content = None
|
||||
content = None
|
||||
# Check the content is reasoning_content or content
|
||||
if hasattr(chunk.choices[0].delta, "reasoning_content"):
|
||||
reasoning_content = chunk.choices[0].delta.reasoning_content
|
||||
elif hasattr(chunk.choices[0].delta, "content"):
|
||||
content = chunk.choices[0].delta.content
|
||||
# Safely extract reasoning_content and content from delta,
|
||||
# defaulting to None if attributes don't exist or are empty strings
|
||||
reasoning_content = (
|
||||
getattr(chunk.choices[0].delta, "reasoning_content", None) or None
|
||||
)
|
||||
content = getattr(chunk.choices[0].delta, "content", None) or None
|
||||
|
||||
if reasoning_content is not None:
|
||||
if not printed_reasoning_content:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user