AI CHAT对话降序获取升序输出,追加历史记录接口生成记录模块
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from typing import Annotated, Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from app.schemas.common import NaiveDatetimeOptional
|
||||
@@ -157,6 +159,7 @@ class GenerationAITaskOut(BaseModel):
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"id": "0019e0a44895b6d837d",
|
||||
"source_type": "chat_task",
|
||||
"project_id": None,
|
||||
"gen_type": "image",
|
||||
"generation_mode": "chatapi_async",
|
||||
@@ -204,6 +207,10 @@ class GenerationAITaskOut(BaseModel):
|
||||
)
|
||||
|
||||
id: str = Field(..., description="生成任务ID")
|
||||
source_type: Literal["chat_task"] = Field(
|
||||
"chat_task",
|
||||
description="历史记录来源。ChatGenerationTask 新任务历史固定为 chat_task",
|
||||
)
|
||||
project_id: str | None = Field(
|
||||
None,
|
||||
description="项目ID。当前 /generation-ai 任务不绑定项目,通常为 null",
|
||||
@@ -274,6 +281,7 @@ class GenerationAITaskListOut(BaseModel):
|
||||
"items": [
|
||||
{
|
||||
"id": "0019e0a44895b6d837d",
|
||||
"source_type": "chat_task",
|
||||
"project_id": None,
|
||||
"gen_type": "image",
|
||||
"generation_mode": "chatapi_async",
|
||||
@@ -338,6 +346,124 @@ class GenerationAIRetryOut(BaseModel):
|
||||
message: str = Field(..., description="操作结果提示信息")
|
||||
|
||||
|
||||
class GenerationAIRecordHistoryItemOut(BaseModel):
|
||||
"""旧 generation_records 历史记录详情响应体。"""
|
||||
|
||||
model_config = ConfigDict(
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"id": "0019e0a44895b6d837d",
|
||||
"source_type": "generation_record",
|
||||
"project_id": "project_xxx",
|
||||
"project_name": "默认项目",
|
||||
"gen_type": "image",
|
||||
"generation_mode": "generation_record",
|
||||
"pipeline_stage": None,
|
||||
"status": "completed",
|
||||
"original_prompt": "生成一张赛博朋克风格的城市夜景",
|
||||
"optimized_prompt": "赛博朋克城市夜景,霓虹灯,电影感,高细节",
|
||||
"duration": None,
|
||||
"aspect_ratio": None,
|
||||
"resolution": None,
|
||||
"image_size": "2K",
|
||||
"image_proportion": "1:1",
|
||||
"image_px": "2048x2048",
|
||||
"references": None,
|
||||
"media_references": None,
|
||||
"provider_task_id": "provider_task_xxx",
|
||||
"seedance_task_id": "provider_task_xxx",
|
||||
"remote_result_url": None,
|
||||
"image_url": "https://example.com/result.png",
|
||||
"video_url": None,
|
||||
"engine_id": None,
|
||||
"engine_snapshot": None,
|
||||
"credits_cost": 10.0,
|
||||
"text_credits_cost": 1.0,
|
||||
"text_tokens_used": 100,
|
||||
"image_tokens_used": 0,
|
||||
"video_tokens_used": 0,
|
||||
"retry_count": 0,
|
||||
"poll_count": 0,
|
||||
"error_message": None,
|
||||
"created_at": "2026-05-27T10:12:00",
|
||||
"generated_at": "2026-05-27T10:15:30",
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
id: str = Field(..., description="旧生成记录ID")
|
||||
source_type: Literal["generation_record"] = Field(
|
||||
"generation_record",
|
||||
description="历史记录来源固定为 generation_record,用于和 chat_task 历史区分",
|
||||
)
|
||||
project_id: str | None = Field(None, description="旧项目ID,来源于 generation_records.project_id")
|
||||
project_name: str | None = Field(None, description="旧项目名称,来源于 projects.name;项目不存在时为空")
|
||||
gen_type: str = Field(..., description="生成类型:image=图片,video=视频")
|
||||
generation_mode: str | None = Field(
|
||||
"generation_record",
|
||||
description="兼容新历史结构的生成模式字段。旧表历史固定返回 generation_record",
|
||||
)
|
||||
pipeline_stage: str | None = Field(
|
||||
None,
|
||||
description="兼容新历史结构的流水线阶段字段。旧 generation_records 无该字段,固定为 null",
|
||||
)
|
||||
status: str = Field(..., description="记录状态,例如 completed=已完成,failed=失败")
|
||||
original_prompt: str = Field(..., description="用户原始提示词")
|
||||
optimized_prompt: str | None = Field(None, description="优化后的提示词,可能为空")
|
||||
duration: int | None = Field(None, description="视频时长,单位秒。图片记录通常为空")
|
||||
aspect_ratio: str | None = Field(None, description="视频比例,例如 16:9。图片记录通常为空")
|
||||
resolution: str | None = Field(None, description="视频分辨率,例如 480p。图片记录通常为空")
|
||||
image_size: str | None = Field(None, description="图片分辨率档位,例如 2K")
|
||||
image_proportion: str | None = Field(None, description="图片比例,例如 1:1")
|
||||
image_px: str | None = Field(None, description="图片像素尺寸,例如 2048x2048")
|
||||
references: list[dict] | None = Field(
|
||||
None,
|
||||
description="旧接口字段名,来源于 generation_records.media_references 解析后的参考素材列表",
|
||||
)
|
||||
media_references: list[dict] | None = Field(
|
||||
None,
|
||||
description="兼容新历史结构字段名,和 references 内容一致",
|
||||
)
|
||||
provider_task_id: str | None = Field(None, description="第三方服务商任务ID,旧表使用 seedance_task_id 兼容填充")
|
||||
seedance_task_id: str | None = Field(None, description="旧服务命名的第三方任务ID字段")
|
||||
remote_result_url: str | None = Field(
|
||||
None,
|
||||
description="第三方远程结果地址。旧 generation_records 未保存该字段,固定为 null",
|
||||
)
|
||||
image_url: str | None = Field(None, description="最终图片地址。图片记录完成后通常有值")
|
||||
video_url: str | None = Field(None, description="最终视频地址。视频记录完成后通常有值")
|
||||
engine_id: str | None = Field(
|
||||
None,
|
||||
description="兼容新历史结构的引擎ID字段。旧 generation_records 未保存该字段,固定为 null",
|
||||
)
|
||||
engine_snapshot: dict | None = Field(
|
||||
None,
|
||||
description="兼容新历史结构的引擎快照字段。旧 generation_records 未保存该字段,固定为 null",
|
||||
)
|
||||
credits_cost: float = Field(0.0, description="本次记录总消耗积分")
|
||||
text_credits_cost: float = Field(0.0, description="文本优化或文本处理消耗积分")
|
||||
text_tokens_used: int = Field(0, description="文本 token 使用量")
|
||||
image_tokens_used: int = Field(0, description="图片 token 使用量")
|
||||
video_tokens_used: int = Field(0, description="视频 token 使用量")
|
||||
retry_count: int = Field(
|
||||
0,
|
||||
description="兼容新历史结构的重试次数字段。旧 generation_records 未保存该字段,固定为 0",
|
||||
)
|
||||
poll_count: int = Field(
|
||||
0,
|
||||
description="兼容新历史结构的轮询次数字段。旧 generation_records 未保存该字段,固定为 0",
|
||||
)
|
||||
error_message: str | None = Field(None, description="错误信息。成功记录一般为 null")
|
||||
created_at: NaiveDatetimeOptional = Field(None, description="记录创建时间")
|
||||
generated_at: NaiveDatetimeOptional = Field(None, description="生成完成时间")
|
||||
|
||||
|
||||
GenerationAIHistoryItemOut = Annotated[
|
||||
GenerationAITaskOut | GenerationAIRecordHistoryItemOut,
|
||||
Field(discriminator="source_type"),
|
||||
]
|
||||
|
||||
|
||||
class GenerationAIHistoryDayGroupOut(BaseModel):
|
||||
"""AI生成历史按天分组响应项。"""
|
||||
|
||||
@@ -353,9 +479,13 @@ class GenerationAIHistoryDayGroupOut(BaseModel):
|
||||
|
||||
generated_date: str = Field(..., description="生成日期,格式:YYYY-MM-DD")
|
||||
total: int = Field(..., description="当前生成日期下的生成成功记录总数")
|
||||
items: list[GenerationAITaskOut] = Field(
|
||||
items: list[GenerationAIHistoryItemOut] = Field(
|
||||
default_factory=list,
|
||||
description="当前生成日期下倒序前10条生成记录详情",
|
||||
description=(
|
||||
"当前生成日期下倒序前10条生成记录详情。"
|
||||
"默认 history_source=chat_task 时 item 为 GenerationAITaskOut;"
|
||||
"history_source=generation_record 时 item 为 GenerationAIRecordHistoryItemOut"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -412,7 +542,11 @@ class GenerationAIHistoryDayItemsOut(BaseModel):
|
||||
total: int = Field(..., description="当前日期下的生成成功记录总数")
|
||||
page: int = Field(..., description="当前日期下的记录分页页码")
|
||||
page_size: int = Field(..., description="当前日期下每页返回的生成记录数量")
|
||||
items: list[GenerationAITaskOut] = Field(
|
||||
items: list[GenerationAIHistoryItemOut] = Field(
|
||||
default_factory=list,
|
||||
description="当前日期下的生成记录详情列表,按 generated_at 倒序排列",
|
||||
description=(
|
||||
"当前日期下的生成记录详情列表,按 generated_at 倒序排列。"
|
||||
"默认 history_source=chat_task 时 item 为 GenerationAITaskOut;"
|
||||
"history_source=generation_record 时 item 为 GenerationAIRecordHistoryItemOut"
|
||||
),
|
||||
)
|
||||
Reference in New Issue
Block a user