mirror of
https://github.com/langgenius/dify.git
synced 2026-05-01 06:06:35 +08:00
refactor(api): deduplicate Pydantic models across fields and controllers (#34718)
This commit is contained in:
parent
e138523123
commit
4d4265f531
@ -8,6 +8,7 @@ from pydantic import BaseModel, Field, field_validator
|
|||||||
from sqlalchemy import exists, func, select
|
from sqlalchemy import exists, func, select
|
||||||
from werkzeug.exceptions import InternalServerError, NotFound
|
from werkzeug.exceptions import InternalServerError, NotFound
|
||||||
|
|
||||||
|
from controllers.common.controller_schemas import MessageFeedbackPayload as _MessageFeedbackPayloadBase
|
||||||
from controllers.common.schema import register_schema_models
|
from controllers.common.schema import register_schema_models
|
||||||
from controllers.console import console_ns
|
from controllers.console import console_ns
|
||||||
from controllers.console.app.error import (
|
from controllers.console.app.error import (
|
||||||
@ -59,10 +60,8 @@ class ChatMessagesQuery(BaseModel):
|
|||||||
return uuid_value(value)
|
return uuid_value(value)
|
||||||
|
|
||||||
|
|
||||||
class MessageFeedbackPayload(BaseModel):
|
class MessageFeedbackPayload(_MessageFeedbackPayloadBase):
|
||||||
message_id: str = Field(..., description="Message ID")
|
message_id: str = Field(..., description="Message ID")
|
||||||
rating: Literal["like", "dislike"] | None = Field(default=None, description="Feedback rating")
|
|
||||||
content: str | None = Field(default=None, description="Feedback content")
|
|
||||||
|
|
||||||
@field_validator("message_id")
|
@field_validator("message_id")
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@ -80,7 +80,7 @@ class Feedback(ResponseModel):
|
|||||||
from_account: SimpleAccount | None = None
|
from_account: SimpleAccount | None = None
|
||||||
|
|
||||||
|
|
||||||
class Annotation(ResponseModel):
|
class ConversationAnnotation(ResponseModel):
|
||||||
id: str
|
id: str
|
||||||
question: str | None = None
|
question: str | None = None
|
||||||
content: str
|
content: str
|
||||||
@ -95,7 +95,7 @@ class Annotation(ResponseModel):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class AnnotationHitHistory(ResponseModel):
|
class ConversationAnnotationHitHistory(ResponseModel):
|
||||||
annotation_id: str
|
annotation_id: str
|
||||||
annotation_create_account: SimpleAccount | None = None
|
annotation_create_account: SimpleAccount | None = None
|
||||||
created_at: int | None = None
|
created_at: int | None = None
|
||||||
@ -151,8 +151,8 @@ class MessageDetail(ResponseModel):
|
|||||||
from_account_id: str | None = None
|
from_account_id: str | None = None
|
||||||
feedbacks: list[Feedback]
|
feedbacks: list[Feedback]
|
||||||
workflow_run_id: str | None = None
|
workflow_run_id: str | None = None
|
||||||
annotation: Annotation | None = None
|
annotation: ConversationAnnotation | None = None
|
||||||
annotation_hit_history: AnnotationHitHistory | None = None
|
annotation_hit_history: ConversationAnnotationHitHistory | None = None
|
||||||
created_at: int | None = None
|
created_at: int | None = None
|
||||||
agent_thoughts: list[AgentThought]
|
agent_thoughts: list[AgentThought]
|
||||||
message_files: list[MessageFile]
|
message_files: list[MessageFile]
|
||||||
@ -223,7 +223,7 @@ class Conversation(ResponseModel):
|
|||||||
read_at: int | None = None
|
read_at: int | None = None
|
||||||
created_at: int | None = None
|
created_at: int | None = None
|
||||||
updated_at: int | None = None
|
updated_at: int | None = None
|
||||||
annotation: Annotation | None = None
|
annotation: ConversationAnnotation | None = None
|
||||||
model_config_: SimpleModelConfig | None = Field(default=None, alias="model_config")
|
model_config_: SimpleModelConfig | None = Field(default=None, alias="model_config")
|
||||||
user_feedback_stats: FeedbackStat | None = None
|
user_feedback_stats: FeedbackStat | None = None
|
||||||
admin_feedback_stats: FeedbackStat | None = None
|
admin_feedback_stats: FeedbackStat | None = None
|
||||||
|
|||||||
@ -4,18 +4,15 @@ from datetime import datetime
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from graphon.file import File
|
from graphon.file import File
|
||||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
from pydantic import Field, field_validator
|
||||||
|
|
||||||
from core.entities.execution_extra_content import ExecutionExtraContentDomainModel
|
from core.entities.execution_extra_content import ExecutionExtraContentDomainModel
|
||||||
|
from fields.base import ResponseModel
|
||||||
from fields.conversation_fields import AgentThought, JSONValue, MessageFile
|
from fields.conversation_fields import AgentThought, JSONValue, MessageFile
|
||||||
|
|
||||||
type JSONValueType = JSONValue
|
type JSONValueType = JSONValue
|
||||||
|
|
||||||
|
|
||||||
class ResponseModel(BaseModel):
|
|
||||||
model_config = ConfigDict(from_attributes=True, extra="ignore")
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleFeedback(ResponseModel):
|
class SimpleFeedback(ResponseModel):
|
||||||
rating: str | None = None
|
rating: str | None = None
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user