mirror of
https://github.com/langgenius/dify.git
synced 2026-08-28 21:23:22 +08:00
refactor: split changes for api/controllers/web/workflow.py (#29852)
This commit is contained in:
parent
5dc5709d58
commit
6342d196e8
@ -1,8 +1,10 @@
|
|||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from flask_restx import reqparse
|
from pydantic import BaseModel, Field
|
||||||
from werkzeug.exceptions import InternalServerError
|
from werkzeug.exceptions import InternalServerError
|
||||||
|
|
||||||
|
from controllers.common.schema import register_schema_models
|
||||||
from controllers.web import web_ns
|
from controllers.web import web_ns
|
||||||
from controllers.web.error import (
|
from controllers.web.error import (
|
||||||
CompletionRequestError,
|
CompletionRequestError,
|
||||||
@ -27,19 +29,22 @@ from models.model import App, AppMode, EndUser
|
|||||||
from services.app_generate_service import AppGenerateService
|
from services.app_generate_service import AppGenerateService
|
||||||
from services.errors.llm import InvokeRateLimitError
|
from services.errors.llm import InvokeRateLimitError
|
||||||
|
|
||||||
|
|
||||||
|
class WorkflowRunPayload(BaseModel):
|
||||||
|
inputs: dict[str, Any] = Field(description="Input variables for the workflow")
|
||||||
|
files: list[dict[str, Any]] | None = Field(default=None, description="Files to be processed by the workflow")
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
register_schema_models(web_ns, WorkflowRunPayload)
|
||||||
|
|
||||||
|
|
||||||
@web_ns.route("/workflows/run")
|
@web_ns.route("/workflows/run")
|
||||||
class WorkflowRunApi(WebApiResource):
|
class WorkflowRunApi(WebApiResource):
|
||||||
@web_ns.doc("Run Workflow")
|
@web_ns.doc("Run Workflow")
|
||||||
@web_ns.doc(description="Execute a workflow with provided inputs and files.")
|
@web_ns.doc(description="Execute a workflow with provided inputs and files.")
|
||||||
@web_ns.doc(
|
@web_ns.expect(web_ns.models[WorkflowRunPayload.__name__])
|
||||||
params={
|
|
||||||
"inputs": {"description": "Input variables for the workflow", "type": "object", "required": True},
|
|
||||||
"files": {"description": "Files to be processed by the workflow", "type": "array", "required": False},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@web_ns.doc(
|
@web_ns.doc(
|
||||||
responses={
|
responses={
|
||||||
200: "Success",
|
200: "Success",
|
||||||
@ -58,12 +63,8 @@ class WorkflowRunApi(WebApiResource):
|
|||||||
if app_mode != AppMode.WORKFLOW:
|
if app_mode != AppMode.WORKFLOW:
|
||||||
raise NotWorkflowAppError()
|
raise NotWorkflowAppError()
|
||||||
|
|
||||||
parser = (
|
payload = WorkflowRunPayload.model_validate(web_ns.payload or {})
|
||||||
reqparse.RequestParser()
|
args = payload.model_dump(exclude_none=True)
|
||||||
.add_argument("inputs", type=dict, required=True, nullable=False, location="json")
|
|
||||||
.add_argument("files", type=list, required=False, location="json")
|
|
||||||
)
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = AppGenerateService.generate(
|
response = AppGenerateService.generate(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user