Unverified Commit 5c8fe389 authored by Hongsheng Liu's avatar Hongsheng Liu Committed by GitHub
Browse files

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


Signed-off-by: default avatarwangzi <3220100013@zju.edu.cn>
Co-authored-by: default avatarwangzi <3220100013@zju.edu.cn>
Co-authored-by: default avatarZi Wang <66560864+BruceW-07@users.noreply.github.com>
parent 5bbaf492
...@@ -123,13 +123,12 @@ OpenAI Python client library does not officially support `reasoning_content` att ...@@ -123,13 +123,12 @@ OpenAI Python client library does not officially support `reasoning_content` att
printed_content = False printed_content = False
for chunk in stream: for chunk in stream:
reasoning_content = None # Safely extract reasoning_content and content from delta,
content = None # defaulting to None if attributes don't exist or are empty strings
# Check the content is reasoning_content or content reasoning_content = (
if hasattr(chunk.choices[0].delta, "reasoning_content"): getattr(chunk.choices[0].delta, "reasoning_content", None) or None
reasoning_content = chunk.choices[0].delta.reasoning_content )
elif hasattr(chunk.choices[0].delta, "content"): content = getattr(chunk.choices[0].delta, "content", None) or None
content = chunk.choices[0].delta.content
if reasoning_content is not None: if reasoning_content is not None:
if not printed_reasoning_content: if not printed_reasoning_content:
......
...@@ -51,13 +51,12 @@ def main(): ...@@ -51,13 +51,12 @@ def main():
printed_content = False printed_content = False
for chunk in stream: for chunk in stream:
reasoning_content = None # Safely extract reasoning_content and content from delta,
content = None # defaulting to None if attributes don't exist or are empty strings
# Check the content is reasoning_content or content reasoning_content = (
if hasattr(chunk.choices[0].delta, "reasoning_content"): getattr(chunk.choices[0].delta, "reasoning_content", None) or None
reasoning_content = chunk.choices[0].delta.reasoning_content )
elif hasattr(chunk.choices[0].delta, "content"): content = getattr(chunk.choices[0].delta, "content", None) or None
content = chunk.choices[0].delta.content
if reasoning_content is not None: if reasoning_content is not None:
if not printed_reasoning_content: if not printed_reasoning_content:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment