【AI基础专题】简单对话
在这一节中,我们将创建一个简单的对话示例,演示如何使用 DeepSeek API 与模型进行交互。
本节内容全部都在src/index.ts中实现,现在给这次行动简单分一下步骤:
- 引入依赖
1 | import OpenAI from 'openai'; |
- 初始化客户端
1 | const client = new OpenAI({ |
- 发送对话请求
1 | const response = await client.chat.completions.create({ |
- 获取模型回复
1 | const reply = response.choices[0]?.message?.content; |
实际运行结果如下:
