更新了文档,增加了部分解耦功能

This commit is contained in:
jinye_huang 2025-04-22 14:34:07 +08:00
parent 0a048da5dd
commit 64f91f288e

View File

@ -32,7 +32,7 @@ pip install numpy pandas opencv-python pillow
## 核心组件与目录结构
- `main.py`: 项目入口,负责加载配置、编排主要流程(选题生成 -> 内容与海报生成)。
- `main.py`: **项目入口与协调器**: 负责加载配置、初始化共享资源(如 AI Agent、并按顺序调用 `utils` 模块中的函数来执行主要流程(选题生成 -> 内容与海报生成协调)。
- `poster_gen_config.json`: (用户需从 `example_config.json` 创建) 核心配置文件。
- `core/`: 核心算法与功能模块
- `ai_agent.py`: **AI代理**: 封装与大语言模型 API 的底层交互逻辑(发送请求、接收响应)。
@ -41,9 +41,9 @@ pip install numpy pandas opencv-python pillow
- `posterGen.py`: **海报生成器**: 负责将图片和文字元素组合生成最终的海报图片,处理字体、布局等。
- `simple_collage.py`: **图片拼贴工具**: 提供图片预处理和拼贴功能。
- `utils/`: 工具与辅助模块
- `resource_loader.py`: **资源加载器**: 负责加载项目所需的各种**原始**资源文件(如文本文件、配置文件中的路径指向的文件)
- `prompt_manager.py`: **提示词管理器**: **集中管理**不同阶段(选题、内容生成)的提示词构建逻辑。它调用 `ResourceLoader` 获取基础文件,并根据配置和当前任务(如特定选题)组装最终的 System Prompt 和 User Prompt。
- `tweet_generator.py`: **流程与数据结构**: 包含选题生成 (`run_topic_generation_pipeline`) 和单篇内容生成 (`generate_single_content`) 的流程函数,以及相关的数据类(如 `tweetTopicRecord`, `tweetContent`
- `resource_loader.py`: **资源加载器**: 负责加载项目所需的各种**原始**资源文件。
- `prompt_manager.py`: **提示词管理器**: **集中管理**不同阶段提示词构建逻辑。
- `tweet_generator.py`: **主要流程执行与数据结构**: 包含执行**选题生成** (`run_topic_generation_pipeline`)、**单选题内容生成** (`generate_content_for_topic`)、**单选题海报生成** (`generate_posters_for_topic`) 的核心函数,以及相关的数据类
- `genPrompts/`: 内容生成提示词模板目录。
- `SelectPrompt/`: 选题生成提示词模板目录。
- `resource/`: 存放基础的景点信息 `.txt` 文件等数据资源。
@ -54,23 +54,24 @@ pip install numpy pandas opencv-python pillow
1. **加载配置**: `main.py` 读取 `poster_gen_config.json` 文件。
2. **选题生成**:
- 调用 `utils.tweet_generator.run_topic_generation_pipeline`
- 内部调用 `utils.prompt_manager.PromptManager.get_topic_prompts()` 来构建选题阶段的系统和用户提示词(结合模板、资源文件、配置参数)。
- 初始化一个 `core.ai_agent.AI_Agent` 实例。
- 调用 AI Agent 发送请求生成选题文本。
- 使用 `core.topic_parser` 解析结果。
- 保存选题结果 (`tweet_topic.json`) 到输出目录。
- 关闭此阶段的 AI Agent。
3. **内容与海报生成**: (在 `main.generate_content_and_posters_step` 中执行)
- 初始化 `utils.prompt_manager.PromptManager`**一个共享的** `core.ai_agent.AI_Agent` 实例供此阶段所有任务使用(**优化点避免为每个变体重复创建Agent**)。
- 遍历上一步生成的每个选题 (`topic_item`)
- 为当前选题调用 `prompt_manager.get_content_prompts(topic_item)` 获取内容生成的特定提示词。
- 遍历每个变体 (variant)
- 调用 `utils.tweet_generator.generate_single_content`,传入**共享的 AI Agent** 和**特定于此选题的提示词**,生成推文内容。
- 调用 `core.contentGen` 处理生成的文本内容,准备海报所需元素。
- 调用 `core.simple_collage` 处理图片。
- 调用 `core.posterGen` 结合图片和文本生成最终海报。
- 所有选题处理完毕后,关闭此阶段共享的 AI Agent。
- `main.py` 调用 `utils.tweet_generator.run_topic_generation_pipeline(config)`
- 此函数内部:
- 调用 `utils.prompt_manager.PromptManager.get_topic_prompts()` 构建提示词。
- 初始化 `core.ai_agent.AI_Agent`
- 调用 AI Agent 生成选题文本。
- 使用 `core.topic_parser` 解析结果。
- 保存选题结果 (`tweet_topic.json`)。
- 关闭此阶段的 AI Agent。
- 返回 `run_id``tweet_topic_record``main.py`
3. **内容与海报生成协调**: (在 `main.generate_content_and_posters_step` 中执行)
- 初始化 `utils.prompt_manager.PromptManager`
- 初始化一个**共享的** `core.ai_agent.AI_Agent` 实例供后续所有内容生成使用。
- 遍历上一步返回的每个选题 (`topic_item`)
- **内容生成**: 调用 `utils.tweet_generator.generate_content_for_topic()`,传入共享的 AI Agent、Prompt Manager、配置和当前选题信息。
- 此函数内部循环生成该选题的所有内容变体,每次调用 `prompt_manager.get_content_prompts()` 获取特定提示词,并使用共享 AI Agent 执行 `generate_single_content`
- **海报生成**: 如果内容生成成功,调用 `utils.tweet_generator.generate_posters_for_topic()`,传入配置、选题信息和生成的内容列表。
- 此函数内部负责初始化 `ContentGenerator``PosterGenerator`,调用 `core` 模块中的函数处理图片和文本,并生成所有海报变体。
- 所有选题处理完毕后,在 `main.generate_content_and_posters_step` 中关闭共享的 AI Agent。
## 使用方法