Files
ai-ticket-platform/docs/development/local-setup.md
2026-07-16 19:37:42 +08:00

116 lines
3.4 KiB
Markdown
Raw 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.
# Local Setup
## Prerequisites
- Python 3.12
- Node.js 22
- Docker Desktop
## First Run
```powershell
Copy-Item .env.example .env
python -c "import base64,secrets; print(base64.urlsafe_b64encode(secrets.token_bytes(32)).decode())"
```
将输出写入 `.env` 的 `AI_CREDENTIAL_ENCRYPTION_KEY`。该值缺失时,系统会拒绝保存模型渠道凭证;已经保存凭证后不要随意更换主密钥。
完整应用(PostgreSQL、Redis、MinIO、Django、Celery worker、Celery Beat、React):
```powershell
cd infra
docker compose --env-file ../.env up --build
```
只启动本地基础设施、在宿主机运行前后端时:
```powershell
cd infra
docker compose -f docker-compose.local.yml --env-file ../.env up -d
```
首次启动时,backend 容器会自动等待 PostgreSQL、执行数据库迁移,并初始化企业后台治理数据。
Backend:
- API: http://localhost:8000/api/docs
- Health: http://localhost:8000/api/system/health
Frontend:
- App: http://localhost:5173
- 局域网访问: `http://<宿主机局域网 IP>:5173`
前端默认通过同源 `/api` 代理后端:宿主机直接运行 Vite 时代理到
`http://localhost:8000`,Docker Compose 中通过 `API_PROXY_TARGET` 代理到
`http://backend:8000`。因此局域网访问时无需把浏览器 API 地址配置为
`localhost:8000`。
默认管理员:
- 账号: `admin`
- 密码: `admin12345`
- 可通过 `.env` 中的 `DJANGO_SUPERUSER_USERNAME`、`DJANGO_SUPERUSER_PASSWORD`、`DJANGO_SUPERUSER_EMAIL` 修改。
## Backend Tests
```bash
cd backend
python -m pip install -e ".[dev]"
pytest -v
```
## Frontend Checks
```bash
cd frontend
npm install
npm run test:run
npm run lint
npm run typecheck
npm run build
```
## AI Platform Demo
1. 使用管理员账号打开 `#/modelhub/providers`,创建 OpenAI-compatible 渠道和文本模型,并执行异步连通测试。
2. 取得模型配置 ID 后创建预置草稿:
```powershell
cd backend
python manage.py seed_ai_demo --deployment-id 1
```
3. 在 `#/skills` 检查、编辑并发布三个 Skill。
4. 在 `#/agents` 编辑技术支持分析 Agent 的模型、步骤和输入映射,先运行草稿沙箱,再发布并运行正式版本。
5. 在 `#/agent-runs` 查看执行脊柱、每步输入输出、调用尝试、Token、耗时和配置快照。
完整验收步骤见 [AI 平台配置演示版验收](ai-platform-demo-acceptance.md)。
## Trusted Ticket Intake
1. 在模型中心配置并启用一个文本模型。
2. 发布预置建单 Skill 与单步 Agent:
```powershell
cd backend
python manage.py seed_ticket_intake --deployment-id 1
```
3. 打开 `#/tickets/create`,输入自然语言描述,审核结构化字段并明确确认。
4. 可运行固定真实文本验收脚本;脚本会保留草稿、AgentRun、产物、审计和一张验收工单:
```powershell
python manage.py verify_ticket_intake --username admin
```
宿主机直接运行时要确保已加载根目录 `.env` 中的凭证主密钥,并把容器服务主机名覆盖为本机地址。缺少主密钥时脚本会安全失败,不会读取或替换渠道凭证。
图片代码要求 MinIO 可用;只有 `vision_chat` 模型且渠道已由管理员授权图片出境时才允许分析图片。当前真实视觉渠道验收仍待完成。
## Stage 1 API Smoke Tests
- Tickets: `GET http://localhost:8000/api/tickets`
- Ticket export: `GET http://localhost:8000/api/tickets/export`
- Solutions: `GET http://localhost:8000/api/solutions`