Files
chat/backend/README.md
2025-08-22 14:22:43 +08:00

32 lines
877 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 后端服务
Node.js + Express + TypeScript + Mongoose + OpenAI 示例。
## 环境变量
复制 `.env.example``.env` 并填写:
```
PORT=3000
MONGODB_URI=mongodb://localhost:27017/multi_llm_chat
OPENAI_API_KEY=sk-...
# 可选 OpenAI base (代理): OPENAI_BASE_URL=https://api.openai.com
DEEPSEEK_API_KEY=sk-deepseek...
DEEPSEEK_BASE_URL=https://api.deepseek.com
```
## 运行
```bash
npm install
npm run dev
```
## 接口
- POST /api/chat { modelId, messages } => { text }
- POST /api/chat/stream (SSE) data: <chunk> 直到 data: [DONE]
- POST /api/conversations 保存对话
- GET /api/conversations/:id 读取对话
- GET /api/health 健康检查
## 说明
已接入 OpenAI 与 DeepSeekDeepSeek 通过 model 名包含 "deepseek" 自动匹配,使用 OpenAI 协议 /v1/chat/completions。可继续在 `llmService.ts` 中扩展更多 provider 逻辑。