mirror of
https://github.com/langgenius/dify.git
synced 2026-05-08 09:00:22 -04:00
refactor: port MessageAnnotation (#31005)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1867,15 +1867,18 @@ class MessageAnnotation(TypeBase):
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(
|
||||
StringUUID, insert_default=lambda: str(uuid4()), default_factory=lambda: str(uuid4()), init=False
|
||||
StringUUID,
|
||||
insert_default=lambda: str(uuid4()),
|
||||
default_factory=lambda: str(uuid4()),
|
||||
init=False,
|
||||
)
|
||||
app_id: Mapped[str] = mapped_column(StringUUID)
|
||||
question: Mapped[str] = mapped_column(LongText, nullable=False)
|
||||
content: Mapped[str] = mapped_column(LongText, nullable=False)
|
||||
hit_count: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default=sa.text("0"), init=False)
|
||||
account_id: Mapped[str] = mapped_column(StringUUID, nullable=False)
|
||||
conversation_id: Mapped[str | None] = mapped_column(StringUUID, sa.ForeignKey("conversations.id"), default=None)
|
||||
message_id: Mapped[str | None] = mapped_column(StringUUID, default=None)
|
||||
hit_count: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default=sa.text("0"), default=0)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
sa.DateTime, nullable=False, server_default=func.current_timestamp(), init=False
|
||||
)
|
||||
|
||||
@@ -133,7 +133,14 @@ class AppAnnotationService:
|
||||
raise ValueError("'question' is required when 'message_id' is not provided")
|
||||
question = maybe_question
|
||||
|
||||
annotation = MessageAnnotation(app_id=app.id, content=answer, question=question, account_id=current_user.id)
|
||||
annotation = MessageAnnotation(
|
||||
app_id=app.id,
|
||||
conversation_id=None,
|
||||
message_id=None,
|
||||
content=answer,
|
||||
question=question,
|
||||
account_id=current_user.id,
|
||||
)
|
||||
db.session.add(annotation)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@@ -711,6 +711,8 @@ class TestMessageAnnotation:
|
||||
annotation = MessageAnnotation(
|
||||
app_id=app_id,
|
||||
question="What is AI?",
|
||||
conversation_id=None,
|
||||
message_id=None,
|
||||
content="AI stands for Artificial Intelligence.",
|
||||
account_id=account_id,
|
||||
)
|
||||
@@ -728,6 +730,8 @@ class TestMessageAnnotation:
|
||||
annotation = MessageAnnotation(
|
||||
app_id=str(uuid4()),
|
||||
question="Test question",
|
||||
conversation_id=None,
|
||||
message_id=None,
|
||||
content="Test content",
|
||||
account_id=str(uuid4()),
|
||||
)
|
||||
@@ -1068,6 +1072,8 @@ class TestModelIntegration:
|
||||
app_id=app_id,
|
||||
question="What is AI?",
|
||||
content="AI stands for Artificial Intelligence.",
|
||||
conversation_id=None,
|
||||
message_id=message_id,
|
||||
account_id=account_id,
|
||||
)
|
||||
annotation.id = annotation_id
|
||||
|
||||
@@ -238,6 +238,8 @@ class TestAppAnnotationServiceUpInsert:
|
||||
assert result == annotation_instance
|
||||
mock_cls.assert_called_once_with(
|
||||
app_id=app.id,
|
||||
conversation_id=None,
|
||||
message_id=None,
|
||||
content="hello",
|
||||
question="q1",
|
||||
account_id=current_user.id,
|
||||
|
||||
Reference in New Issue
Block a user