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

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