修改了tweet相关的响应模型

This commit is contained in:
jinye_huang 2025-07-14 13:41:43 +08:00
parent 495b7525ae
commit d04e406972
6 changed files with 20 additions and 6 deletions

View File

@ -46,8 +46,11 @@ class TopicResponse(BaseModel):
"date": "2023-07-15",
"object": "北京故宫",
"product": "故宫门票",
"product_logic": "套票包含水上碰碰船等消暑项目,契合夏季游玩需求",
"style": "旅游攻略",
"style_logic": "重点解析如何避开高温时段并高效游玩各园区",
"target_audience": "年轻人",
"target_audience_logic": "解决家长担心孩子中暑的问题,提供科学游玩方案",
"logic": "暑期旅游热门景点推荐"
}
]
@ -89,6 +92,7 @@ class ContentResponse(BaseModel):
request_id: str = Field(..., description="请求ID")
topic_index: str = Field(..., description="选题索引")
content: Dict[str, Any] = Field(..., description="生成的内容")
judge_success: Optional[bool] = Field(None, description="审核是否成功(仅在启用自动审核时返回)")
class Config:
schema_extra = {
@ -99,7 +103,8 @@ class ContentResponse(BaseModel):
"title": "【北京故宫】避开人潮的秘密路线90%的人都不知道!",
"content": "故宫,作为中国最著名的文化遗产之一...",
"tag": ["北京旅游", "故宫", "旅游攻略", "避暑胜地"]
}
},
"judge_success": True
}
}
@ -142,7 +147,7 @@ class JudgeResponse(BaseModel):
"""内容审核响应模型"""
request_id: str = Field(..., description="请求ID")
topic_index: str = Field(..., description="选题索引")
judged_content: Dict[str, Any] = Field(..., description="审核后的内容")
content: Dict[str, Any] = Field(..., description="审核后的内容")
judge_success: bool = Field(..., description="审核是否成功")
class Config:
@ -150,7 +155,7 @@ class JudgeResponse(BaseModel):
"example": {
"request_id": "judge_20230715_123456",
"topic_index": "1",
"judged_content": {
"content": {
"title": "【北京故宫】避开人潮的秘密路线90%的人都不知道!",
"content": "故宫,作为中国最著名的文化遗产之一...",
"tag": ["北京旅游", "故宫", "旅游攻略", "避暑胜地"]

View File

@ -111,10 +111,14 @@ async def generate_content(
auto_judge=request.auto_judge
)
# 提取judge_success字段
judge_success = content.pop('judge_success', None) if isinstance(content, dict) else None
return ContentResponse(
request_id=request_id,
topic_index=topic_index,
content=content
content=content,
judge_success=judge_success
)
except Exception as e:
logger.error(f"生成内容失败: {e}", exc_info=True)
@ -143,7 +147,8 @@ async def generate_content_with_prompt(
return ContentResponse(
request_id=request_id,
topic_index=topic_index,
content=content
content=content,
judge_success=None
)
except Exception as e:
logger.error(f"使用预构建提示词生成内容失败: {e}", exc_info=True)
@ -178,7 +183,7 @@ async def judge_content(
return JudgeResponse(
request_id=request_id,
topic_index=topic_index,
judged_content=judged_content,
content=judged_content,
judge_success=judge_success
)
except Exception as e:

View File

@ -156,9 +156,13 @@ class TweetService:
content = judged_content
else:
logger.warning(f"选题 {topic_index} 内容审核失败,使用原始内容")
# 为原始内容添加审核失败标记
content['judge_success'] = False
except Exception as e:
logger.error(f"选题 {topic_index} 内嵌审核失败: {e},使用原始内容")
# 为原始内容添加审核失败标记
content['judge_success'] = False
# 生成请求ID
request_id = f"content_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{str(uuid.uuid4())[:8]}"