You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
# 安装 OpenAI SDK:
|
|
|
|
|
# pip install openai
|
|
|
|
|
from openai import OpenAI
|
|
|
|
|
from Config import Config
|
|
|
|
|
|
|
|
|
|
# 创建 API 客户端
|
|
|
|
|
client = OpenAI(api_key=Config.DEEPSEEK_API_KEY, base_url=Config.DEEPSEEK_URL)
|
|
|
|
|
|
|
|
|
|
# 调用 deepseek-chat 模型(流式模式)
|
|
|
|
|
response = client.chat.completions.create(
|
|
|
|
|
model="deepseek-chat",
|
|
|
|
|
messages=[
|
|
|
|
|
{"role": "system", "content": "You are a helpful assistant."},
|
|
|
|
|
{"role": "user", "content": "什么是CNN神经网络?"},
|
|
|
|
|
],
|
|
|
|
|
stream=True # 启用流式输出
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 流式输出响应内容
|
|
|
|
|
for chunk in response:
|
|
|
|
|
if chunk.choices[0].delta.content:
|
|
|
|
|
print(chunk.choices[0].delta.content, end="", flush=True)
|
|
|
|
|
print(response.choices[0].message.content)
|