diff --git a/utils/__pycache__/content_judger.cpython-312.pyc b/utils/__pycache__/content_judger.cpython-312.pyc new file mode 100644 index 0000000..1820624 Binary files /dev/null and b/utils/__pycache__/content_judger.cpython-312.pyc differ diff --git a/utils/__pycache__/output_handler.cpython-312.pyc b/utils/__pycache__/output_handler.cpython-312.pyc index ee6c618..547b7a7 100644 Binary files a/utils/__pycache__/output_handler.cpython-312.pyc and b/utils/__pycache__/output_handler.cpython-312.pyc differ diff --git a/utils/__pycache__/poster_notes_creator.cpython-312.pyc b/utils/__pycache__/poster_notes_creator.cpython-312.pyc index e50b985..7ce0edb 100644 Binary files a/utils/__pycache__/poster_notes_creator.cpython-312.pyc and b/utils/__pycache__/poster_notes_creator.cpython-312.pyc differ diff --git a/utils/__pycache__/prompt_manager.cpython-312.pyc b/utils/__pycache__/prompt_manager.cpython-312.pyc index ac00924..fd0c3c7 100644 Binary files a/utils/__pycache__/prompt_manager.cpython-312.pyc and b/utils/__pycache__/prompt_manager.cpython-312.pyc differ diff --git a/utils/__pycache__/tweet_generator.cpython-312.pyc b/utils/__pycache__/tweet_generator.cpython-312.pyc index f5d67eb..6d44fd5 100644 Binary files a/utils/__pycache__/tweet_generator.cpython-312.pyc and b/utils/__pycache__/tweet_generator.cpython-312.pyc differ diff --git a/utils/output_handler.py b/utils/output_handler.py index 72b0192..e0cc9e4 100644 --- a/utils/output_handler.py +++ b/utils/output_handler.py @@ -91,9 +91,40 @@ class FileSystemOutputHandler(OutputHandler): """Saves content JSON and prompt for a specific variant.""" variant_dir = self._get_variant_dir(run_id, topic_index, variant_index) + # 检查内容是否经过审核 + if content_data.get("judged", False): + # 保存原始内容到raw_data.json + raw_content = { + "title": content_data.get("original_title", content_data.get("title", "")), + "content": content_data.get("original_content", content_data.get("content", "")), + "tag": content_data.get("tag", ""), # 确保保留tag字段 + "error": content_data.get("error", False) + } + + # 如果内容里没有original_字段,则认为当前内容就是原始内容 + if "original_title" not in content_data and "original_content" not in content_data: + # 先深拷贝当前内容数据以避免修改原数据 + import copy + raw_content = copy.deepcopy(content_data) + # 移除审核相关字段 + raw_content.pop("judged", None) + raw_content.pop("judge_analysis", None) + + raw_data_path = os.path.join(variant_dir, "raw_data.json") + try: + with open(raw_data_path, "w", encoding="utf-8") as f: + json.dump(raw_content, f, ensure_ascii=False, indent=4) + logging.info(f"原始内容保存到: {raw_data_path}") + except Exception as e: + logging.exception(f"保存原始内容到 {raw_data_path} 失败: {e}") + # Save content JSON content_path = os.path.join(variant_dir, "article.json") try: + # 确保tag字段存在 + if "tag" not in content_data and content_data.get("tags"): + content_data["tag"] = content_data["tags"] + with open(content_path, "w", encoding="utf-8") as f: json.dump(content_data, f, ensure_ascii=False, indent=4) logging.info(f"Content JSON saved to: {content_path}") diff --git a/utils/prompt_manager.py b/utils/prompt_manager.py index fe9b465..7305246 100644 --- a/utils/prompt_manager.py +++ b/utils/prompt_manager.py @@ -23,11 +23,13 @@ class PromptManager: prompts_config: list = None, # 新的配置方式 resource_dir_config: list = None, topic_gen_num: int = 1, # Default values if needed - topic_gen_date: str = "" + topic_gen_date: str = "", + content_judger_system_prompt_path: str = None # 添加内容审核系统提示词路径参数 ): self.topic_system_prompt_path = topic_system_prompt_path self.topic_user_prompt_path = topic_user_prompt_path self.content_system_prompt_path = content_system_prompt_path + self.content_judger_system_prompt_path = content_judger_system_prompt_path # 添加成员变量 self.prompts_dir = prompts_dir # 保留兼容旧配置 self.prompts_config = prompts_config or [] # 新的配置方式 self.resource_dir_config = resource_dir_config or [] @@ -67,6 +69,13 @@ class PromptManager: self._system_prompt_cache["content"] = content logging.info(f"预加载内容系统提示词: {self.content_system_prompt_path}") + # 预加载内容审核系统提示词 + if self.content_judger_system_prompt_path and os.path.exists(self.content_judger_system_prompt_path): + content = ResourceLoader.load_file_content(self.content_judger_system_prompt_path) + if content: + self._system_prompt_cache["judger_system_prompt"] = content + logging.info(f"预加载内容审核系统提示词: {self.content_judger_system_prompt_path}") + # 预加载日期线文件 if self.topic_user_prompt_path: user_prompt_dir = os.path.dirname(self.topic_user_prompt_path) diff --git a/utils/tweet_generator.py b/utils/tweet_generator.py index 117ca8e..cd1a28b 100644 --- a/utils/tweet_generator.py +++ b/utils/tweet_generator.py @@ -512,6 +512,10 @@ content: {content_json.get('content', '')} if "title" in judged_result and "content" in judged_result: # 使用审核后的内容替换原内容 logging.info(f" 内容审核成功,使用审核后的内容替换原内容") + # 保存原始标题和内容 + content_json["original_title"] = content_json.get("title", "") + content_json["original_content"] = content_json.get("content", "") + # 更新为审核后的内容 content_json["title"] = judged_result["title"] content_json["content"] = judged_result["content"] # 添加审核标记