mirror of https://github.com/langgenius/dify.git
fix: chat api in explore page reject blank conversation id (#29500)
This commit is contained in:
parent
a195b410d1
commit
281e9d4f51
|
|
@ -2,7 +2,7 @@ import logging
|
||||||
from typing import Any, Literal
|
from typing import Any, Literal
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, field_validator
|
||||||
from werkzeug.exceptions import InternalServerError, NotFound
|
from werkzeug.exceptions import InternalServerError, NotFound
|
||||||
|
|
||||||
import services
|
import services
|
||||||
|
|
@ -52,10 +52,24 @@ class ChatMessagePayload(BaseModel):
|
||||||
inputs: dict[str, Any]
|
inputs: dict[str, Any]
|
||||||
query: str
|
query: str
|
||||||
files: list[dict[str, Any]] | None = None
|
files: list[dict[str, Any]] | None = None
|
||||||
conversation_id: UUID | None = None
|
conversation_id: str | None = None
|
||||||
parent_message_id: UUID | None = None
|
parent_message_id: str | None = None
|
||||||
retriever_from: str = Field(default="explore_app")
|
retriever_from: str = Field(default="explore_app")
|
||||||
|
|
||||||
|
@field_validator("conversation_id", "parent_message_id", mode="before")
|
||||||
|
@classmethod
|
||||||
|
def normalize_uuid(cls, value: str | UUID | None) -> str | None:
|
||||||
|
"""
|
||||||
|
Accept blank IDs and validate UUID format when provided.
|
||||||
|
"""
|
||||||
|
if not value:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
return helper.uuid_value(value)
|
||||||
|
except ValueError as exc:
|
||||||
|
raise ValueError("must be a valid UUID") from exc
|
||||||
|
|
||||||
|
|
||||||
register_schema_models(console_ns, CompletionMessagePayload, ChatMessagePayload)
|
register_schema_models(console_ns, CompletionMessagePayload, ChatMessagePayload)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue