追加了数据保存的方式
This commit is contained in:
parent
8dc8f32b87
commit
125eaffe5f
BIN
utils/__pycache__/content_judger.cpython-312.pyc
Normal file
BIN
utils/__pycache__/content_judger.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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}")
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"]
|
||||
# 添加审核标记
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user