修改了content接口的响应,正确反映judge
This commit is contained in:
parent
015570b685
commit
3aa2775ec1
@ -170,7 +170,6 @@ class JudgeResponse(BaseModel):
|
|||||||
"title": "天津冒险湾亲子游攻略",
|
"title": "天津冒险湾亲子游攻略",
|
||||||
"content": "经过审核的详细游玩攻略内容...",
|
"content": "经过审核的详细游玩攻略内容...",
|
||||||
"tags": ["亲子游", "水上乐园", "天津"],
|
"tags": ["亲子游", "水上乐园", "天津"],
|
||||||
"judgeSuccess": True
|
|
||||||
},
|
},
|
||||||
"judgeSuccess": True
|
"judgeSuccess": True
|
||||||
}
|
}
|
||||||
|
|||||||
@ -278,8 +278,10 @@ async def generate_content(
|
|||||||
autoJudge=request.autoJudge
|
autoJudge=request.autoJudge
|
||||||
)
|
)
|
||||||
|
|
||||||
# 提取judge_success字段
|
# 提取judgeSuccess字段,从content中移除以避免重复
|
||||||
judge_success = content.pop('judge_success', None) if isinstance(content, dict) else None
|
judge_success = None
|
||||||
|
if isinstance(content, dict) and 'judgeSuccess' in content:
|
||||||
|
judge_success = content.pop('judgeSuccess')
|
||||||
|
|
||||||
return ContentResponse(
|
return ContentResponse(
|
||||||
requestId=request_id,
|
requestId=request_id,
|
||||||
|
|||||||
@ -115,7 +115,7 @@ class TweetService:
|
|||||||
autoJudge: 是否自动进行内容审核
|
autoJudge: 是否自动进行内容审核
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
请求ID、选题索引和生成的内容(如果启用审核则返回审核后的内容)
|
请求ID、选题索引和生成的内容(包含judgeSuccess状态)
|
||||||
"""
|
"""
|
||||||
# 如果没有提供topic,创建一个基础的topic
|
# 如果没有提供topic,创建一个基础的topic
|
||||||
if not topic:
|
if not topic:
|
||||||
@ -155,18 +155,26 @@ class TweetService:
|
|||||||
# 进行内容审核
|
# 进行内容审核
|
||||||
judged_content = await self.content_judger.judge_content_with_prompt(content, enhanced_topic, judge_system_prompt, judge_user_prompt)
|
judged_content = await self.content_judger.judge_content_with_prompt(content, enhanced_topic, judge_system_prompt, judge_user_prompt)
|
||||||
|
|
||||||
if judged_content.get('judgeSuccess', False):
|
# 统一输出格式:始终包含judgeSuccess状态
|
||||||
logger.info(f"选题 {topicIndex} 内容审核成功,使用审核后的内容")
|
# content_judger返回的是judge_success字段(下划线命名)
|
||||||
content = judged_content
|
judge_success = judged_content.get('judge_success', False)
|
||||||
|
if judge_success:
|
||||||
|
logger.info(f"选题 {topicIndex} 内容审核成功")
|
||||||
|
# 审核成功:使用审核后的内容,但移除judge_success,添加统一的judgeSuccess
|
||||||
|
content = {k: v for k, v in judged_content.items() if k != 'judge_success'}
|
||||||
|
content['judgeSuccess'] = True
|
||||||
else:
|
else:
|
||||||
logger.warning(f"选题 {topicIndex} 内容审核失败,使用原始内容")
|
logger.warning(f"选题 {topicIndex} 内容审核失败,保持原始内容")
|
||||||
# 添加审核失败标记
|
# 审核失败:保持原始内容,添加judgeSuccess=False标记
|
||||||
content['judgeSuccess'] = False
|
content['judgeSuccess'] = False
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"选题 {topicIndex} 内嵌审核失败: {e},使用原始内容")
|
logger.error(f"选题 {topicIndex} 内嵌审核失败: {e},保持原始内容")
|
||||||
# 添加审核失败标记
|
# 审核异常:保持原始内容,添加judgeSuccess=False标记
|
||||||
content['judgeSuccess'] = False
|
content['judgeSuccess'] = False
|
||||||
|
else:
|
||||||
|
# 未启用审核:添加judgeSuccess=None标记,表示未进行审核
|
||||||
|
content['judgeSuccess'] = None
|
||||||
|
|
||||||
# 生成请求ID
|
# 生成请求ID
|
||||||
requestId = f"content-{datetime.now().strftime('%Y%m%d-%H%M%S')}-{str(uuid.uuid4())[:8]}"
|
requestId = f"content-{datetime.now().strftime('%Y%m%d-%H%M%S')}-{str(uuid.uuid4())[:8]}"
|
||||||
@ -245,8 +253,13 @@ class TweetService:
|
|||||||
# 使用预构建的提示词进行审核
|
# 使用预构建的提示词进行审核
|
||||||
judged_data = await self.content_judger.judge_content_with_prompt(content, enhanced_topic, system_prompt, user_prompt)
|
judged_data = await self.content_judger.judge_content_with_prompt(content, enhanced_topic, system_prompt, user_prompt)
|
||||||
|
|
||||||
# 提取审核是否成功
|
# 提取审核是否成功(content_judger返回judge_success字段)
|
||||||
judgeSuccess = judged_data.get('judgeSuccess', False)
|
judgeSuccess = judged_data.get('judge_success', False)
|
||||||
|
|
||||||
|
# 统一字段命名:移除judge_success,添加judgeSuccess
|
||||||
|
if 'judge_success' in judged_data:
|
||||||
|
judged_data = {k: v for k, v in judged_data.items() if k != 'judge_success'}
|
||||||
|
judged_data['judgeSuccess'] = judgeSuccess
|
||||||
|
|
||||||
# 生成请求ID
|
# 生成请求ID
|
||||||
requestId = f"judge-{datetime.now().strftime('%Y%m%d-%H%M%S')}-{str(uuid.uuid4())[:8]}"
|
requestId = f"judge-{datetime.now().strftime('%Y%m%d-%H%M%S')}-{str(uuid.uuid4())[:8]}"
|
||||||
@ -290,14 +303,28 @@ class TweetService:
|
|||||||
|
|
||||||
# 2. 为每个选题生成内容
|
# 2. 为每个选题生成内容
|
||||||
contents = {}
|
contents = {}
|
||||||
|
judgedContents = {}
|
||||||
|
|
||||||
for topic in topics:
|
for topic in topics:
|
||||||
topicIndex = topic.get('index', 'unknown')
|
topicIndex = topic.get('index', 'unknown')
|
||||||
_, _, content = await self.generate_content(topic, autoJudge=autoJudge)
|
_, _, content = await self.generate_content(topic, autoJudge=autoJudge)
|
||||||
|
|
||||||
|
if autoJudge:
|
||||||
|
# 内嵌审核模式:content已包含审核结果和judgeSuccess状态
|
||||||
|
# 创建原始内容副本(移除judgeSuccess状态,但保留其他字段)
|
||||||
|
original_content = {k: v for k, v in content.items() if k != 'judgeSuccess'}
|
||||||
|
contents[topicIndex] = original_content
|
||||||
|
judgedContents[topicIndex] = content # 包含审核结果和judgeSuccess状态
|
||||||
|
else:
|
||||||
|
# 无审核模式:直接保存内容
|
||||||
contents[topicIndex] = content
|
contents[topicIndex] = content
|
||||||
|
|
||||||
# 如果使用内嵌审核或跳过审核,直接返回结果
|
# 如果使用内嵌审核或跳过审核,直接返回结果
|
||||||
if autoJudge or skipJudge:
|
if autoJudge or skipJudge:
|
||||||
logger.info(f"{'使用内嵌审核' if autoJudge else '跳过内容审核步骤'},流水线完成,请求ID: {requestId}")
|
logger.info(f"{'使用内嵌审核' if autoJudge else '跳过内容审核步骤'},流水线完成,请求ID: {requestId}")
|
||||||
|
if autoJudge:
|
||||||
|
return requestId, topics, contents, judgedContents
|
||||||
|
else:
|
||||||
return requestId, topics, contents, contents
|
return requestId, topics, contents, contents
|
||||||
|
|
||||||
# 3. 对每个内容进行审核
|
# 3. 对每个内容进行审核
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user