Skip to content

Commit cb3aafe

Browse files
author
BitsAdmin
committed
Merge branch 'feat/support_reasoning' into 'integration_2025-02-06_695254313218'
feat: [development task] ark-runtime-manual-Python (999432) See merge request iaasng/volcengine-python-sdk!503
2 parents 240d768 + d5560f1 commit cb3aafe

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

volcenginesdkarkruntime/types/chat/chat_completion_chunk.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class ChoiceDelta(BaseModel):
7070

7171
tool_calls: Optional[List[ChoiceDeltaToolCall]] = None
7272

73+
reasoning_content: Optional[str] = None
74+
"""The reasoning content of the message."""
75+
7376

7477
class ChoiceLogprobs(BaseModel):
7578
content: Optional[List[ChatCompletionTokenLogprob]] = None

volcenginesdkarkruntime/types/chat/chat_completion_message.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ class ChatCompletionMessage(BaseModel):
4040

4141
audio: Optional[ChatCompletionAudio] = None
4242
"""Audio response from the model."""
43+
44+
reasoning_content: Optional[str] = None
45+
"""The reasoning content of the message."""

volcenginesdkarkruntime/types/completion_usage.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ class PromptTokensDetails(BaseModel):
1111
"""Number of tokens hit cache."""
1212

1313

14+
class CompletionTokensDetails(BaseModel):
15+
reasoning_tokens: Optional[int] = None
16+
"""Tokens generated by the model for reasoning."""
17+
18+
1419
class CompletionUsage(BaseModel):
1520
completion_tokens: int
1621
"""Number of tokens in the generated completion."""
@@ -23,3 +28,6 @@ class CompletionUsage(BaseModel):
2328

2429
prompt_tokens_details: Optional[PromptTokensDetails] = None
2530
"""Prompt tokens details."""
31+
32+
completion_tokens_details: Optional[CompletionTokensDetails] = None
33+
"""Breakdown of tokens used in a completion."""
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from volcenginesdkarkruntime import Ark
2+
3+
# Authentication
4+
# 1.If you authorize your endpoint using an API key, you can set your api key to environment variable "ARK_API_KEY"
5+
# or specify api key by Ark(api_key="${YOUR_API_KEY}").
6+
# Note: If you use an API key, this API key will not be refreshed.
7+
# To prevent the API from expiring and failing after some time, choose an API key with no expiration date.
8+
9+
# 2.If you authorize your endpoint with Volcengine Identity and Access Management(IAM),
10+
# set your api key to environment variable "VOLC_ACCESSKEY", "VOLC_SECRETKEY"
11+
# or specify ak&sk by Ark(ak="${YOUR_AK}", sk="${YOUR_SK}").
12+
# To get your ak&sk, please refer to this document(https://www.volcengine.com/docs/6291/65568)
13+
# For more information,please check this document(https://www.volcengine.com/docs/82379/1263279)
14+
client = Ark()
15+
16+
if __name__ == "__main__":
17+
# Non-streaming:
18+
print("----- standard request -----")
19+
completion = client.chat.completions.create(
20+
model="${YOUR_ENDPOINT_ID}",
21+
messages=[
22+
{"role": "user", "content": "How many Rs are there in the word 'strawberry'?"},
23+
],
24+
)
25+
print(completion.choices[0].message.reasoning_content)
26+
print(completion.choices[0].message.content)
27+
28+
# Streaming:
29+
print("----- streaming request -----")
30+
stream = client.chat.completions.create(
31+
model="${YOUR_ENDPOINT_ID}",
32+
messages=[
33+
{"role": "user", "content": "How many Rs are there in the word 'strawberry'?"},
34+
],
35+
stream=True
36+
)
37+
for chunk in stream:
38+
if not chunk.choices:
39+
continue
40+
if chunk.choices[0].delta.reasoning_content:
41+
print(chunk.choices[0].delta.reasoning_content, end="")
42+
else:
43+
print(chunk.choices[0].delta.content, end="")
44+
print()

0 commit comments

Comments
 (0)