返回 VideoClaw
init_backend.md
根目录 / video-claw / references / init_project / init_backend.md
1 # 初始化后端
2
3 配置并启动 FastAPI 后端服务。
4
5 ## 步骤1:进入后端目录
6
7 ```bash
8 cd video-claw/backend
9 ```
10
11 ## 步骤2:创建虚拟环境(首次)
12
13 ```bash
14 # 创建虚拟环境
15 python3 -m venv venv
16
17 # 激活虚拟环境
18 source venv/bin/activate
19 ```
20
21 ## 步骤3:安装依赖
22
23 ```bash
24 # 激活虚拟环境后执行
25 pip install -r requirements.txt
26 ```
27
28 > **注意**:如果安装慢,可使用国内镜像:
29 > ```bash
30 > pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
31 > ```
32
33 ## 步骤4:配置后端 YAML
34
35 ```bash
36 # 复制配置示例文件
37 cp config.yaml.example config.yaml
38 ```
39
40 然后编辑 `config.yaml` 文件,或启动前端后通过侧边栏底部「设置」页面填写必要配置:
41
42 | 字段 | 说明 | 获取方式 |
43 |------|------|----------|
44 | `models.llm` | 默认 LLM 模型名 | 按后端模型注册表选择 |
45 | `api_providers.dashscope.api_key` | 阿里云 DashScope API Key | [阿里云百炼](https://dashscope.console.aliyun.com/) |
46 | `api_providers.ark.api_key` | 火山方舟 API Key | [火山方舟](https://www.volcengine.com/product/ark) |
47 | `api_providers.openai.api_key` | OpenAI 兼容 API Key | 根据实际部署情况 |
48 | `api_providers.deepseek.api_key` | DeepSeek API Key | [DeepSeek](https://platform.deepseek.com/) |
49 | `api_providers.kling.access_key` / `api_providers.kling.secret_key` | Kling 视频模型鉴权 | [Kling 开放平台](https://klingai.com/cn/dev) |
50 | `models.*` | 默认 LLM、图片、视频、评估模型 | 按后端模型注册表选择 |
51 | `server.host` / `server.port` / `server.debug` | 后端服务地址、端口和调试开关 | 本地部署配置 |
52 | `api_providers.common.proxy` / `api_providers.<provider>.enable_proxy` | 统一代理地址,以及每个模型提供商是否启用代理 | 默认不启用代理 |
53
54 > ⚠️ **重要**:至少需要配置一个 LLM 和一个图片/视频生成 API,否则无法正常使用。
55
56 ## 步骤5:启动后端
57
58 ```bash
59 source venv/bin/activate
60 python api_server.py
61 ```
62
63 ## 步骤6:验证
64
65 ```bash
66 curl http://localhost:8000/api/health
67 ```
68
69 返回 `{"status":"ok"}` 表示成功。
70
71 ## 常见问题
72
73 | 错误 | 原因 | 解决方法 |
74 |------|------|----------|
75 | `python: command not found` | Python 未安装 | 安装 Python 3.9+ |
76 | `No module named venv` | python3-venv 未安装 | `brew install python3-venv` (macOS) |
77 | `ModuleNotFoundError` | 依赖未安装 | `pip install -r requirements.txt` |
78 | 模型 API Key 缺失 | `config.yaml` 未配置 | 编辑 `config.yaml` 或在前端「设置」页面填入 API Key |
79 | `Address already in use` | 端口 8000 被占用 | `lsof -ti :8000 | xargs kill` |
80
80 lines MARKDOWN