mirror of
https://github.com/langgenius/dify.git
synced 2026-09-24 23:22:26 +08:00
refactor: fix OpenAPI contract generation schemas (#37387)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
autofix-ci[bot]
parent
7cf75c3cc5
commit
5d77c0af08
@@ -5,7 +5,7 @@ from pydantic import BaseModel, Field, field_validator
|
||||
from werkzeug.exceptions import BadRequest, InternalServerError, NotFound
|
||||
|
||||
import services
|
||||
from controllers.common.fields import SimpleResultResponse
|
||||
from controllers.common.fields import GeneratedAppResponse, SimpleResultResponse
|
||||
from controllers.common.schema import register_response_schema_models, register_schema_models
|
||||
from controllers.web import web_ns
|
||||
from controllers.web.error import (
|
||||
@@ -47,9 +47,14 @@ def _resolve_agent_app_streaming(*, app_mode: AppMode, response_mode: str | None
|
||||
|
||||
|
||||
class CompletionMessagePayload(BaseModel):
|
||||
inputs: dict[str, Any] = Field(description="Input variables for the completion")
|
||||
inputs: dict[str, Any] = Field(
|
||||
description="Input variables for the completion",
|
||||
)
|
||||
query: str = Field(default="", description="Query text for completion")
|
||||
files: list[dict[str, Any]] | None = Field(default=None, description="Files to be processed")
|
||||
files: list[dict[str, Any]] | None = Field(
|
||||
default=None,
|
||||
description="Files to be processed",
|
||||
)
|
||||
response_mode: Literal["blocking", "streaming"] | None = Field(
|
||||
default=None, description="Response mode: blocking or streaming"
|
||||
)
|
||||
@@ -57,9 +62,14 @@ class CompletionMessagePayload(BaseModel):
|
||||
|
||||
|
||||
class ChatMessagePayload(BaseModel):
|
||||
inputs: dict[str, Any] = Field(description="Input variables for the chat")
|
||||
inputs: dict[str, Any] = Field(
|
||||
description="Input variables for the chat",
|
||||
)
|
||||
query: str = Field(description="User query/message")
|
||||
files: list[dict[str, Any]] | None = Field(default=None, description="Files to be processed")
|
||||
files: list[dict[str, Any]] | None = Field(
|
||||
default=None,
|
||||
description="Files to be processed",
|
||||
)
|
||||
response_mode: Literal["blocking", "streaming"] | None = Field(
|
||||
default=None, description="Response mode: blocking or streaming"
|
||||
)
|
||||
@@ -76,7 +86,7 @@ class ChatMessagePayload(BaseModel):
|
||||
|
||||
|
||||
register_schema_models(web_ns, CompletionMessagePayload, ChatMessagePayload)
|
||||
register_response_schema_models(web_ns, SimpleResultResponse)
|
||||
register_response_schema_models(web_ns, GeneratedAppResponse, SimpleResultResponse)
|
||||
|
||||
|
||||
# define completion api for user
|
||||
@@ -95,6 +105,7 @@ class CompletionApi(WebApiResource):
|
||||
500: "Internal Server Error",
|
||||
}
|
||||
)
|
||||
@web_ns.response(200, "Success", web_ns.models[GeneratedAppResponse.__name__])
|
||||
def post(self, app_model: App, end_user: EndUser):
|
||||
if app_model.mode != AppMode.COMPLETION:
|
||||
raise NotCompletionAppError()
|
||||
@@ -178,6 +189,7 @@ class ChatApi(WebApiResource):
|
||||
500: "Internal Server Error",
|
||||
}
|
||||
)
|
||||
@web_ns.response(200, "Success", web_ns.models[GeneratedAppResponse.__name__])
|
||||
def post(self, app_model: App, end_user: EndUser):
|
||||
app_mode = AppMode.value_of(app_model.mode)
|
||||
if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT, AppMode.AGENT}:
|
||||
|
||||
Reference in New Issue
Block a user