修改了结果Json文件的格式
This commit is contained in:
parent
125eaffe5f
commit
fd19997834
Binary file not shown.
@ -91,42 +91,29 @@ 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)
|
||||
output_data = copy.deepcopy(content_data)
|
||||
|
||||
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}")
|
||||
# 确保tag和tags字段保持一致
|
||||
if "tag" not in output_data and output_data.get("tags"):
|
||||
output_data["tag"] = output_data["tags"]
|
||||
elif "tags" not in output_data and output_data.get("tag"):
|
||||
output_data["tags"] = output_data["tag"]
|
||||
|
||||
# Save content JSON
|
||||
# 确保即使在未启用审核的情况下,字段也保持一致
|
||||
if not output_data.get("judged", False):
|
||||
output_data["judged"] = False
|
||||
# 添加original_title、original_content和judge_analysis字段,值为null
|
||||
output_data["original_title"] = None
|
||||
output_data["original_content"] = None
|
||||
output_data["judge_analysis"] = None
|
||||
|
||||
# 保存统一格式的article.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)
|
||||
json.dump(output_data, f, ensure_ascii=False, indent=4)
|
||||
logging.info(f"Content JSON saved to: {content_path}")
|
||||
except Exception as e:
|
||||
logging.exception(f"Failed to save content JSON to {content_path}: {e}")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user