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.

24 lines
739 B

1 month ago
# 安装 OpenAI SDK
# pip install openai
from openai import OpenAI
1 month ago
from Config import Config
1 month ago
# 创建 API 客户端
1 month ago
client = OpenAI(api_key=Config.DEEPSEEK_API_KEY, base_url=Config.DEEPSEEK_URL)
1 month ago
1 month ago
# 调用 deepseek-chat 模型(流式模式)
1 month ago
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "什么是CNN神经网络?"},
],
1 month ago
stream=True # 启用流式输出
1 month ago
)
1 month ago
# 流式输出响应内容
for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
1 month ago
print(response.choices[0].message.content)