from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.jiekou.ai/openai")
messages = [
{"role": "user", "content": "解释一下牛顿第二定律。"}
]
response = client.chat.completions.create(
model="deepseek/deepseek-r1",
messages=messages,
stream=True,
max_tokens=4096
)
content = ""
reasoning_content = ""
for chunk in response:
if chunk.choices[0].delta.content:
content += chunk.choices[0].delta.content
if chunk.choices[0].delta.reasoning_content:
reasoning_content += chunk.choices[0].delta.reasoning_content
print("最终回答:", content)
print("推理过程:", reasoning_content)