#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 文字内容API模型定义 """ from typing import List, Dict, Any, Optional from pydantic import BaseModel, Field class TopicRequest(BaseModel): """选题生成请求模型""" dates: Optional[str] = Field(None, description="日期字符串,可能为单个日期、多个日期用逗号分隔或范围如'2023-01-01 to 2023-01-31'") num_topics: int = Field(5, description="要生成的选题数量", ge=1, le=10) styles: Optional[List[str]] = Field(None, description="风格列表") audiences: Optional[List[str]] = Field(None, description="受众列表") scenic_spots: Optional[List[str]] = Field(None, description="景区列表") products: Optional[List[str]] = Field(None, description="产品列表") class Config: schema_extra = { "example": { "dates": "2023-07-01 to 2023-07-31", "num_topics": 5, "styles": ["旅游攻略", "亲子游"], "audiences": ["年轻人", "家庭"], "scenic_spots": ["故宫", "长城"], "products": ["门票", "导游服务"] } } class TopicResponse(BaseModel): """选题生成响应模型""" request_id: str = Field(..., description="请求ID") topics: List[Dict[str, Any]] = Field(..., description="生成的选题列表") class Config: schema_extra = { "example": { "request_id": "topic_20230715_123456", "topics": [ { "index": "1", "date": "2023-07-15", "object": "北京故宫", "product": "故宫门票", "style": "旅游攻略", "target_audience": "年轻人", "logic": "暑期旅游热门景点推荐" } ] } } class ContentRequest(BaseModel): """内容生成请求模型""" topic: Dict[str, Any] = Field(..., description="选题信息") class Config: schema_extra = { "example": { "topic": { "index": "1", "date": "2023-07-15", "object": "北京故宫", "product": "故宫门票", "style": "旅游攻略", "target_audience": "年轻人", "logic": "暑期旅游热门景点推荐" } } } class ContentResponse(BaseModel): """内容生成响应模型""" request_id: str = Field(..., description="请求ID") topic_index: str = Field(..., description="选题索引") content: Dict[str, Any] = Field(..., description="生成的内容") class Config: schema_extra = { "example": { "request_id": "content_20230715_123456", "topic_index": "1", "content": { "title": "【北京故宫】避开人潮的秘密路线,90%的人都不知道!", "content": "故宫,作为中国最著名的文化遗产之一...", "tag": ["北京旅游", "故宫", "旅游攻略", "避暑胜地"] } } } class JudgeRequest(BaseModel): """内容审核请求模型""" topic: Dict[str, Any] = Field(..., description="选题信息") content: Dict[str, Any] = Field(..., description="要审核的内容") class Config: schema_extra = { "example": { "topic": { "index": "1", "date": "2023-07-15", "object": "北京故宫", "product": "故宫门票", "style": "旅游攻略", "target_audience": "年轻人", "logic": "暑期旅游热门景点推荐" }, "content": { "title": "【北京故宫】避开人潮的秘密路线,90%的人都不知道!", "content": "故宫,作为中国最著名的文化遗产之一...", "tag": ["北京旅游", "故宫", "旅游攻略", "避暑胜地"] } } } class JudgeResponse(BaseModel): """内容审核响应模型""" request_id: str = Field(..., description="请求ID") topic_index: str = Field(..., description="选题索引") judged_content: Dict[str, Any] = Field(..., description="审核后的内容") judge_success: bool = Field(..., description="审核是否成功") class Config: schema_extra = { "example": { "request_id": "judge_20230715_123456", "topic_index": "1", "judged_content": { "title": "【北京故宫】避开人潮的秘密路线,90%的人都不知道!", "content": "故宫,作为中国最著名的文化遗产之一...", "tag": ["北京旅游", "故宫", "旅游攻略", "避暑胜地"] }, "judge_success": True } } class PipelineRequest(BaseModel): """完整流程请求模型""" dates: Optional[str] = Field(None, description="日期字符串,可能为单个日期、多个日期用逗号分隔或范围如'2023-01-01 to 2023-01-31'") num_topics: int = Field(5, description="要生成的选题数量", ge=1, le=10) styles: Optional[List[str]] = Field(None, description="风格列表") audiences: Optional[List[str]] = Field(None, description="受众列表") scenic_spots: Optional[List[str]] = Field(None, description="景区列表") products: Optional[List[str]] = Field(None, description="产品列表") skip_judge: bool = Field(False, description="是否跳过内容审核步骤") class Config: schema_extra = { "example": { "dates": "2023-07-01 to 2023-07-31", "num_topics": 3, "styles": ["旅游攻略", "亲子游"], "audiences": ["年轻人", "家庭"], "scenic_spots": ["故宫", "长城"], "products": ["门票", "导游服务"], "skip_judge": False } } class PipelineResponse(BaseModel): """完整流程响应模型""" request_id: str = Field(..., description="请求ID") topics: List[Dict[str, Any]] = Field(..., description="生成的选题列表") contents: Dict[str, Dict[str, Any]] = Field(..., description="生成的内容,键为选题索引") judged_contents: Dict[str, Dict[str, Any]] = Field(..., description="审核后的内容,键为选题索引") class Config: schema_extra = { "example": { "request_id": "pipeline_20230715_123456", "topics": [ { "index": "1", "date": "2023-07-15", "object": "北京故宫", "product": "故宫门票", "style": "旅游攻略", "target_audience": "年轻人", "logic": "暑期旅游热门景点推荐" } ], "contents": { "1": { "title": "【北京故宫】避开人潮的秘密路线,90%的人都不知道!", "content": "故宫,作为中国最著名的文化遗产之一..." } }, "judged_contents": { "1": { "title": "【北京故宫】避开人潮的秘密路线,90%的人都不知道!", "content": "故宫,作为中国最著名的文化遗产之一...", "tag": ["北京旅游", "故宫", "旅游攻略", "避暑胜地"], "judge_success": True } } } }