feat: 增加 YAML 配置与一键启动脚本

This commit is contained in:
caoxiaozhu
2026-07-21 16:15:01 +08:00
parent a5fbe5130a
commit 7c38e37b23
15 changed files with 954 additions and 71 deletions

View File

@@ -48,12 +48,36 @@ YG_FT/
- 前端新增 `/compute` 算力节点页面展示节点地址、权重、标签、启用状态、GPU、队列和资源副本。
- `compute/engines/llama_factory/adapter.py` 提供 LLaMA-Factory 参数校验、命令生成和日志解析基础能力。
## 一键启动前端和后端
```bash
./scripts/start-dev.sh --setup # 首次运行,初始化本地依赖
./scripts/start-dev.sh # 后续直接启动
./scripts/start-dev.sh --check # 仅检查依赖和 PostgreSQL 连接
```
首次运行前可将 `backend/config.example.yaml` 复制为 `backend/config.yaml` 并填写
本地数据库凭据;`config.yaml` 已加入 Git 忽略。脚本会检查 PostgreSQL 和两个服务
的健康状态,并在退出时同时停止前端和后端。也可以按下面步骤分别启动服务。
一键启动使用的前后端端口也统一配置在同一个 YAML 中:
```yaml
server:
frontend_port: 16801
backend_port: 17861
```
端口被占用时修改这两项后重新启动即可。未显式配置 `cors_allow_origins` 时,后端会
根据 `frontend_port` 自动允许本机前端来源。环境变量 `FRONTEND_PORT`
`BACKEND_PORT` 可以临时覆盖 YAML。
## 后端启动
```bash
cd backend
python -m venv .venv
.venv\Scripts\activate
/opt/miniconda3/bin/python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 17861
```
@@ -69,13 +93,22 @@ GET /modelTF/fine-tune
GET /modelTF/compute/nodes
```
本地运行时默认 PostgreSQL 连接
本地运行时默认通过 `backend/config.yaml` 连接 PostgreSQL
```text
DATABASE_URL=postgresql+psycopg://yg_ft:change_me@localhost:15432/yg_ft
```yaml
server:
frontend_port: 16801
backend_port: 17861
database:
url: postgresql+psycopg://localhost:5432/yg_ft
username: yg_ft
password: "change_me"
```
本地启动前需要确保 PostgreSQL 已监听 `localhost:15432`并已创建 `yg_ft` 数据库和 `yg_ft` 用户。后端启动后会自动创建当前运行表并写入内置管理员账号,运行数据统一写入 PostgreSQL。
本地启动前需要确保 PostgreSQL 已监听 YAML 配置的地址(默认 `localhost:5432`
并已创建 `yg_ft` 数据库和 `yg_ft` 用户。后端启动后会自动创建当前运行表并写入
内置管理员账号,运行数据统一写入 PostgreSQL。
开发阶段内置登录账号:
@@ -94,7 +127,9 @@ npm install
npm run dev
```
前端开发服务默认运行在 `http://localhost:16801`,并通过 Vite proxy 将 `/modelTF` 转发到 `http://localhost:17861`
通过一键脚本启动时,前端端口和 Vite proxy 的后端端口均来自
`backend/config.yaml`。单独运行 `npm run dev` 时,默认使用前端 `16801`、后端
`17861`,也可以通过 `FRONTEND_PORT``BACKEND_PORT` 覆盖。
## 算力服务启动