|
|
发表于 2025-7-27 18:21:32
|
显示全部楼层
- stream = client.chat.completions.create(
- model="deepseek-ai/DeepSeek-R1",
- messages=messages,
- stream=True
- )
- thinking_content = ""
- final_response = ""
- for chunk in stream:
- if chunk.choices:
- # 如果需要显示思考过程,可根据 delta 内容判断
- if hasattr(chunk.choices[0].delta, 'reasoning_content'):
- reasoning = chunk.choices[0].delta.reasoning_content or ""
- thinking_content += reasoning
- yield thinking_content, final_response
- if hasattr(chunk.choices[0].delta, 'content'):
- content = chunk.choices[0].delta.content or ""
- final_response += content
- yield thinking_content, final_response
- yield thinking_content, final_response
- messages.append({"role": "assistant", "content": final_response})
复制代码
- # 启动Gradio应用
- demo.queue().launch(inbrowser=True)
复制代码 |
|