refactor: port MessageAnnotation (#31005)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Asuka Minato
2026-04-26 20:47:42 +09:00
committed by GitHub
parent 8b346e69d9
commit 7efc887e32
4 changed files with 21 additions and 3 deletions

View File

@@ -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
)

View File

@@ -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()

View File

@@ -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

View File

@@ -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,