46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
from datetime import UTC, datetime
|
|
|
|
from app.models.entities import Conversation, ConversationMessage
|
|
from app.services.conversations import ConversationService
|
|
|
|
|
|
def test_history_context_does_not_duplicate_current_user_message() -> None:
|
|
current_text = "继续分析这个产品的供应商风险"
|
|
conversation = Conversation(
|
|
id=1,
|
|
user_id=1,
|
|
title="产品风险",
|
|
created_at=datetime.now(UTC),
|
|
updated_at=datetime.now(UTC),
|
|
messages=[
|
|
ConversationMessage(
|
|
id=1,
|
|
conversation_id=1,
|
|
role="user",
|
|
content="评估一款软管新品",
|
|
created_at=datetime.now(UTC),
|
|
),
|
|
ConversationMessage(
|
|
id=2,
|
|
conversation_id=1,
|
|
role="assistant",
|
|
content="已识别为软管新品风险评估。",
|
|
created_at=datetime.now(UTC),
|
|
),
|
|
ConversationMessage(
|
|
id=3,
|
|
conversation_id=1,
|
|
role="user",
|
|
content=current_text,
|
|
created_at=datetime.now(UTC),
|
|
),
|
|
],
|
|
)
|
|
|
|
history = ConversationService._history_messages(conversation, current_text=current_text)
|
|
|
|
assert [item["content"] for item in history] == [
|
|
"评估一款软管新品",
|
|
"已识别为软管新品风险评估。",
|
|
]
|