2025-07-10 17:51:37 +08:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
2025-07-17 16:15:02 +08:00
|
|
|
|
海报API模型定义 - 简化版本
|
|
|
|
|
|
只保留核心功能,重点优化图片ID使用追踪
|
2025-07-10 17:51:37 +08:00
|
|
|
|
"""
|
|
|
|
|
|
|
2025-07-17 16:15:02 +08:00
|
|
|
|
from typing import List, Dict, Any, Optional
|
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-17 16:15:02 +08:00
|
|
|
|
content_id: Optional[int] = Field(None, description="内容ID")
|
|
|
|
|
|
product_id: Optional[int] = Field(None, description="产品ID")
|
|
|
|
|
|
scenic_spot_id: Optional[int] = Field(None, description="景区ID")
|
|
|
|
|
|
image_ids: Optional[List[int]] = Field(None, description="图像ID列表")
|
|
|
|
|
|
generate_collage: bool = Field(False, description="是否生成拼图")
|
2025-07-10 17:51:37 +08:00
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
schema_extra = {
|
|
|
|
|
|
"example": {
|
2025-07-17 16:15:02 +08:00
|
|
|
|
"content_id": 1,
|
|
|
|
|
|
"product_id": 2,
|
|
|
|
|
|
"scenic_spot_id": 3,
|
|
|
|
|
|
"image_ids": [1, 2, 3],
|
|
|
|
|
|
"generate_collage": True
|
2025-07-10 17:51:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-17 16:15:02 +08:00
|
|
|
|
class ImageUsageInfo(BaseModel):
|
|
|
|
|
|
"""图像使用信息模型 - 重点追踪图片使用情况"""
|
|
|
|
|
|
image_id: int = Field(..., description="图像ID")
|
|
|
|
|
|
usage_count: int = Field(..., description="使用次数")
|
|
|
|
|
|
first_used_at: str = Field(..., description="首次使用时间")
|
|
|
|
|
|
last_used_at: str = Field(..., description="最后使用时间")
|
|
|
|
|
|
usage_context: List[str] = Field(default_factory=list, description="使用场景列表")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PosterGenerateResponse(BaseModel):
|
2025-07-10 17:51:37 +08:00
|
|
|
|
"""海报生成响应模型"""
|
|
|
|
|
|
request_id: str = Field(..., description="请求ID")
|
2025-07-17 16:15:02 +08:00
|
|
|
|
poster_base64: str = Field(..., description="海报图像的base64编码")
|
|
|
|
|
|
content_info: Optional[Dict[str, Any]] = Field(None, description="内容信息")
|
|
|
|
|
|
product_info: Optional[Dict[str, Any]] = Field(None, description="产品信息")
|
|
|
|
|
|
scenic_spot_info: Optional[Dict[str, Any]] = Field(None, description="景区信息")
|
|
|
|
|
|
used_image_ids: List[int] = Field(default_factory=list, description="使用的图像ID列表")
|
|
|
|
|
|
image_usage_info: List[ImageUsageInfo] = Field(default_factory=list, description="图像使用详情")
|
|
|
|
|
|
collage_base64: Optional[str] = Field(None, description="拼图的base64编码")
|
|
|
|
|
|
metadata: Dict[str, Any] = Field(default_factory=dict, description="处理元数据")
|
2025-07-10 17:51:37 +08:00
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
schema_extra = {
|
|
|
|
|
|
"example": {
|
2025-07-14 13:59:22 +08:00
|
|
|
|
"request_id": "poster-20240715-123456-a1b2c3d4",
|
2025-07-17 16:15:02 +08:00
|
|
|
|
"poster_base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
|
|
|
|
|
|
"content_info": {
|
|
|
|
|
|
"id": 1,
|
|
|
|
|
|
"title": "【北京故宫】避开人潮的秘密路线",
|
|
|
|
|
|
"content": "故宫,作为中国最著名的文化遗产之一...",
|
|
|
|
|
|
"tag": "北京旅游,故宫,旅游攻略"
|
|
|
|
|
|
},
|
|
|
|
|
|
"used_image_ids": [1, 2, 3],
|
|
|
|
|
|
"image_usage_info": [
|
|
|
|
|
|
{
|
|
|
|
|
|
"image_id": 1,
|
|
|
|
|
|
"usage_count": 5,
|
|
|
|
|
|
"first_used_at": "2024-07-15 10:30:00",
|
|
|
|
|
|
"last_used_at": "2024-07-15 10:30:00",
|
|
|
|
|
|
"usage_context": ["poster_generation", "collage_creation"]
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
"collage_base64": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...",
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
"total_images_used": 3,
|
|
|
|
|
|
"has_collage": True,
|
|
|
|
|
|
"processing_time": "2.5s"
|
|
|
|
|
|
}
|
2025-07-10 17:51:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-17 16:15:02 +08:00
|
|
|
|
class ImageUsageRequest(BaseModel):
|
|
|
|
|
|
"""图像使用查询请求模型"""
|
|
|
|
|
|
image_ids: List[int] = Field(..., description="要查询的图像ID列表")
|
2025-07-10 17:51:37 +08:00
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
schema_extra = {
|
|
|
|
|
|
"example": {
|
2025-07-17 16:15:02 +08:00
|
|
|
|
"image_ids": [1, 2, 3, 4, 5]
|
2025-07-10 17:51:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-17 16:15:02 +08:00
|
|
|
|
class ImageUsageResponse(BaseModel):
|
|
|
|
|
|
"""图像使用情况响应模型"""
|
2025-07-10 17:51:37 +08:00
|
|
|
|
request_id: str = Field(..., description="请求ID")
|
2025-07-17 16:15:02 +08:00
|
|
|
|
image_usage_info: List[ImageUsageInfo] = Field(..., description="图像使用详情")
|
|
|
|
|
|
summary: Dict[str, Any] = Field(..., description="使用情况汇总")
|
2025-07-10 17:51:37 +08:00
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
schema_extra = {
|
|
|
|
|
|
"example": {
|
2025-07-17 16:15:02 +08:00
|
|
|
|
"request_id": "usage-20240715-123456-a1b2c3d4",
|
|
|
|
|
|
"image_usage_info": [
|
|
|
|
|
|
{
|
|
|
|
|
|
"image_id": 1,
|
|
|
|
|
|
"usage_count": 5,
|
|
|
|
|
|
"first_used_at": "2024-07-15 10:30:00",
|
|
|
|
|
|
"last_used_at": "2024-07-15 10:30:00",
|
|
|
|
|
|
"usage_context": ["poster_generation", "collage_creation"]
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
"summary": {
|
|
|
|
|
|
"total_images": 5,
|
|
|
|
|
|
"total_usage_count": 15,
|
|
|
|
|
|
"most_used_image_id": 1,
|
|
|
|
|
|
"least_used_image_id": 5
|
2025-07-10 17:51:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|