一个基于 AI 的智能文章生成工具,通过多智能体协作完成标题、大纲、正文生成和配图自动匹配。
- Go 1.26.2 - 编程语言
- Gin - Web 框架
- GORM - ORM 框架
- PostgreSQL - 关系型数据库
- Redis - 缓存和 Session 存储
- LangChainGo - LLM 集成框架
- Stripe - 支付集成
- Vue 3 - 前端框架
- TypeScript - 类型安全
- Ant Design Vue - UI 组件库
- Vite - 构建工具
- Pinia - 状态管理
- Vue Router - 路由管理
ai-passage/
├── cmd/server/ # 后端入口
├── internal/
│ ├── agent/ # 多智能体系统
│ │ ├── agents/ # 具体智能体实现
│ │ ├── parallel/ # 并行处理
│ │ └── orchestrator.go # 智能体编排器
│ ├── app/ # 应用初始化
│ ├── common/ # 公共组件
│ ├── config/ # 配置
│ ├── handler/ # HTTP 处理器
│ ├── middleware/ # 中间件
│ ├── model/ # 数据模型
│ ├── service/ # 业务服务层
│ └── store/ # 数据访问层
├── web/ # 前端项目
│ └── src/
│ ├── api/ # API 调用
│ ├── components/ # 组件
│ ├── pages/ # 页面
│ ├── router/ # 路由
│ ├── stores/ # Pinia 状态
│ └── utils/ # 工具函数
└── docs/ # Swagger 文档
- 阶段 1: 生成多个标题方案供用户选择
- 阶段 2: 生成文章大纲,支持用户编辑和 AI 辅助修改
- 阶段 3: 流式生成正文 + 智能配图
项目采用了两种模式:
- ArticleAgentService: 传统单服务实现(保留用于兼容)
- ArticleAgentOrchestrator: 多智能体编排模式(推荐)
智能体列表:
TitleGenerator- 标题生成智能体OutlineGenerator- 大纲生成智能体ContentGenerator- 正文生成智能体ImageAnalyzer- 配图需求分析智能体ParallelImageGenerator- 并行配图生成器ContentMerger- 图文合成智能体
支持 7 种配图来源:
- PEXELS - 高清无版权照片
- NANO_BANANA (VIP) - Gemini AI 生图
- MERMAID - 流程图/架构图
- ICONIFY - 图标库
- EMOJI_PACK - 表情包
- SVG_DIAGRAM (VIP) - SVG 概念图
- PICSUM - 降级方案
- 用户注册/登录
- 配额管理
- VIP 会员(Stripe 支付)
- 管理员功能
- Go 1.26+
- Node.js 18+
- PostgreSQL 14+
- Redis 7+
复制 config.yaml.example 为 config.yaml 并填写配置:
server:
port: 8123
database:
host: localhost
port: 5432
name: ai_passage
user: postgres
password: your-password
redis:
host: localhost
port: 6379
ai:
dashscope:
api_key: your-dashscope-api-key
model: qwen-plus
pexels:
api_key: your-pexels-api-keycd ai-passage
go mod download
go run cmd/server/main.gocd web
npm install
npm run dev启动后端后访问:http://localhost:8123/api/swagger/index.html
本项目使用 Stripe 测试模式,无需企业资质,直接注册即可使用。
访问 Stripe 官网 注册账号(仅需邮箱)
- 登录 Stripe Dashboard
- 确保处于 测试模式(Test mode)
- 进入 开发者 -> API 密钥 页面
- 复制 Secret key(以
sk_test_开头)
编辑 config.yaml,添加 Stripe 配置:
stripe:
api_key: sk_test_你的密钥
webhook_secret: whsec_你的webhook密钥
success_url: http://localhost:5173/vip?success=true
cancel_url: http://localhost:5173/vip?cancelled=true使用以下测试卡号:
| 卡号 | 有效期 | CVC | 说明 |
|---|---|---|---|
| 4242 4242 4242 4242 | 任意未来日期 | 任意3位数 | 支付成功 |
| 4000 0000 0000 0002 | 任意未来日期 | 任意3位数 | 支付失败 |
-
安装 Stripe CLI:
# macOS brew install stripe/stripe-cli/stripe # Windows # 下载 https://github.com/stripe/stripe-cli/releases
-
登录 Stripe:
stripe login
-
转发 Webhook 到本地:
stripe listen --forward-to localhost:8123/api/webhook/stripe
-
复制显示的 webhook 签名密钥(以
whsec_开头)到配置文件
- 进入 开发者 -> Webhooks 页面
- 点击 添加端点
- 填写 URL:
https://你的域名/api/webhook/stripe - 选择事件:
checkout.session.completedcheckout.session.async_payment_succeeded
- 复制 签名密钥 到配置文件
- 启动后端服务
- 启动前端服务
- 登录普通用户账号
- 访问 VIP 购买页面
/vip - 点击 "立即购买"
- 在 Stripe 支付页面使用测试卡号
- 完成支付后,用户自动升级为 VIP
POST http://localhost:8123/api/payment/refund
Content-Type: application/json
{
"reason": "用户申请退款"
}- 进入 支付 -> 所有支付
- 找到对应的支付记录
- 点击 退款
Q: 如何切换到生产模式?
A: 在 Stripe Dashboard 关闭测试模式,使用生产环境的 API 密钥(以 sk_live_ 开头)
Q: Webhook 签名验证失败?
A: 确保 webhook_secret 配置正确,并且请求来自 Stripe
Q: 支付成功但用户未升级?
A: 检查 Webhook 是否正常工作,查看后端日志
- 测试模式:完全免费,不产生任何费用
- 生产模式:Stripe 收取手续费(约 2.9% + $0.30/笔)
- ✅ 使用 HTTPS(生产环境)
- ✅ 验证 Webhook 签名
- ✅ 实现幂等性检查
- ✅ 定期检查支付记录
- ❌ 不要在前端暴露 Secret Key
- ❌ 不要跳过签名验证
MIT License