基于 Go + Vue3 的全栈 AI 短剧自动化生产平台
Huobao Drama 是一个基于 AI 的短剧自动化生产平台,实现从剧本生成、角色设计、分镜制作到视频合成的全流程自动化。
采用DDD 领域驱动设计,清晰分层:
├── API层 (Gin HTTP)
├── 应用服务层 (Business Logic)
├── 领域层 (Domain Models)
└── 基础设施层 (Database, External Services)
体验 AI 短剧生成效果:
示例作品 1
示例作品 2
| 软件 | 版本要求 | 说明 |
|---|---|---|
| Go | 1.23+ | 后端运行环境 |
| Node.js | 18+ | 前端构建环境 |
| npm | 9+ | 包管理工具 |
| FFmpeg | 4.0+ | 视频处理(必需) |
| SQLite | 3.x | 数据库(已内置) |
macOS:
brew install ffmpeg
Ubuntu/Debian:
sudo apt update
sudo apt install ffmpeg
Windows: 从 FFmpeg 官网 下载并配置环境变量
验证安装:
ffmpeg -version
复制并编辑配置文件:
cp configs/config.example.yaml configs/config.yaml
vim configs/config.yaml
配置文件格式(configs/config.yaml):
app:
name: "Huobao Drama API"
version: "1.0.0"
debug: true # 开发环境设为true,生产环境设为false
server:
port: 5678
host: "0.0.0.0"
cors_origins:
- "http://localhost:3012"
read_timeout: 600
write_timeout: 600
database:
type: "sqlite"
path: "./data/drama_generator.db"
max_idle: 10
max_open: 100
storage:
type: "local"
local_path: "./data/storage"
base_url: "http://localhost:5678/static"
ai:
default_text_provider: "openai"
default_image_provider: "openai"
default_video_provider: "doubao"
重要配置项:
app.debug: 调试模式开关(开发环境建议设为 true)server.port: 服务运行端口server.cors_origins: 允许跨域访问的前端地址database.path: SQLite 数据库文件路径storage.local_path: 本地文件存储路径storage.base_url: 静态资源访问 URLai.default_*_provider: AI 服务提供商配置(在 Web 界面中配置具体的 API Key)# 克隆项目
git clone https://github.com/chatfire-AI/huobao-drama.git
cd huobao-drama
# 安装Go依赖
go mod download
# 安装前端依赖
cd web
npm install
cd ..
前后端分离,支持热重载
# 终端1:启动后端服务
go run main.go
# 终端2:启动前端开发服务器
cd web
npm run dev
http://localhost:3012http://localhost:5678/api/v1后端同时提供 API 和前端静态文件
# 1. 构建前端
cd web
npm run build
cd ..
# 2. 启动服务
go run main.go
访问: http://localhost:5678
数据库表会在首次启动时自动创建(使用 GORM AutoMigrate),无需手动迁移。
如果您在国内网络环境下,Docker 拉取镜像和安装依赖可能较慢。可以通过配置镜像源加速构建过程。
步骤 1:创建环境变量文件
cp .env.example .env
步骤 2:编辑 .env 文件,取消注释需要的镜像源
# 启用 Docker Hub 镜像(推荐)
DOCKER_REGISTRY=docker.1ms.run/
# 启用 npm 镜像
NPM_REGISTRY=https://registry.npmmirror.com/
# 启用 Go 代理
GO_PROXY=https://goproxy.cn,direct
# 启用 Alpine 镜像
ALPINE_MIRROR=mirrors.aliyun.com
步骤 3:使用 docker compose 构建(必须)
docker compose build
重要说明:
- ⚠️ 必须使用
docker compose build才能自动加载.env文件中的镜像源配置- ❌ 如果使用
docker build命令,需要手动传递--build-arg参数- ✅ 推荐始终使用
docker compose build进行构建
效果对比:
| 操作 | 不配置镜像源 | 配置镜像源后 |
|---|---|---|
| 拉取基础镜像 | 5-30 分钟 | 1-5 分钟 |
| 安装 npm 依赖 | 可能失败 | 快速成功 |
| 下载 Go 依赖 | 5-10 分钟 | 30 秒-1 分钟 |
注意:国外用户请勿配置镜像源,使用默认配置即可。
# 启动服务
docker-compose up -d
# 查看日志
docker-compose logs -f
# 停止服务
docker-compose down
注意:Linux 用户需添加
--add-host=host.docker.internal:host-gateway以访问宿主机服务
# 从 Docker Hub 运行
docker run -d \
--name huobao-drama \
-p 5678:5678 \
-v $(pwd)/data:/app/data \
--restart unless-stopped \
huobao/huobao-drama:latest
# 查看日志
docker logs -f huobao-drama
本地构建(可选):
docker build -t huobao-drama:latest .
docker run -d --name huobao-drama -p 5678:5678 -v $(pwd)/data:/app/data huobao-drama:latest
Docker 部署优势:
容器已配置支持访问宿主机服务,直接使用 http://host.docker.internal:端口号 即可。
配置步骤:
bash
export OLLAMA_HOST=0.0.0.0:11434 && ollama serve
http://host.docker.internal:11434/v1openaiqwen2.5:latest# 1. 构建前端
cd web
npm run build
cd ..
# 2. 编译后端
go build -o huobao-drama .
生成文件:
huobao-drama - 后端可执行文件web/dist/ - 前端静态文件(已嵌入后端)需要上传到服务器的文件:
huobao-drama # 后端可执行文件
configs/config.yaml # 配置文件
data/ # 数据目录(可选,首次运行自动创建)
# 上传文件到服务器
scp huobao-drama user@server:/opt/huobao-drama/
scp configs/config.yaml user@server:/opt/huobao-drama/configs/
# SSH登录服务器
ssh user@server
# 修改配置文件
cd /opt/huobao-drama
vim configs/config.yaml
# 设置mode为production
# 配置域名和存储路径
# 创建数据目录并设置权限(重要!)
# 注意:将 YOUR_USER 替换为实际运行服务的用户名(如 www-data、ubuntu、deploy 等)
sudo mkdir -p /opt/huobao-drama/data/storage
sudo chown -R YOUR_USER:YOUR_USER /opt/huobao-drama/data
sudo chmod -R 755 /opt/huobao-drama/data
# 赋予执行权限
chmod +x huobao-drama
# 启动服务
./huobao-drama
创建服务文件 /etc/systemd/system/huobao-drama.service:
[Unit]
Description=Huobao Drama Service
After=network.target
[Service]
Type=simple
User=YOUR_USER
WorkingDirectory=/opt/huobao-drama
ExecStart=/opt/huobao-drama/huobao-drama
Restart=on-failure
RestartSec=10
# 环境变量(可选)
# Environment="GIN_MODE=release"
[Install]
WantedBy=multi-user.target
启动服务:
sudo systemctl daemon-reload
sudo systemctl enable huobao-drama
sudo systemctl start huobao-drama
sudo systemctl status huobao-drama
⚠️ 常见问题:SQLite 写权限错误
如果遇到 attempt to write a readonly database 错误:
# 1. 确认当前运行服务的用户
sudo systemctl status huobao-drama | grep "Main PID"
ps aux | grep huobao-drama
# 2. 修复权限(将 YOUR_USER 替换为实际用户名)
sudo chown -R YOUR_USER:YOUR_USER /opt/huobao-drama/data
sudo chmod -R 755 /opt/huobao-drama/data
# 3. 验证权限
ls -la /opt/huobao-drama/data
# 应该显示所有者为运行服务的用户
# 4. 重启服务
sudo systemctl restart huobao-drama
原因说明:
-wal、-journal)User 与数据目录所有者一致常用用户名:
www-data、ubuntunginx、apachedeploy、app、当前登录用户server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:5678;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# 静态文件直接访问
location /static/ {
alias /opt/huobao-drama/data/storage/;
}
}
A: 使用 http://host.docker.internal:11434/v1 作为 Base URL。注意两点:
0.0.0.0:export OLLAMA_HOST=0.0.0.0:11434 && ollama servedocker run 需添加:--add-host=host.docker.internal:host-gatewayA: 确保 FFmpeg 已安装并在 PATH 环境变量中。运行 ffmpeg -version 验证。
A: 检查后端是否启动,端口是否正确。开发模式下前端代理配置在 web/vite.config.ts。
A: GORM 会在首次启动时自动创建表,检查日志确认迁移是否成功。
modernc.org/sqlite),支持 CGO_ENABLED=0 跨平台编译host.docker.internal 访问宿主机服务欢迎提交 Issue 和 Pull Request!
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)2 分钟完成配置:API 聚合站点
AI 火宝 - AI 工作室创业中
"让 AI 帮我们做更有创造力的事"

⭐ 如果这个项目对你有帮助,请给一个 Star!
$ claude mcp add huobao-drama \
-- python -m otcore.mcp_server <graph>