From dd2b57507cf4b09bfb73cd2bb6e658954c4910cc Mon Sep 17 00:00:00 2001 From: Ismail Ashraq <issey1455@gmail.com> Date: Fri, 5 Jan 2024 03:13:53 +0500 Subject: [PATCH] update tests --- tests/unit/test_splitters.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/unit/test_splitters.py b/tests/unit/test_splitters.py index 5d1e0490..bcd8f62b 100644 --- a/tests/unit/test_splitters.py +++ b/tests/unit/test_splitters.py @@ -1,6 +1,7 @@ import pytest from unittest.mock import Mock from semantic_router.utils.splitters import semantic_splitter +from semantic_router.schema import Conversation, Message def test_semantic_splitter_consecutive_similarity_drop(): @@ -43,3 +44,23 @@ def test_semantic_splitter_invalid_method(): with pytest.raises(ValueError): semantic_splitter(mock_encoder, docs, threshold, split_method) + + +def test_split_by_topic(): + mock_encoder = Mock() + mock_encoder.return_value = [[0.5, 0], [0, 0.5]] + + messages = [ + Message(role="User", content="What is the latest news?"), + Message(role="Bot", content="How is the weather today?"), + ] + conversation = Conversation(messages=messages) + + result = conversation.split_by_topic( + encoder=mock_encoder, threshold=0.5, split_method="consecutive_similarity_drop" + ) + + assert result == { + "split 1": ["User: What is the latest news?"], + "split 2": ["Bot: How is the weather today?"], + } -- GitLab