2025-07-10 17:51:37 +08:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
海报API模型定义
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from typing import List, Dict, Any, Optional, Tuple
|
|
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PosterRequest(BaseModel):
|
|
|
|
|
|
"""海报生成请求模型"""
|
|
|
|
|
|
content: Dict[str, Any] = Field(..., description="内容数据,包含标题、正文等")
|
|
|
|
|
|
topic_index: str = Field(..., description="主题索引,用于文件命名")
|
|
|
|
|
|
template_name: Optional[str] = Field(None, description="模板名称,如果为None则根据配置选择")
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
schema_extra = {
|
|
|
|
|
|
"example": {
|
|
|
|
|
|
"content": {
|
|
|
|
|
|
"title": "【北京故宫】避开人潮的秘密路线,90%的人都不知道!",
|
|
|
|
|
|
"content": "故宫,作为中国最著名的文化遗产之一...",
|
|
|
|
|
|
"tag": ["北京旅游", "故宫", "旅游攻略", "避暑胜地"]
|
|
|
|
|
|
},
|
|
|
|
|
|
"topic_index": "1",
|
|
|
|
|
|
"template_name": "vibrant"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PosterResponse(BaseModel):
|
|
|
|
|
|
"""海报生成响应模型"""
|
|
|
|
|
|
request_id: str = Field(..., description="请求ID")
|
|
|
|
|
|
topic_index: str = Field(..., description="主题索引")
|
|
|
|
|
|
poster_path: str = Field(..., description="生成的海报文件路径")
|
|
|
|
|
|
template_name: str = Field(..., description="使用的模板名称")
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
schema_extra = {
|
|
|
|
|
|
"example": {
|
2025-07-14 13:59:22 +08:00
|
|
|
|
"request_id": "poster-20240715-123456-a1b2c3d4",
|
2025-07-10 17:51:37 +08:00
|
|
|
|
"topic_index": "1",
|
|
|
|
|
|
"poster_path": "/result/run_20230715_123456/topic_1/poster_vibrant.png",
|
|
|
|
|
|
"template_name": "vibrant"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TemplateListResponse(BaseModel):
|
|
|
|
|
|
"""模板列表响应模型"""
|
|
|
|
|
|
templates: List[str] = Field(..., description="可用的模板列表")
|
|
|
|
|
|
default_template: str = Field(..., description="默认模板")
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
schema_extra = {
|
|
|
|
|
|
"example": {
|
|
|
|
|
|
"templates": ["vibrant", "business", "collage"],
|
|
|
|
|
|
"default_template": "vibrant"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PosterTextRequest(BaseModel):
|
|
|
|
|
|
"""海报文案生成请求模型"""
|
|
|
|
|
|
system_prompt: str = Field(..., description="系统提示词")
|
|
|
|
|
|
user_prompt: str = Field(..., description="用户提示词")
|
|
|
|
|
|
context_data: Optional[Dict[str, Any]] = Field(None, description="上下文数据,用于填充提示词中的占位符")
|
|
|
|
|
|
temperature: Optional[float] = Field(0.3, description="生成温度参数")
|
|
|
|
|
|
top_p: Optional[float] = Field(0.4, description="top_p参数")
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
schema_extra = {
|
|
|
|
|
|
"example": {
|
|
|
|
|
|
"system_prompt": "你是一位专业的旅游海报文案撰写专家...",
|
|
|
|
|
|
"user_prompt": "请为{location}的{attraction}创作一段简短有力的海报文案...",
|
|
|
|
|
|
"context_data": {
|
|
|
|
|
|
"location": "北京",
|
|
|
|
|
|
"attraction": "故宫"
|
|
|
|
|
|
},
|
|
|
|
|
|
"temperature": 0.3,
|
|
|
|
|
|
"top_p": 0.4
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PosterTextResponse(BaseModel):
|
|
|
|
|
|
"""海报文案生成响应模型"""
|
|
|
|
|
|
request_id: str = Field(..., description="请求ID")
|
|
|
|
|
|
text_content: Dict[str, Any] = Field(..., description="生成的文案内容")
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
schema_extra = {
|
|
|
|
|
|
"example": {
|
2025-07-14 13:59:22 +08:00
|
|
|
|
"request_id": "text-20240715-123456-a1b2c3d4",
|
2025-07-10 17:51:37 +08:00
|
|
|
|
"text_content": {
|
|
|
|
|
|
"title": "紫禁城的秘密",
|
|
|
|
|
|
"subtitle": "600年历史,等你探索",
|
|
|
|
|
|
"description": "穿越时光,触摸历史,感受帝王的荣耀与辉煌"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|