From fa022a5757de1e96fe0e5e1abc2bf35dc77497e4 Mon Sep 17 00:00:00 2001 From: Siraj R Aizlewood <siraj@aurelio.ai> Date: Mon, 5 Feb 2024 16:52:59 +0400 Subject: [PATCH] Linting. --- docs/07-route-conversations-by-topic.ipynb | 22 +++++++++++----------- semantic_router/schema.py | 2 +- semantic_router/text.py | 9 +++++---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/docs/07-route-conversations-by-topic.ipynb b/docs/07-route-conversations-by-topic.ipynb index cf876353..9d2b5424 100644 --- a/docs/07-route-conversations-by-topic.ipynb +++ b/docs/07-route-conversations-by-topic.ipynb @@ -71,7 +71,9 @@ " Message(role=\"user\", content=\"Hi, my name is John Doe.\"),\n", " Message(role=\"bot\", content=\"Okay, how can I help you today?\"),\n", " Message(role=\"user\", content=\"My computer keeps crashing\"),\n", - " Message(role=\"bot\", content=\"Okay, is our software running when the computer crashes.\"),\n", + " Message(\n", + " role=\"bot\", content=\"Okay, is our software running when the computer crashes.\"\n", + " ),\n", " Message(role=\"user\", content=\"Yeah, v.3.11.2 is running when it crashes.\"),\n", "]\n", "\n", @@ -95,10 +97,10 @@ "from semantic_router.encoders.cohere import CohereEncoder\n", "\n", "cohere_encoder = CohereEncoder(\n", - " name=\"embed-english-v3.0\", \n", - " cohere_api_key='',\n", + " name=\"embed-english-v3.0\",\n", + " cohere_api_key=\"\",\n", " input_type=\"search_document\",\n", - " )" + ")" ] }, { @@ -134,9 +136,7 @@ ], "source": [ "conversation.configure_splitter(\n", - " encoder=cohere_encoder, \n", - " threshold=0.5, \n", - " split_method=\"cumulative_similarity\"\n", + " encoder=cohere_encoder, threshold=0.5, split_method=\"cumulative_similarity\"\n", ")\n", "\n", "all_topics, new_topics = conversation.split_by_topic()\n", @@ -191,7 +191,9 @@ "source": [ "# Define the IT support dialogue\n", "messages = [\n", - " Message(role=\"user\", content=\"What do the system logs say, right before the crash?\"),\n", + " Message(\n", + " role=\"user\", content=\"What do the system logs say, right before the crash?\"\n", + " ),\n", " Message(role=\"user\", content=\"I'll check soon, but first let's talk refund.\"),\n", " Message(role=\"bot\", content=\"Okay let me sort out a refund.\"),\n", "]\n", @@ -223,9 +225,7 @@ ], "source": [ "conversation.configure_splitter(\n", - " encoder=cohere_encoder, \n", - " threshold=0.5, \n", - " split_method=\"cumulative_similarity\"\n", + " encoder=cohere_encoder, threshold=0.5, split_method=\"cumulative_similarity\"\n", ")\n", "\n", "all_topics, new_topics = conversation.split_by_topic()\n", diff --git a/semantic_router/schema.py b/semantic_router/schema.py index 0c8376ce..46ee7f59 100644 --- a/semantic_router/schema.py +++ b/semantic_router/schema.py @@ -64,7 +64,7 @@ class Message(BaseModel): def to_llamacpp(self): return {"role": self.role, "content": self.content} - + def __str__(self): return f"{self.role}: {self.content}" diff --git a/semantic_router/text.py b/semantic_router/text.py index 17fbc4a3..978da135 100644 --- a/semantic_router/text.py +++ b/semantic_router/text.py @@ -19,7 +19,7 @@ colors = [ Fore.YELLOW, Fore.BLUE, Fore.MAGENTA, - Fore.CYAN + Fore.CYAN, ] @@ -48,10 +48,9 @@ class Conversation(BaseModel): return_str_list.append(f"{colors[color_idx]}{message}{Style.RESET_ALL}") return "\n".join(return_str_list) - def add_new_messages(self, new_messages: List[Message]): """Adds new messages to the conversation. - + :param messages: The new messages to be added to the conversation. :type messages: List[Message] """ @@ -148,7 +147,9 @@ class Conversation(BaseModel): for message in topic.docs: self.topics.append((i, message)) - def split_by_topic(self, force: bool = False) -> Tuple[List[Tuple[int, str]], List[DocumentSplit]]: + def split_by_topic( + self, force: bool = False + ) -> Tuple[List[Tuple[int, str]], List[DocumentSplit]]: """ Splits the messages into topics based on their semantic similarity. -- GitLab