6.2 KiB
6.2 KiB
TravelContentCreator 架构迁移进度
迁移状态
| Phase | 状态 | 完成日期 |
|---|---|---|
| Phase 1: 基础结构创建 | ✅ 完成 | 2024-12-08 |
| Phase 2: 引擎封装 | ✅ 完成 | 2024-12-08 |
| Phase 3: API 集成 | ✅ 完成 | 2024-12-08 |
| Phase 4: 基础设施层 | ✅ 完成 | 2024-12-08 |
| Phase 5: ppid 支持 | ✅ 完成 | 2024-12-08 |
| Phase 6: 旧代码拆分 | ✅ 完成 | 2024-12-08 |
| Phase 7: 清理优化 | 🔲 待开始 | - |
Phase 1: 基础结构创建 ✅
已完成
-
路径配置 (
config/paths.json)- 项目路径配置化,避免硬编码
-
领域层结构 (
domain/)domain/ ├── __init__.py └── aigc/ ├── __init__.py ├── engine_registry.py # 引擎注册表 ├── engine_executor.py # 引擎执行器 ├── engines/ │ ├── __init__.py │ ├── base.py # 引擎基类 │ ├── poster_generate.py # 海报生成引擎 │ ├── content_generate.py # 内容生成引擎 │ └── topic_generate.py # 选题生成引擎 └── shared/ ├── __init__.py ├── component_factory.py # 组件工厂 ├── llm_client.py # LLM 客户端 ├── prompt_builder.py # 提示词构建器 ├── image_processor.py # 图片处理器 ├── database_accessor.py # 数据库访问器 └── file_storage.py # 文件存储
Phase 2: 引擎封装 ✅
已完成
- PosterGenerateEngine - 封装现有 PosterService
- ContentGenerateEngine - 封装现有 TweetService 内容生成
- TopicGenerateEngine - 封装现有 TweetService 选题生成
引擎特性
- 统一的参数 Schema 定义
- 自动参数验证
- 进度追踪
- 执行时间预估
Phase 3: API 集成 ✅
已完成
-
AIGC 统一路由 (
api/routers/aigc.py)POST /api/v2/aigc/execute- 执行引擎GET /api/v2/aigc/task/{task_id}/status- 查询任务状态POST /api/v2/aigc/task/{task_id}/cancel- 取消任务GET /api/v2/aigc/engines- 列出所有引擎GET /api/v2/aigc/engines/{engine_id}- 获取引擎详情GET /api/v2/aigc/tasks- 列出任务POST /api/v2/aigc/tasks/cleanup- 清理任务
-
主应用集成 (
api/main.py)- V1 API 保持不变
- V2 API 新增 AIGC 统一入口
Phase 4: 基础设施层 ✅
已完成
-
数据库连接管理 (
infrastructure/database/connection.py)- 连接池管理
- 配置加载(支持环境变量)
- 上下文管理器
-
Repository 基类 (
infrastructure/database/base_repository.py)- 通用 CRUD 操作
- 软删除支持
- 批量查询
-
具体 Repository (
infrastructure/database/repositories/)ScenicSpotRepository- 景区ProductRepository- 产品ProductPackageRepository- 套餐 (ppid)StyleRepository- 风格AudienceRepository- 受众TemplateRepository- 模板
Phase 5: ppid 支持 ✅
已完成
-
所有引擎支持 ppid 参数
poster_generate- 海报生成content_generate- 内容生成topic_generate- 选题生成
-
ppid 解析逻辑
ProductPackageRepository.resolve_ids(ppid)- 解析为 scenic_spot_id + product_idDatabaseAccessor.resolve_ppid(ppid)- 便捷方法
-
与 Java 端对齐
- 参考
AigcCompatibilityService.getOriginalIdsByPackageId() - 统一使用 ppid 作为入口
- 参考
Phase 6: 旧代码拆分 ✅
已完成
-
海报领域模块 (
domain/poster/)TemplateManager- 模板加载和管理FabricGenerator- Fabric.js JSON 生成PosterRenderer- 海报渲染和输出
-
内容领域模块 (
domain/content/)TopicEngine- 选题生成引擎ContentEngine- 内容生成引擎JudgeEngine- 内容审核引擎TopicIDMappingManager- ID 映射管理
-
引擎集成
PosterGenerateEngine可使用新的TemplateManager,FabricGenerator,PosterRendererTopicGenerateEngine可使用新的TopicEngineContentGenerateEngine可使用新的ContentEngine,JudgeEngine
迁移策略
当前采用渐进式迁移:
- 新引擎同时保留旧服务调用和新模块调用
- 可通过配置切换使用哪个实现
- 验证新模块功能后,逐步移除旧服务依赖
Phase 7: 清理优化 (待开始)
计划
- 删除冗余代码
- 更新 import 路径
- 添加单元测试
- 性能优化
使用指南
新增 AIGC 功能
只需创建一个引擎文件:
# domain/aigc/engines/new_feature.py
from .base import BaseAIGCEngine, EngineResult
class NewFeatureEngine(BaseAIGCEngine):
engine_id = "new_feature"
engine_name = "新功能"
version = "1.0.0"
description = "功能描述"
def get_param_schema(self):
return {
"param1": {"type": "str", "required": True, "desc": "参数1"},
}
async def execute(self, params):
# 实现逻辑
return EngineResult(success=True, data={...})
引擎会被自动发现和注册。
调用 API
# 执行引擎 (同步)
curl -X POST http://localhost:8000/api/v2/aigc/execute \
-H "Content-Type: application/json" \
-d '{"engine": "poster_generate", "params": {"template_id": "vibrant", "images": [...]}}'
# 执行引擎 (异步)
curl -X POST http://localhost:8000/api/v2/aigc/execute \
-H "Content-Type: application/json" \
-d '{"engine": "poster_generate", "params": {...}, "async_mode": true}'
# 查询任务状态
curl http://localhost:8000/api/v2/aigc/task/{task_id}/status
# 列出所有引擎
curl http://localhost:8000/api/v2/aigc/engines
测试
# 运行测试
cd /root/TravelContentCreator
python3 tests/test_aigc_engines.py
注意事项
- V1 API 保持兼容 - 现有调用不受影响
- 渐进式迁移 - 新引擎封装旧服务,逐步替换
- 路径配置化 - 所有路径通过
config/paths.json配置