Skip to content

Commit 2831150

Browse files
committed
Support of reasoning
1 parent 4095c2e commit 2831150

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

docs/Usage.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ curl $OPENAI_BASE_URL/chat/completions \
378378

379379
You can also use OpenAI SDK (run `pip3 install -U openai` first )
380380

381+
- Non-Streaming
382+
381383
```python
382384
from openai import OpenAI
383385
client = OpenAI()
@@ -392,4 +394,29 @@ response = client.chat.completions.create(
392394

393395
reasoning_content = response.choices[0].message.reasoning_content
394396
content = 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
```

docs/Usage_CN.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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
381383
from openai import OpenAI
382384
client = OpenAI()
@@ -391,4 +393,29 @@ response = client.chat.completions.create(
391393

392394
reasoning_content = response.choices[0].message.reasoning_content
393395
content = 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
```

0 commit comments

Comments
 (0)