83 lines
1.7 KiB
Markdown
83 lines
1.7 KiB
Markdown
# 后端项目配置说明
|
||
|
||
## API密钥配置
|
||
|
||
### 1. 配置方式
|
||
|
||
本项目支持两种方式配置DeepSeek API密钥:
|
||
|
||
#### 方式一:环境变量文件 (.env)
|
||
在 `backend/.env` 文件中设置:
|
||
```env
|
||
DEEPSEEK_API_KEY=your-actual-deepseek-api-key
|
||
```
|
||
|
||
#### 方式二:系统环境变量
|
||
直接在系统环境中设置:
|
||
```bash
|
||
export DEEPSEEK_API_KEY=your-actual-deepseek-api-key
|
||
```
|
||
|
||
### 2. 获取DeepSeek API密钥
|
||
|
||
1. 访问 [DeepSeek官网](https://platform.deepseek.com/)
|
||
2. 注册并登录账户
|
||
3. 进入API密钥管理页面
|
||
4. 创建新的API密钥
|
||
5. 将生成的密钥配置到项目中
|
||
|
||
### 3. 配置验证
|
||
|
||
运行以下命令验证配置是否正确:
|
||
```bash
|
||
cd backend
|
||
python -c "from config import is_api_key_configured; print(f'API密钥已配置: {is_api_key_configured()}')"
|
||
```
|
||
|
||
如果输出 `API密钥已配置: True` 表示配置成功。
|
||
|
||
### 4. 其他配置项
|
||
|
||
#### 服务器配置
|
||
```env
|
||
HOST=0.0.0.0
|
||
PORT=8000
|
||
```
|
||
|
||
#### 调试模式
|
||
```env
|
||
DEBUG=false
|
||
```
|
||
|
||
#### CORS配置
|
||
在 `config.py` 中修改 `cors_origins` 列表来添加允许的前端域名。
|
||
|
||
### 5. 安全注意事项
|
||
|
||
- 不要将真实的API密钥提交到版本控制系统
|
||
- 确保 `.env` 文件在 `.gitignore` 中
|
||
- 生产环境中建议使用系统环境变量而非文件配置
|
||
- 定期轮换API密钥
|
||
|
||
### 6. 故障排除
|
||
|
||
如果API密钥未正确配置:
|
||
1. 检查 `.env` 文件路径是否正确
|
||
2. 确认环境变量名称拼写正确
|
||
3. 重启应用使配置生效
|
||
4. 检查API密钥是否有效
|
||
|
||
### 7. 示例配置
|
||
|
||
完整的 `.env` 文件示例:
|
||
```env
|
||
# DeepSeek API配置
|
||
DEEPSEEK_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||
|
||
# 服务器配置
|
||
HOST=0.0.0.0
|
||
PORT=8000
|
||
|
||
# 其他配置
|
||
DEBUG=false
|