This commit is contained in:
2025-08-25 15:36:15 +08:00
parent 1d9e1896ce
commit b68431828c
3 changed files with 869 additions and 696 deletions

View File

@@ -13,7 +13,7 @@ from Config import Config
import asyncio import asyncio
import threading import threading
from fastapi.responses import StreamingResponse from fastapi.responses import StreamingResponse
from fastapi import APIRouter, Request, HTTPException, BackgroundTasks
# 创建路由路由器 # 创建路由路由器
router = APIRouter(prefix="/api/mj", tags=["文生图"]) router = APIRouter(prefix="/api/mj", tags=["文生图"])
@@ -144,24 +144,21 @@ async def submit_imagine(request: ImagineRequest, background_tasks: BackgroundTa
raise HTTPException(status_code=500, detail=f"提交文生图请求失败: {str(e)}") raise HTTPException(status_code=500, detail=f"提交文生图请求失败: {str(e)}")
@router.get("/task_status", response_model=TaskStatusResponse) # 在文件顶部确保已定义任务状态缓存
async def get_task_status(task_id: str = Query(..., description="任务ID")): task_status_cache = {}
""" @router.get("/task_status")
查询文生图任务状态 async def get_task_status(task_id: str):
if not task_id:
raise HTTPException(status_code=400, detail="task_id 参数缺失")
Args: # 将所有 task_status_store 替换为 task_status_cache
task_id: 任务ID if task_id not in task_status_cache:
Returns:
任务状态信息
"""
if task_id not in TASK_STATUS:
raise HTTPException(status_code=404, detail="任务ID不存在") raise HTTPException(status_code=404, detail="任务ID不存在")
return TaskStatusResponse( return {
task_id=task_id, "task_id": task_id,
status=TASK_STATUS[task_id]["status"], "status": task_status_cache[task_id]["status"],
image_url=TASK_STATUS[task_id]["image_url"], "progress": task_status_cache[task_id]["progress"] ,
progress=TASK_STATUS[task_id]["progress"], "result": task_status_cache[task_id]["result"],
error=TASK_STATUS[task_id]["error"] "error": task_status_cache[task_id]["error"]
) }

File diff suppressed because it is too large Load Diff