Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

AI Passage - AI 爆款文章创作器

一个基于 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. 多阶段文章创作流程

  • 阶段 1: 生成多个标题方案供用户选择
  • 阶段 2: 生成文章大纲,支持用户编辑和 AI 辅助修改
  • 阶段 3: 流式生成正文 + 智能配图

2. 多智能体架构

项目采用了两种模式:

  • ArticleAgentService: 传统单服务实现(保留用于兼容)
  • ArticleAgentOrchestrator: 多智能体编排模式(推荐)

智能体列表:

  • TitleGenerator - 标题生成智能体
  • OutlineGenerator - 大纲生成智能体
  • ContentGenerator - 正文生成智能体
  • ImageAnalyzer - 配图需求分析智能体
  • ParallelImageGenerator - 并行配图生成器
  • ContentMerger - 图文合成智能体

3. 丰富的配图方式

支持 7 种配图来源:

  • PEXELS - 高清无版权照片
  • NANO_BANANA (VIP) - Gemini AI 生图
  • MERMAID - 流程图/架构图
  • ICONIFY - 图标库
  • EMOJI_PACK - 表情包
  • SVG_DIAGRAM (VIP) - SVG 概念图
  • PICSUM - 降级方案

4. 用户系统

  • 用户注册/登录
  • 配额管理
  • 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-key

启动后端

cd ai-passage
go mod download
go run cmd/server/main.go

启动前端

cd web
npm install
npm run dev

API 文档

启动后端后访问:http://localhost:8123/api/swagger/index.html

Stripe 支付配置

本项目使用 Stripe 测试模式,无需企业资质,直接注册即可使用。

1. 注册 Stripe 账号

访问 Stripe 官网 注册账号(仅需邮箱)

2. 获取 API 密钥

  1. 登录 Stripe Dashboard
  2. 确保处于 测试模式(Test mode)
  3. 进入 开发者 -> API 密钥 页面
  4. 复制 Secret key(以 sk_test_ 开头)

3. 配置后端

编辑 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

4. 测试支付

使用以下测试卡号:

卡号 有效期 CVC 说明
4242 4242 4242 4242 任意未来日期 任意3位数 支付成功
4000 0000 0000 0002 任意未来日期 任意3位数 支付失败

5. 配置 Webhook(本地开发)

方法一:使用 Stripe CLI(推荐)

  1. 安装 Stripe CLI:

    # macOS
    brew install stripe/stripe-cli/stripe
    
    # Windows
    # 下载 https://github.com/stripe/stripe-cli/releases
  2. 登录 Stripe:

    stripe login
  3. 转发 Webhook 到本地:

    stripe listen --forward-to localhost:8123/api/webhook/stripe
  4. 复制显示的 webhook 签名密钥(以 whsec_ 开头)到配置文件

方法二:使用 Stripe Dashboard(生产环境)

  1. 进入 开发者 -> Webhooks 页面
  2. 点击 添加端点
  3. 填写 URL: https://你的域名/api/webhook/stripe
  4. 选择事件:
    • checkout.session.completed
    • checkout.session.async_payment_succeeded
  5. 复制 签名密钥 到配置文件

6. 测试流程

  1. 启动后端服务
  2. 启动前端服务
  3. 登录普通用户账号
  4. 访问 VIP 购买页面 /vip
  5. 点击 "立即购买"
  6. 在 Stripe 支付页面使用测试卡号
  7. 完成支付后,用户自动升级为 VIP

7. 退款功能

通过 API 退款

POST http://localhost:8123/api/payment/refund
Content-Type: application/json

{
  "reason": "用户申请退款"
}

通过 Stripe Dashboard 退款

  1. 进入 支付 -> 所有支付
  2. 找到对应的支付记录
  3. 点击 退款

8. 常见问题

Q: 如何切换到生产模式?

A: 在 Stripe Dashboard 关闭测试模式,使用生产环境的 API 密钥(以 sk_live_ 开头)

Q: Webhook 签名验证失败?

A: 确保 webhook_secret 配置正确,并且请求来自 Stripe

Q: 支付成功但用户未升级?

A: 检查 Webhook 是否正常工作,查看后端日志

9. 价格说明

  • 测试模式:完全免费,不产生任何费用
  • 生产模式:Stripe 收取手续费(约 2.9% + $0.30/笔)

10. 安全建议

  • ✅ 使用 HTTPS(生产环境)
  • ✅ 验证 Webhook 签名
  • ✅ 实现幂等性检查
  • ✅ 定期检查支付记录
  • ❌ 不要在前端暴露 Secret Key
  • ❌ 不要跳过签名验证

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages