From 862d48b0ce23573b3f901a16dfed63cc946bf111 Mon Sep 17 00:00:00 2001 From: iHeyTang Date: Wed, 13 Aug 2025 18:14:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0API=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=8F=82=E6=95=B0=E8=A7=A3=E6=9E=90=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8Body=E8=8E=B7=E5=8F=96=E8=AF=B7=E6=B1=82=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=EF=BC=8C=E7=AE=80=E5=8C=96=E8=AF=B7=E6=B1=82=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workflow_service/routes/run.py | 11 ++++++----- .../routes/runx/model_with_multi_dress.py | 5 ++--- workflow_service/routes/workflow.py | 5 ++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/workflow_service/routes/run.py b/workflow_service/routes/run.py index 7cdb91b..a2e4ef9 100644 --- a/workflow_service/routes/run.py +++ b/workflow_service/routes/run.py @@ -1,7 +1,8 @@ import json -from typing import Optional +from typing import Dict, Optional -from fastapi import APIRouter, HTTPException, Request +from fastapi import APIRouter, Body, HTTPException, Request +from fastapi.openapi.models import RequestBody from fastapi.responses import JSONResponse from workflow_service import comfyui_client, database @@ -14,15 +15,15 @@ run_router = APIRouter( @run_router.post("") async def run_workflow( - request: Request, workflow_name: str, workflow_version: Optional[str] = None + workflow_name: str, + workflow_version: Optional[str] = None, + data: Dict = Body(...), ): """ 异步执行工作流。 立即返回任务ID,调用者可以通过任务ID查询执行状态。 """ try: - data = await request.json() - if not workflow_name: raise HTTPException(status_code=400, detail="`workflow_name` 字段是必需的") diff --git a/workflow_service/routes/runx/model_with_multi_dress.py b/workflow_service/routes/runx/model_with_multi_dress.py index 485108d..8846d8d 100644 --- a/workflow_service/routes/runx/model_with_multi_dress.py +++ b/workflow_service/routes/runx/model_with_multi_dress.py @@ -1,7 +1,7 @@ import json from typing import Optional -from fastapi import Request, HTTPException +from fastapi import Body, HTTPException from fastapi.responses import JSONResponse from workflow_service import comfyui_client, database from ._base import runx_router @@ -12,7 +12,7 @@ RUNX_WORKFLOW_NAME = "测试" @runx_router.post(f"/{RUNX_NAME}") async def model_with_multi_dress( - request: Request, + data: dict = Body(...), workflow_version: Optional[str] = None, ): """ @@ -34,7 +34,6 @@ async def model_with_multi_dress( api_spec = comfyui_client.parse_api_spec(workflow) # 将请求拆分为多个请求 - data = await request.json() batch_data = _convert(data) # 提交到队列 diff --git a/workflow_service/routes/workflow.py b/workflow_service/routes/workflow.py index a19430c..6c3932d 100644 --- a/workflow_service/routes/workflow.py +++ b/workflow_service/routes/workflow.py @@ -1,7 +1,7 @@ import json from typing import Optional, List -from fastapi import APIRouter, Request, HTTPException, Path +from fastapi import APIRouter, Body, HTTPException, Path from fastapi.responses import JSONResponse from workflow_service import comfyui_client @@ -15,12 +15,11 @@ workflow_router = APIRouter( @workflow_router.post("", status_code=201) -async def publish_workflow_endpoint(request: Request): +async def publish_workflow_endpoint(data: dict = Body(...)): """ 发布工作流 """ try: - data = await request.json() name, wf_json = data.get("name"), data.get("workflow") if not name or not wf_json: raise HTTPException(