diff --git a/apps/entities/enum_var.py b/apps/entities/enum_var.py index 3d19ab98698776f0ddba27a976ae9814197a98ec..281d53e07d3ecf9756bf7bf01ce28b1fad6a21b2 100644 --- a/apps/entities/enum_var.py +++ b/apps/entities/enum_var.py @@ -147,3 +147,11 @@ class SpecialCallType(str, Enum): START = "start" END = "end" CHOICE = "choice" + + +class CommentType(str, Enum): + """点赞点踩类型""" + + LIKE = "liked" + DISLIKE = "disliked" + NONE = "none" diff --git a/apps/entities/record.py b/apps/entities/record.py index 58ba869a91ae1ae0d6e9503c87037cc4f45f3810..6322cb106bc6d18bc92e4145d5c9d86b8f6c221e 100644 --- a/apps/entities/record.py +++ b/apps/entities/record.py @@ -13,7 +13,7 @@ from pydantic import BaseModel, Field from apps.entities.collection import ( Document, ) -from apps.entities.enum_var import StepStatus +from apps.entities.enum_var import StepStatus, CommentType class RecordDocument(Document): @@ -65,6 +65,15 @@ class RecordMetadata(BaseModel): time_cost: float = Field(default=0, alias="timeCost") feature: dict[str, Any] = {} +class RecordComment(BaseModel): + """Record表子项:Record的评论信息""" + + comment: CommentType = Field(default=CommentType.NONE) + feedback_type: list[str] = Field(default=[], alias="dislike_reason") + feedback_link: str = Field(default="", alias="reason_link") + feedback_content: str = Field(default="", alias="reason_description") + feedback_time: float = Field(default_factory=lambda: round(datetime.now(tz=UTC).timestamp(), 3)) + class RecordData(BaseModel): """GET /api/record/{conversation_id} Result内元素数据结构""" @@ -77,6 +86,7 @@ class RecordData(BaseModel): flow: RecordFlow | None = None content: RecordContent metadata: RecordMetadata + comment: RecordComment created_at: float = Field(alias="createdAt") @@ -87,16 +97,6 @@ class RecordGroupDocument(BaseModel): associated: Literal["question", "answer"] -class RecordComment(BaseModel): - """Record表子项:Record的评论信息""" - - is_liked: bool - feedback_type: list[str] - feedback_link: str - feedback_content: str - feedback_time: float = Field(default_factory=lambda: round(datetime.now(tz=UTC).timestamp(), 3)) - - class Record(RecordData): """问答,用于保存在MongoDB中""" diff --git a/apps/entities/request_data.py b/apps/entities/request_data.py index fdc8b710ffe62b94c2251c498b738290d1cf3b9d..ec5a9b03cf7541346951fd9453106c56058dd5c8 100644 --- a/apps/entities/request_data.py +++ b/apps/entities/request_data.py @@ -9,6 +9,7 @@ from typing import Any from pydantic import BaseModel, Field from apps.common.config import Config +from apps.entities.enum_var import CommentType from apps.entities.appcenter import AppData from apps.entities.flow_topology import FlowItem @@ -26,7 +27,7 @@ class MockRequestData(BaseModel): app_id: str = Field(default="", description="应用ID", alias="appId") flow_id: str = Field(default="", description="流程ID", alias="flowId") - conversation_id : str = Field(..., description="会话ID", alias="conversationId") + conversation_id: str = Field(..., description="会话ID", alias="conversationId") question: str = Field(..., description="问题", alias="question") @@ -128,7 +129,7 @@ class AddCommentData(BaseModel): record_id: str group_id: str - is_like: bool = Field(...) + comment: CommentType dislike_reason: list[str] = Field(default=[], max_length=10) reason_link: str = Field(default="", max_length=200) reason_description: str = Field(default="", max_length=500) diff --git a/apps/routers/comment.py b/apps/routers/comment.py index b75bedb24c5bc698e255cce1bf934aa382f1dd3a..ccaada8b1409b2b768df8c466218c3ba007e4b4c 100644 --- a/apps/routers/comment.py +++ b/apps/routers/comment.py @@ -40,7 +40,7 @@ async def add_comment(post_body: AddCommentData, user_sub: Annotated[str, Depend ).model_dump(exclude_none=True, by_alias=True)) comment_data = RecordComment( - is_liked=post_body.is_like, + comment=post_body.comment, feedback_type=post_body.dislike_reason, feedback_link=post_body.reason_link, feedback_content=post_body.reason_description, diff --git a/apps/routers/record.py b/apps/routers/record.py index 8b6c8d06af9e8eb527f4b4f058fdb6636d5943ad..e3554b77fbf13b3aebee5742bca7e91bb8240a54 100644 --- a/apps/routers/record.py +++ b/apps/routers/record.py @@ -77,6 +77,7 @@ async def get_record(conversation_id: str, user_sub: Annotated[str, Depends(get_ outputTokens=0, timeCost=0, ), + comment=record.comment, createdAt=record.created_at, )