From 3aa2775ec15f7746ed5dbec9929fa4324f6be001 Mon Sep 17 00:00:00 2001 From: jinye_huang Date: Wed, 16 Jul 2025 18:24:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86content=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9A=84=E5=93=8D=E5=BA=94=EF=BC=8C=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E5=8F=8D=E6=98=A0judge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/models/tweet.py | 1 - api/routers/tweet.py | 6 +++-- api/services/tweet.py | 51 +++++++++++++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/api/models/tweet.py b/api/models/tweet.py index fbda200..c962043 100644 --- a/api/models/tweet.py +++ b/api/models/tweet.py @@ -170,7 +170,6 @@ class JudgeResponse(BaseModel): "title": "天津冒险湾亲子游攻略", "content": "经过审核的详细游玩攻略内容...", "tags": ["亲子游", "水上乐园", "天津"], - "judgeSuccess": True }, "judgeSuccess": True } diff --git a/api/routers/tweet.py b/api/routers/tweet.py index 40d6fee..6f094de 100644 --- a/api/routers/tweet.py +++ b/api/routers/tweet.py @@ -278,8 +278,10 @@ async def generate_content( autoJudge=request.autoJudge ) - # 提取judge_success字段 - judge_success = content.pop('judge_success', None) if isinstance(content, dict) else None + # 提取judgeSuccess字段,从content中移除以避免重复 + judge_success = None + if isinstance(content, dict) and 'judgeSuccess' in content: + judge_success = content.pop('judgeSuccess') return ContentResponse( requestId=request_id, diff --git a/api/services/tweet.py b/api/services/tweet.py index 4458a12..d703297 100644 --- a/api/services/tweet.py +++ b/api/services/tweet.py @@ -115,7 +115,7 @@ class TweetService: autoJudge: 是否自动进行内容审核 Returns: - 请求ID、选题索引和生成的内容(如果启用审核则返回审核后的内容) + 请求ID、选题索引和生成的内容(包含judgeSuccess状态) """ # 如果没有提供topic,创建一个基础的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) - if judged_content.get('judgeSuccess', False): - logger.info(f"选题 {topicIndex} 内容审核成功,使用审核后的内容") - content = judged_content + # 统一输出格式:始终包含judgeSuccess状态 + # content_judger返回的是judge_success字段(下划线命名) + 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: - logger.warning(f"选题 {topicIndex} 内容审核失败,使用原始内容") - # 添加审核失败标记 + logger.warning(f"选题 {topicIndex} 内容审核失败,保持原始内容") + # 审核失败:保持原始内容,添加judgeSuccess=False标记 content['judgeSuccess'] = False except Exception as e: - logger.error(f"选题 {topicIndex} 内嵌审核失败: {e},使用原始内容") - # 添加审核失败标记 + logger.error(f"选题 {topicIndex} 内嵌审核失败: {e},保持原始内容") + # 审核异常:保持原始内容,添加judgeSuccess=False标记 content['judgeSuccess'] = False + else: + # 未启用审核:添加judgeSuccess=None标记,表示未进行审核 + content['judgeSuccess'] = None # 生成请求ID 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) - # 提取审核是否成功 - judgeSuccess = judged_data.get('judgeSuccess', False) + # 提取审核是否成功(content_judger返回judge_success字段) + 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 requestId = f"judge-{datetime.now().strftime('%Y%m%d-%H%M%S')}-{str(uuid.uuid4())[:8]}" @@ -290,15 +303,29 @@ class TweetService: # 2. 为每个选题生成内容 contents = {} + judgedContents = {} + for topic in topics: topicIndex = topic.get('index', 'unknown') _, _, content = await self.generate_content(topic, autoJudge=autoJudge) - contents[topicIndex] = content + + 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 # 如果使用内嵌审核或跳过审核,直接返回结果 if autoJudge or skipJudge: logger.info(f"{'使用内嵌审核' if autoJudge else '跳过内容审核步骤'},流水线完成,请求ID: {requestId}") - return requestId, topics, contents, contents + if autoJudge: + return requestId, topics, contents, judgedContents + else: + return requestId, topics, contents, contents # 3. 对每个内容进行审核 judgedContents = {}