使用的模型是:deepseek-r1-250120
请求示例如下
获取响应结果代码如下
None之前的最后一个数据流Usage里依然是None
这个看起来是代码有一点问题,因为方舟的usage其实和openai对齐,是在finish_reason
后一个chunk的。但看起来截图里最后一个chunk只停留到了finish_reason
这一个chunk(还未到usage输出的chunk)。 要不尝试改成:
python from openai import OpenAI client = OpenAI(base_url="<https://ark.cn-beijing.volces.com/api/v3>") messages = [{"role": "user", "content": "9.11 and 9.8, which is greater?"}] response = client.chat.completions.create( model="${YOUR ENDPOINT ID}", messages=messages, stream=True, stream_options={ "include_usage": True, } ) reasoning_content = "" content = "" for chunk in response: if len(chunk.choices) > 0: if hasattr(chunk.choices[0].delta, 'reasoning_content') and chunk.choices[0].delta.reasoning_content: reasoning_content += chunk.choices[0].delta.reasoning_content print(chunk.choices[0].delta.reasoning_content, end="") else: content += chunk.choices[0].delta.content print(chunk.choices[0].delta.content, end="") else: print("\n") print(chunk.usage) # Round 2 messages.append({"role": "assistant", "content": content}) messages.append({'role': 'user', 'content': "How many Rs are there in the word 'strawberry'?"}) response = client.chat.completions.create( model="deepseek-reasoner", messages=messages, stream=True ) # ...