File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -378,6 +378,8 @@ curl $OPENAI_BASE_URL/chat/completions \
378378
379379You can also use OpenAI SDK (run ` pip3 install -U openai ` first )
380380
381+ - Non-Streaming
382+
381383``` python
382384from openai import OpenAI
383385client = OpenAI()
@@ -392,4 +394,29 @@ response = client.chat.completions.create(
392394
393395reasoning_content = response.choices[0 ].message.reasoning_content
394396content = response.choices[0 ].message.content
397+ ```
398+
399+ - Streaming
400+
401+ ``` python
402+ from openai import OpenAI
403+ client = OpenAI()
404+
405+ messages = [{" role" : " user" , " content" : " 9.11 and 9.8, which is greater?" }]
406+ response = client.chat.completions.create(
407+ model = " us.anthropic.claude-3-7-sonnet-20250219-v1:0" ,
408+ messages = messages,
409+ reasoning_effort = " low" ,
410+ max_completion_tokens = 4096 ,
411+ stream = True ,
412+ )
413+
414+ reasoning_content = " "
415+ content = " "
416+
417+ for chunk in response:
418+ if hasattr (chunk.choices[0 ].delta, ' reasoning_content' ) and chunk.choices[0 ].delta.reasoning_content:
419+ reasoning_content += chunk.choices[0 ].delta.reasoning_content
420+ elif hasattr (chunk.choices[0 ].delta, ' content' ) and chunk.choices[0 ].delta.content:
421+ content += chunk.choices[0 ].delta.content
395422```
Original file line number Diff line number Diff line change @@ -377,6 +377,8 @@ curl $OPENAI_BASE_URL/chat/completions \
377377
378378或者使用 OpenAI SDK (请先运行` pip3 install -U openai ` 升级到最新版本)
379379
380+ - Non-Streaming
381+
380382``` python
381383from openai import OpenAI
382384client = OpenAI()
@@ -391,4 +393,29 @@ response = client.chat.completions.create(
391393
392394reasoning_content = response.choices[0 ].message.reasoning_content
393395content = response.choices[0 ].message.content
396+ ```
397+
398+ - Streaming
399+
400+ ``` python
401+ from openai import OpenAI
402+ client = OpenAI()
403+
404+ messages = [{" role" : " user" , " content" : " 9.11 and 9.8, which is greater?" }]
405+ response = client.chat.completions.create(
406+ model = " us.anthropic.claude-3-7-sonnet-20250219-v1:0" ,
407+ messages = messages,
408+ reasoning_effort = " low" ,
409+ max_completion_tokens = 4096 ,
410+ stream = True ,
411+ )
412+
413+ reasoning_content = " "
414+ content = " "
415+
416+ for chunk in response:
417+ if hasattr (chunk.choices[0 ].delta, ' reasoning_content' ) and chunk.choices[0 ].delta.reasoning_content:
418+ reasoning_content += chunk.choices[0 ].delta.reasoning_content
419+ elif hasattr (chunk.choices[0 ].delta, ' content' ) and chunk.choices[0 ].delta.content:
420+ content += chunk.choices[0 ].delta.content
394421```
You can’t perform that action at this time.
0 commit comments