Files
AI-VideoAssistant/api
2026-02-06 14:01:34 +08:00
..
2026-02-06 14:01:34 +08:00
2026-02-06 14:01:34 +08:00
2026-02-06 14:01:34 +08:00
2026-02-06 14:01:34 +08:00
2026-02-06 14:01:34 +08:00
2026-02-06 14:01:34 +08:00
2026-02-06 14:01:34 +08:00

AI VideoAssistant Backend

Python 后端 API配合前端 ai-videoassistant-frontend 使用。

快速开始

1. 安装依赖

cd ~/Code/ai-videoassistant-backend
pip install -r requirements.txt

2. 初始化数据库

python init_db.py

这会:

  • 创建 data/app.db SQLite 数据库
  • 初始化默认声音数据

3. 启动服务

# 开发模式 (热重载)
python -m uvicorn main:app --reload --host 0.0.0.0 --port 8000

4. 测试 API

# 健康检查
curl http://localhost:8000/health

# 获取助手列表
curl http://localhost:8000/api/assistants

# 获取声音列表
curl http://localhost:8000/api/voices

# 获取通话历史
curl http://localhost:8000/api/history

API 文档

端点 方法 说明
/api/assistants GET 助手列表
/api/assistants POST 创建助手
/api/assistants/{id} GET 助手详情
/api/assistants/{id} PUT 更新助手
/api/assistants/{id} DELETE 删除助手
/api/voices GET 声音库列表
/api/history GET 通话历史列表
/api/history/{id} GET 通话详情
/api/history/{id}/transcripts POST 添加转写
/api/history/{id}/audio/{turn} GET 获取音频

使用 Docker 启动

cd ~/Code/ai-videoassistant-backend

# 启动所有服务
docker-compose up -d

# 查看日志
docker-compose logs -f backend

目录结构

backend/
├── app/
│   ├── __init__.py
│   ├── main.py           # FastAPI 入口
│   ├── db.py             # SQLite 连接
│   ├── models.py         # 数据模型
│   ├── schemas.py        # Pydantic 模型
│   ├── storage.py        # MinIO 存储
│   └── routers/
│       ├── __init__.py
│       ├── assistants.py # 助手 API
│       └── history.py    # 通话记录 API
├── data/                 # 数据库文件
├── requirements.txt
├── .env
└── docker-compose.yml

环境变量

变量 默认值 说明
DATABASE_URL sqlite:///./data/app.db 数据库连接
MINIO_ENDPOINT localhost:9000 MinIO 地址
MINIO_ACCESS_KEY admin MinIO 密钥
MINIO_SECRET_KEY password123 MinIO 密码
MINIO_BUCKET ai-audio 存储桶名称