diff --git a/docs/07-route-conversations-by-topic.ipynb b/docs/examples/conversation-topic-splitter.ipynb similarity index 76% rename from docs/07-route-conversations-by-topic.ipynb rename to docs/examples/conversation-topic-splitter.ipynb index 9d2b54243644db66b7611d4088214b5a636b7c70..5ac130b0fcd8277f559606817a353e1b261f12f6 100644 --- a/docs/07-route-conversations-by-topic.ipynb +++ b/docs/examples/conversation-topic-splitter.ipynb @@ -18,11 +18,6 @@ "Additionally, splitters have been integrated with `Conversation` objects allowing conversations to be progressively spit by topic as they evolve. This is beneficial to routing, as earlier messages in a conversation topic might provide useful context when determining routes. By using all utterances in the latest conversation this additional context allows for correct routes to be more reliably chosen." ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -53,7 +48,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "c:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\20240130 2148 Semantic Topic Splitter (Siraj Local Repo)\\venvs\\semantic_splitter_1\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + "/Users/jamesbriggs/opt/anaconda3/envs/decision-layer/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } @@ -74,7 +69,7 @@ " 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", + " Message(role=\"user\", content=\"Yeah, v.3.11.2.\"),\n", "]\n", "\n", "# Add messages to the conversation\n", @@ -90,24 +85,15 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "from semantic_router.encoders.cohere import CohereEncoder\n", + "from semantic_router.encoders.openai import OpenAIEncoder\n", "\n", - "cohere_encoder = CohereEncoder(\n", - " name=\"embed-english-v3.0\",\n", - " cohere_api_key=\"\",\n", - " input_type=\"search_document\",\n", - ")" + "encoder = OpenAIEncoder(openai_api_key=\"sk-...\")" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -117,26 +103,25 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "No unclustered messages to process.\n", "\u001b[31muser: Hi, there, please can you confirm your full name\u001b[0m\n", "\u001b[31muser: Hi, my name is John Doe.\u001b[0m\n", - "\u001b[32mbot: Okay, how can I help you today?\u001b[0m\n", - "\u001b[33muser: My computer keeps crashing\u001b[0m\n", - "\u001b[33mbot: Okay, is our software running when the computer crashes.\u001b[0m\n", - "\u001b[33muser: Yeah, v.3.11.2 is running when it crashes.\u001b[0m\n" + "\u001b[31mbot: Okay, how can I help you today?\u001b[0m\n", + "\u001b[32muser: My computer keeps crashing\u001b[0m\n", + "\u001b[32mbot: Okay, is our software running when the computer crashes.\u001b[0m\n", + "\u001b[32muser: Yeah, v.3.11.2.\u001b[0m\n" ] } ], "source": [ "conversation.configure_splitter(\n", - " encoder=cohere_encoder, threshold=0.5, split_method=\"cumulative_similarity\"\n", + " encoder=encoder, threshold=0.78, split_method=\"cumulative_similarity\"\n", ")\n", "\n", "all_topics, new_topics = conversation.split_by_topic()\n", @@ -185,7 +170,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -204,7 +189,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -213,22 +198,22 @@ "text": [ "\u001b[31muser: Hi, there, please can you confirm your full name\u001b[0m\n", "\u001b[31muser: Hi, my name is John Doe.\u001b[0m\n", - "\u001b[32mbot: Okay, how can I help you today?\u001b[0m\n", - "\u001b[33muser: My computer keeps crashing\u001b[0m\n", - "\u001b[33mbot: Okay, is our software running when the computer crashes.\u001b[0m\n", - "\u001b[33muser: Yeah, v.3.11.2 is running when it crashes.\u001b[0m\n", - "\u001b[33muser: What do the system logs say, right before the crash?\u001b[0m\n", - "\u001b[34muser: I'll check soon, but first let's talk refund.\u001b[0m\n", - "\u001b[34mbot: Okay let me sort out a refund.\u001b[0m\n" + "\u001b[31mbot: Okay, how can I help you today?\u001b[0m\n", + "\u001b[32muser: My computer keeps crashing\u001b[0m\n", + "\u001b[32mbot: Okay, is our software running when the computer crashes.\u001b[0m\n", + "\u001b[32muser: Yeah, v.3.11.2.\u001b[0m\n", + "\u001b[32muser: What do the system logs say, right before the crash?\u001b[0m\n", + "\u001b[33muser: I'll check soon, but first let's talk refund.\u001b[0m\n", + "\u001b[33mbot: Okay let me sort out a refund.\u001b[0m\n" ] } ], "source": [ "conversation.configure_splitter(\n", - " encoder=cohere_encoder, threshold=0.5, split_method=\"cumulative_similarity\"\n", + " encoder=encoder, threshold=0.78, split_method=\"cumulative_similarity\"\n", ")\n", "\n", - "all_topics, new_topics = conversation.split_by_topic()\n", + "all_topics, new_topics = conversation.split_by_topic(force=True)\n", "\n", "print(conversation)" ] @@ -246,16 +231,6 @@ "\n", "Despite \"user: Yeah, v.3.11.2 is running when it crashes\" and \"user: What do the system logs say, right before the crash?\" being added and separately, and despite the conversation splitter being run twice (once before user: What do the system logs say, right before the crash?\" was added, and once after), both these utterances were successfully assigned the same Topic - `Topic 4`.\n" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] } ], "metadata": { @@ -274,7 +249,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.11.5" } }, "nbformat": 4,