'commit'
This commit is contained in:
@@ -13,7 +13,7 @@ from Config import Config
|
||||
import asyncio
|
||||
import threading
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from fastapi import APIRouter, Request, HTTPException, BackgroundTasks
|
||||
# 创建路由路由器
|
||||
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)}")
|
||||
|
||||
|
||||
@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_id: 任务ID
|
||||
|
||||
Returns:
|
||||
任务状态信息
|
||||
"""
|
||||
if task_id not in TASK_STATUS:
|
||||
# 将所有 task_status_store 替换为 task_status_cache
|
||||
if task_id not in task_status_cache:
|
||||
raise HTTPException(status_code=404, detail="任务ID不存在")
|
||||
|
||||
return TaskStatusResponse(
|
||||
task_id=task_id,
|
||||
status=TASK_STATUS[task_id]["status"],
|
||||
image_url=TASK_STATUS[task_id]["image_url"],
|
||||
progress=TASK_STATUS[task_id]["progress"],
|
||||
error=TASK_STATUS[task_id]["error"]
|
||||
)
|
||||
|
||||
return {
|
||||
"task_id": task_id,
|
||||
"status": task_status_cache[task_id]["status"],
|
||||
"progress": task_status_cache[task_id]["progress"] ,
|
||||
"result": task_status_cache[task_id]["result"],
|
||||
"error": task_status_cache[task_id]["error"]
|
||||
}
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user