Files

288 lines
12 KiB
Markdown
Raw Permalink 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.
# AI PaaS 商业平台 - 架构方案
## 架构概览
基于需求分析,采用 **平台底座 + 标准化中间件 + AI 能力层** 三层架构:
```
┌─────────────────────────────────────────────────────────────────────┐
│ 用户入口层 │
│ Web UI / IM Bot / CLI / OpenAPI / MCP Client / ACP │
└───────────────────────────┬─────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────┐
│ 平台底座层 │
│ ┌─────────────┐ ┌──────────────┐ ┌──────────────┐ ┌────────────┐ │
│ │ Auth/多租户 │ │ 订阅+Token计费 │ │ 用户Dashboard │ │ Admin 管理 │ │
│ └─────────────┘ └──────────────┘ └──────────────┘ └────────────┘ │
└───────────────────────────┬─────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────┐
│ 标准化中间件层(核心 IP) │
│ │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ Capability Registry(能力注册中心) │ │
│ │ - 每个 AI 项目注册为 Capability │ │
│ │ - 标准接口:发现 / 调用 / 计费 / 版本管理 │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────────┐ │
│ │ API Gateway │ │ LLM Router │ │ Metering │ │ OpenAPI 网关 │ │
│ │ 统一入口 │ │ 多平台模型 │ │ 用量追踪 │ │ 外部应用接入 │ │
│ └────────────┘ └────────────┘ └────────────┘ └────────────────┘ │
└───────────────────────────┬─────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────────────┐
│ AI 能力层(各取所长) │
│ │
│ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌──────┐ │
│ │ Agent │ │ MCP │ │ Skills │ │ LLM │ │ ACP │ │ IMBot│ │
│ │ 编排 │ │ Server │ │ 市场 │ │ Provider│ │ Agent │ │ │ │
│ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └──────┘ │
│ LangFlow mcp-hub 自研 多平台对接 自研 LangBot │
└─────────────────────────────────────────────────────────────────────┘
```
## 技术选型
### 平台底座候选方案
| 方案 | 底座 | 许可证 | 多租户 | 计费 | 成熟度 | 风险 |
|------|------|--------|--------|------|--------|------|
| **方案一** | Sovra | MIT ✅ | ✅ 内置 | ✅ Stripe | ⭐ (1星) | 高 |
| **方案二** | 全自研 | - | ✅ 自研 | ✅ 自研 | 需 6-9 月 | 低 |
| **方案三** | CoAI | Apache 2.0 ✅ | ✅ 内置 | ✅ 内置 | ⭐⭐⭐ | 中 |
### 推荐方案:方案三(CoAI 底座)
**选择理由**:
1. **许可证合规**:Apache 2.0 允许多租户 SaaS 商业化
2. **功能齐全**:OpenAI 兼容 API + 订阅计费 + 多租户 + 模型市场
3. **快速验证**:可在 2-3 个月内上线 MVP
4. **自主可控**:自研标准化中间件层,核心 IP 不受限
### 标准化中间件设计
#### Capability Registry(能力注册中心)
```yaml
# 能力注册示例
capabilities:
- id: "langflow-agent"
name: "LangFlow Agent 编排"
type: "agent"
version: "1.0.0"
endpoint: "http://langflow:7860/api/v1"
auth_type: "api_key"
billing_model: "per_request"
description: "可视化 AI Agent 工作流编排"
tags: ["agent", "workflow", "no-code"]
- id: "langbot-im"
name: "LangBot 即时通讯"
type: "imbot"
version: "2.0.0"
endpoint: "http://langbot:5300/api"
auth_type: "jwt"
billing_model: "subscription"
description: "多平台即时通讯机器人"
tags: ["im", "wechat", "qq"]
- id: "mcp-hub"
name: "MCP 服务管理"
type: "mcp"
version: "1.0.0"
endpoint: "http://mcp-hub:3001/api"
auth_type: "api_key"
billing_model: "per_token"
description: "MCP 协议服务发现与管理"
tags: ["mcp", "protocol", "tools"]
```
#### LLM Provider Router
```yaml
# 多平台模型配置
llm_providers:
- name: "deepseek"
base_url: "https://api.deepseek.com/v1"
api_key: "${DEEPSEEK_API_KEY}"
models: ["deepseek-chat", "deepseek-coder"]
compatible: true # OpenAI 兼容
- name: "qianwen"
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
api_key: "${QIANWEN_API_KEY}"
models: ["qwen-turbo", "qwen-plus", "qwen-max"]
compatible: true
- name: "doubao"
base_url: "https://ark.cn-beijing.volces.com/api/v3"
api_key: "${DOUBAO_API_KEY}"
models: ["doubao-pro", "doubao-lite"]
compatible: true
- name: "baidu"
base_url: "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop"
api_key: "${BAIDU_API_KEY}"
models: ["ernie-4.0", "ernie-3.5"]
compatible: false # 需要适配层
- name: "yuanbao"
base_url: "https://api.yuanbao.tencent.com/v1"
api_key: "${YUANBAO_API_KEY}"
models: ["yuanbao-pro", "yuanbao-lite"]
compatible: true
```
### AI 能力层选型
| 能力 | 推荐项目 | 许可证 | 成熟度 | 作用 |
|------|---------|--------|--------|------|
| **Agent 编排** | LangFlow | MIT ✅ | ⭐⭐⭐⭐⭐ | 可视化工作流编排 |
| **IM Bot** | LangBot | Apache 2.0 ✅ | ⭐⭐⭐⭐ | 个人微信/多平台 |
| **MCP** | mcp-hub | MIT ✅ | ⭐⭐⭐ | MCP 服务管理 |
| **知识库** | FastGPT | ❌ 限制 | ⭐⭐⭐⭐⭐ | 单租户使用 |
| **Skills 市场** | 自研 | - | - | 完全自定义 |
| **ACP** | 自研 | - | - | Agent 间通信 |
## 标准化中间件 API 设计
### 能力注册 API
```http
POST /api/v1/capabilities
Content-Type: application/json
Authorization: Bearer <token>
{
"id": "my-agent",
"name": "我的智能体",
"type": "agent",
"version": "1.0.0",
"endpoint": "http://my-agent:8000/api",
"auth_type": "api_key",
"billing_model": "per_request",
"description": "自定义 AI Agent"
}
```
### 能力调用 API
```http
POST /api/v1/capabilities/{capability_id}/invoke
Content-Type: application/json
Authorization: Bearer <token>
{
"method": "chat",
"params": {
"model": "gpt-4",
"messages": [
{"role": "user", "content": "你好"}
]
}
}
```
### 用量查询 API
```http
GET /api/v1/usage?user_id=xxx&start_date=2026-06-01&end_date=2026-06-30
Authorization: Bearer <token>
```
## 实施路线图
### 阶段一:MVP(2-3 月)
**目标**:上线基础版本,验证商业模式
- [ ] 部署 CoAI 底座(多租户 + 计费)
- [ ] 部署 LangBot(IM Bot)
- [ ] 部署 LangFlow(Agent 编排)
- [ ] 实现 Capability Registry 基础版
- [ ] 实现 LLM Provider Router(接入 DeepSeek、千问、豆包)
- [ ] 用户 Dashboard 基础版
- [ ] 基础计费功能
### 阶段二:功能完善(3-4 月)
**目标**:补齐核心功能,提升用户体验
- [ ] MCP 支持(部署 mcp-hub)
- [ ] Skills 市场 v1(发布、审核、交易)
- [ ] 知识库功能(集成 FastGPT 单租户版)
- [ ] ACP 协议实现
- [ ] 高级计费模式(订阅 + Token 混合)
- [ ] 管理后台完善
### 阶段三:商业化(2-3 月)
**目标**:正式商业化运营
- [ ] 支付集成(支付宝、微信支付)
- [ ] 开发者文档完善
- [ ] API 开放平台
- [ ] 运营数据分析
- [ ] 安全审计与合规
- [ ] 性能优化与扩展
## 验证计划
### 多平台 LLM 对接验证
1. **DeepSeek**:直接 OpenAI 兼容,无需适配
2. **千问**:直接 OpenAI 兼容,无需适配
3. **豆包**:直接 OpenAI 兼容,无需适配
4. **百度**:需要适配层,封装非标准 API 为 OpenAI 格式
5. **元宝**:直接 OpenAI 兼容,无需适配
6. **智谱**:直接 OpenAI 兼容,无需适配
7. **本地 Ollama**:直接 OpenAI 兼容,无需适配
### 测试用例
```python
# 统一调用示例
import openai
# DeepSeek
client = openai.OpenAI(
base_url="https://api.deepseek.com/v1",
api_key="your-deepseek-key"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "你好"}]
)
# 千问
client = openai.OpenAI(
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
api_key="your-qianwen-key"
)
response = client.chat.completions.create(
model="qwen-turbo",
messages=[{"role": "user", "content": "你好"}]
)
```
## 风险与对策
| 风险 | 影响 | 对策 |
|------|------|------|
| CoAI 停更 | 中 | 核心功能自研,CoAI 仅作底座 |
| LangFlow 依赖 | 低 | MIT 许可,可自行维护 |
| LLM API 价格波动 | 中 | 多平台路由,自动选择最优 |
| 多租户性能 | 高 | 数据库分库分表,缓存优化 |
| 计费纠纷 | 中 | 实时用量追踪,详细日志 |
## 总结
本方案的核心竞争力在于 **标准化中间件层**:
- **Capability Registry**:让每个 AI 项目都能标准化接入
- **LLM Router**:统一多平台模型对接
- **Metering**:精确的用量追踪与计费
通过这种架构,可以快速接入各种 AI 能力,形成 **AI 能力市场**,为个人用户提供完整的 AI 服务交易平台。