From 906aebcf8d5cdf1de29b93fca85a218f0ff31657 Mon Sep 17 00:00:00 2001 From: James Briggs <35938317+jamescalam@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:40:38 +0100 Subject: [PATCH] remove warning --- docs/00-introduction.ipynb | 7 -- docs/01-save-load-from-file.ipynb | 7 -- docs/03-basic-langchain-agent.ipynb | 9 -- docs/04-chat-history.ipynb | 139 ++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 23 deletions(-) create mode 100644 docs/04-chat-history.ipynb diff --git a/docs/00-introduction.ipynb b/docs/00-introduction.ipynb index 4d672f37..06650703 100644 --- a/docs/00-introduction.ipynb +++ b/docs/00-introduction.ipynb @@ -44,13 +44,6 @@ "!pip install -qU semantic-router==0.0.15" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "_**âš ï¸ If using Google Colab, install the prerequisites and then restart the notebook before continuing**_" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/docs/01-save-load-from-file.ipynb b/docs/01-save-load-from-file.ipynb index 43937d2b..6c5945cb 100644 --- a/docs/01-save-load-from-file.ipynb +++ b/docs/01-save-load-from-file.ipynb @@ -39,13 +39,6 @@ "!pip install -qU semantic-router==0.0.15" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "_**âš ï¸ If using Google Colab, install the prerequisites and then restart the notebook before continuing**_" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/docs/03-basic-langchain-agent.ipynb b/docs/03-basic-langchain-agent.ipynb index c8c48b3d..dc728495 100644 --- a/docs/03-basic-langchain-agent.ipynb +++ b/docs/03-basic-langchain-agent.ipynb @@ -83,15 +83,6 @@ " openai==1.6.1" ] }, - { - "cell_type": "markdown", - "metadata": { - "id": "cHtVnoJPA04x" - }, - "source": [ - "_**âš ï¸ If using Google Colab, install the prerequisites and then restart the notebook before continuing**_" - ] - }, { "cell_type": "markdown", "metadata": { diff --git a/docs/04-chat-history.ipynb b/docs/04-chat-history.ipynb new file mode 100644 index 00000000..4ac533b1 --- /dev/null +++ b/docs/04-chat-history.ipynb @@ -0,0 +1,139 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[](https://colab.research.google.com/github/aurelio-labs/semantic-router/blob/main/docs/00-introduction.ipynb) [](https://nbviewer.org/github/aurelio-labs/semantic-router/blob/main/docs/00-introduction.ipynb)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Considering Chat History" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Applying semantic-router to the most recent interaction in a conversation can work for many cases but it misses scenarios where information provided in the latest interaction." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/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", + "100%|██████████| 83.2M/83.2M [00:09<00:00, 8.45MiB/s]\n" + ] + }, + { + "data": { + "text/plain": [ + "{'split 1': ['User: Hello! Can you tell me the latest news headlines?',\n", + " 'Bot: Hi! Sure, here are the top news headlines for today...'],\n", + " 'split 2': [\"User: That's quite interesting. I'm also looking for some new music to listen to.\",\n", + " 'Bot: What genre do you prefer?',\n", + " 'User: I like pop music.',\n", + " 'Bot: You might enjoy the latest album by Dua Lipa.',\n", + " \"User: I'll give it a listen. Also, I'm planning a trip and need some travel tips.\",\n", + " 'Bot: Sure, where are you planning to go?'],\n", + " 'split 3': [\"User: I'm thinking of visiting Italy.\",\n", + " 'Bot: Italy is a beautiful country. Make sure to visit the Colosseum in Rome and the canals in Venice.'],\n", + " 'split 4': ['User: Those sound like great suggestions. I also need some help with my diet.',\n", + " 'Bot: What kind of diet are you following?',\n", + " \"User: I'm trying to eat more protein.\",\n", + " 'Bot: Include lean meats, eggs, and legumes in your diet for a protein boost.',\n", + " \"User: Thanks for the tips! I'll talk to you later.\",\n", + " \"Bot: You're welcome! Don't hesitate to reach out if you need more help.\",\n", + " 'User: I appreciate it. Goodbye!',\n", + " 'Bot: Goodbye! Take care!']}" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from semantic_router.schema import Conversation, Message\n", + "from semantic_router.encoders import FastEmbedEncoder\n", + "\n", + "\n", + "messages = [\n", + " \"User: Hello! Can you tell me the latest news headlines?\",\n", + " \"Bot: Hi! Sure, here are the top news headlines for today...\",\n", + " \"User: That's quite interesting. I'm also looking for some new music to listen to.\",\n", + " \"Bot: What genre do you prefer?\",\n", + " \"User: I like pop music.\",\n", + " \"Bot: You might enjoy the latest album by Dua Lipa.\",\n", + " \"User: I'll give it a listen. Also, I'm planning a trip and need some travel tips.\",\n", + " \"Bot: Sure, where are you planning to go?\",\n", + " \"User: I'm thinking of visiting Italy.\",\n", + " \"Bot: Italy is a beautiful country. Make sure to visit the Colosseum in Rome and the canals in Venice.\",\n", + " \"User: Those sound like great suggestions. I also need some help with my diet.\",\n", + " \"Bot: What kind of diet are you following?\",\n", + " \"User: I'm trying to eat more protein.\",\n", + " \"Bot: Include lean meats, eggs, and legumes in your diet for a protein boost.\",\n", + " \"User: Thanks for the tips! I'll talk to you later.\",\n", + " \"Bot: You're welcome! Don't hesitate to reach out if you need more help.\",\n", + " \"User: I appreciate it. Goodbye!\",\n", + " \"Bot: Goodbye! Take care!\",\n", + "]\n", + "\n", + "encoder = FastEmbedEncoder(model_name=\"sentence-transformers/all-MiniLM-L6-v2\")\n", + "\n", + "convo = Conversation(\n", + " messages=[\n", + " Message(role=m.split(\": \")[0], content=m.split(\": \")[1]) for m in messages\n", + " ]\n", + ")\n", + "\n", + "convo.split_by_topic(\n", + " encoder=encoder, threshold=0.72, split_method=\"cumulative_similarity_drop\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "ml", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} -- GitLab