2025-07-10 17:51:37 +08:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
2025-07-18 19:32:55 +08:00
|
|
|
|
海报API模型定义 - 使用 camelCase 命名约定
|
2025-07-10 17:51:37 +08:00
|
|
|
|
"""
|
|
|
|
|
|
|
2025-07-25 17:13:37 +08:00
|
|
|
|
from re import T
|
2025-07-17 16:15:02 +08:00
|
|
|
|
from typing import List, Dict, Any, Optional
|
2025-07-28 10:32:41 +08:00
|
|
|
|
from datetime import datetime
|
2025-07-10 17:51:37 +08:00
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-17 16:15:02 +08:00
|
|
|
|
class PosterGenerateRequest(BaseModel):
|
2025-07-10 17:51:37 +08:00
|
|
|
|
"""海报生成请求模型"""
|
2025-07-18 19:32:55 +08:00
|
|
|
|
templateId: str = Field("vibrant", description="模板ID")
|
2025-08-04 13:43:52 +08:00
|
|
|
|
imagesBase64: Optional[List[str]] = Field(None, description="图像base64编码列表")
|
2025-07-18 19:32:55 +08:00
|
|
|
|
posterContent: Optional[Dict[str, Any]] = Field(None, description="海报内容,如果提供则直接使用此内容")
|
2025-07-28 20:14:11 +08:00
|
|
|
|
contentId: Optional[str] = Field(None, description="内容ID,用于AI生成内容")
|
|
|
|
|
|
productId: Optional[str] = Field(None, description="产品ID,用于AI生成内容")
|
|
|
|
|
|
scenicSpotId: Optional[str] = Field(None, description="景区ID,用于AI生成内容")
|
2025-07-18 19:32:55 +08:00
|
|
|
|
numVariations: int = Field(3, description="要生成的海报变体数量, 默认为3", ge=1, le=5)
|
|
|
|
|
|
forceLlmGeneration: bool = Field(False, description="是否强制使用LLM重新生成内容")
|
2025-07-27 22:55:51 +08:00
|
|
|
|
generatePsd: bool = Field(False, description="是否生成PSD分层文件")
|
|
|
|
|
|
psdOutputPath: Optional[str] = Field(None, description="PSD文件输出路径(可选,默认自动生成)")
|
2025-07-10 17:51:37 +08:00
|
|
|
|
|
|
|
|
|
|
class Config:
|
2025-07-18 19:32:55 +08:00
|
|
|
|
json_schema_extra = {
|
2025-07-10 17:51:37 +08:00
|
|
|
|
"example": {
|
2025-07-18 19:32:55 +08:00
|
|
|
|
"templateId": "vibrant",
|
2025-08-04 13:45:14 +08:00
|
|
|
|
"imagesBase64": "",
|
2025-07-25 17:13:37 +08:00
|
|
|
|
"numVariations": 1,
|
|
|
|
|
|
"forceLlmGeneration":False,
|
2025-07-27 22:55:51 +08:00
|
|
|
|
"generatePsd": True,
|
|
|
|
|
|
"psdOutputPath": "custom_poster.psd",
|
2025-07-28 20:14:11 +08:00
|
|
|
|
"contentId":"1",
|
|
|
|
|
|
"productId":"1",
|
|
|
|
|
|
"scenicSpotId":"1",
|
2025-07-25 17:13:37 +08:00
|
|
|
|
"posterContent":{
|
|
|
|
|
|
"title":"天津冒险湾",
|
|
|
|
|
|
"slogan":"天津冒险湾,让你体验不一样的冒险之旅"
|
2025-07-18 19:32:55 +08:00
|
|
|
|
}
|
2025-07-10 17:51:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-18 19:32:55 +08:00
|
|
|
|
class TemplateInfo(BaseModel):
|
|
|
|
|
|
"""模板信息模型"""
|
|
|
|
|
|
id: str
|
|
|
|
|
|
name: str
|
|
|
|
|
|
description: str
|
2025-07-28 10:32:41 +08:00
|
|
|
|
handler_path: str = Field(alias="handlerPath")
|
|
|
|
|
|
class_name: str = Field(alias="className")
|
|
|
|
|
|
system_prompt: Optional[str] = None
|
|
|
|
|
|
user_prompt_template: Optional[str] = None
|
|
|
|
|
|
required_fields: Optional[List[str]] = None
|
|
|
|
|
|
optional_fields: Optional[List[str]] = None
|
|
|
|
|
|
size: Optional[List[int]] = None
|
|
|
|
|
|
is_active: bool = Field(alias="isActive")
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
allow_population_by_field_name = True
|
2025-07-10 17:51:37 +08:00
|
|
|
|
|
2025-07-18 19:32:55 +08:00
|
|
|
|
class TemplateListResponse(BaseModel):
|
|
|
|
|
|
"""模板列表响应模型"""
|
|
|
|
|
|
templates: List[TemplateInfo]
|
|
|
|
|
|
totalCount: int
|
2025-07-17 16:15:02 +08:00
|
|
|
|
|
2025-07-18 19:32:55 +08:00
|
|
|
|
class ImageUsageInfo(BaseModel):
|
|
|
|
|
|
"""图像使用信息模型"""
|
|
|
|
|
|
imageId: int
|
|
|
|
|
|
usageCount: int
|
|
|
|
|
|
firstUsedAt: str
|
|
|
|
|
|
lastUsedAt: str
|
|
|
|
|
|
usageContext: List[str]
|
2025-07-17 16:15:02 +08:00
|
|
|
|
|
|
|
|
|
|
class PosterGenerateResponse(BaseModel):
|
2025-07-10 17:51:37 +08:00
|
|
|
|
"""海报生成响应模型"""
|
2025-07-18 19:32:55 +08:00
|
|
|
|
requestId: str
|
|
|
|
|
|
templateId: str
|
2025-07-25 17:13:37 +08:00
|
|
|
|
resultImagesBase64: List[Dict[str, Any]] = Field(description="生成的海报图像(base64编码)列表")
|
2025-07-27 22:55:51 +08:00
|
|
|
|
psdFiles: Optional[List[Dict[str, Any]]] = Field(None, description="生成的PSD文件信息列表")
|
2025-07-18 19:32:55 +08:00
|
|
|
|
metadata: Dict[str, Any] = Field(default_factory=dict)
|
2025-07-28 10:32:41 +08:00
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
json_encoders = {
|
|
|
|
|
|
datetime: lambda v: v.isoformat()
|
|
|
|
|
|
}
|
2025-07-10 17:51:37 +08:00
|
|
|
|
|
2025-07-17 16:15:02 +08:00
|
|
|
|
class ImageUsageRequest(BaseModel):
|
|
|
|
|
|
"""图像使用查询请求模型"""
|
2025-07-18 19:32:55 +08:00
|
|
|
|
imageIds: List[int]
|
2025-07-10 17:51:37 +08:00
|
|
|
|
|
2025-07-17 16:15:02 +08:00
|
|
|
|
class ImageUsageResponse(BaseModel):
|
|
|
|
|
|
"""图像使用情况响应模型"""
|
2025-07-18 19:32:55 +08:00
|
|
|
|
requestId: str
|
|
|
|
|
|
imageUsageInfo: List[ImageUsageInfo]
|
2025-07-25 17:13:37 +08:00
|
|
|
|
summary: Dict[str, Any]
|
|
|
|
|
|
|