修改了文档 加入了适用于api的改造方案

This commit is contained in:
jinye_huang 2025-04-22 17:51:14 +08:00
parent 58add25adb
commit b176add779

View File

@ -82,7 +82,7 @@ pip install numpy pandas opencv-python pillow openai
3. 复制 `example_config.json``poster_gen_config.json`,并根据你的 API Key、模型端点、文件路径、图片根目录等进行修改。确保 `prompts_dir` 下的 `Style/``Demand/` 目录包含选题生成 AI 可能输出的文件名 (带 `.txt` 后缀)。确保 `Refer/` 目录下包含所有需要的参考文件。
4. **运行完整流程**:
```bash
python main.py
python main.py --config poster_gen_config.json
```
5. **分阶段运行**: (参考 `examples/` 目录下的脚本,**注意需要传递 run_id**)
```bash
@ -235,4 +235,39 @@ finally:
这个模式允许你灵活地利用流式输出,同时在需要时也能访问到最终的完整文本。参考 `examples/test_stream.py` 获取可运行的示例(该示例也包含了拼接逻辑,只是默认注释了最后的打印)。
**注意:** 如果你只需要最终的完整结果而不需要流式处理,可以直接调用 `ai_agent.work(...)` 方法,它会内部处理好拼接并直接返回结果字符串。
**注意:** 如果你只需要最终的完整结果而不需要流式处理,可以直接调用 `ai_agent.work(...)` 方法,它会内部处理好拼接并直接返回结果字符串。
### Planned Refactoring: Decoupling Generation and Output Handling
To enhance the flexibility and extensibility of this tool, we are planning a refactoring effort to separate the core content/image generation logic from the output handling (currently, saving results to the local filesystem).
**Motivation:**
* **API Integration:** Allow generated results (topics, text content, image URLs/data) to be easily returned via an API endpoint instead of only being saved locally.
* **Alternative Storage:** Enable saving results to different backends like databases, cloud storage (e.g., S3, OSS), etc.
* **Modularity:** Improve code structure by separating concerns.
**Approach:**
1. **Modify Core Functions:** Functions responsible for generating topics, content, and posters (primarily in `utils/tweet_generator.py` and potentially `core` modules) will be updated to **return** the generated data (e.g., Python dictionaries, lists, PIL Image objects, or image bytes) rather than directly writing files to the `./result` directory.
2. **Introduce Output Handlers:** An "Output Handler" pattern will be implemented.
* An abstract base class or interface (`OutputHandler`) will define methods for processing different types of results (topics, content, configurations, images).
* An initial concrete implementation (`FileSystemOutputHandler`) will replicate the current behavior of saving all results to the `./result/{run_id}/...` directory structure.
3. **Update Main Workflow:** The main script (`main.py`) will be modified to:
* Instantiate a specific `OutputHandler` (initially the `FileSystemOutputHandler`).
* Call the generation functions to get the data.
* Pass the returned data to the `OutputHandler` instance for processing (e.g., saving).
**Future Possibilities:**
This refactoring will make it straightforward to add new output handlers in the future, such as:
* `ApiOutputHandler`: Formats results for API responses.
* `DatabaseOutputHandler`: Stores results in a database.
* `CloudStorageOutputHandler`: Uploads results (especially images) to cloud storage and potentially stores metadata elsewhere.
**(Note:** This refactoring is in progress. The current documentation reflects the existing file-saving behavior, but expect changes in how results are handled internally.)
### 配置文件说明 (Configuration)
主配置文件为 `poster_gen_config.json` (可以复制 `example_config.json` 并修改)。主要包含以下部分: