diff --git a/docs/00-introduction.ipynb b/docs/00-introduction.ipynb index ae6b768d54baa59a6d6117c41fe3df736ca3584e..4d672f379a44b236ad60a04eaf439c7a0c29ec94 100644 --- a/docs/00-introduction.ipynb +++ b/docs/00-introduction.ipynb @@ -41,7 +41,7 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -qU semantic-router==0.0.14" + "!pip install -qU semantic-router==0.0.15" ] }, { @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -88,7 +88,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -115,7 +115,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -143,14 +143,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2023-12-28 19:14:34 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" + "\u001b[32m2024-01-07 18:08:29 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" ] } ], @@ -169,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -178,7 +178,7 @@ "RouteChoice(name='politics', function_call=None)" ] }, - "execution_count": 7, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -189,7 +189,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -198,7 +198,7 @@ "RouteChoice(name='chitchat', function_call=None)" ] }, - "execution_count": 8, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -216,7 +216,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -225,7 +225,7 @@ "RouteChoice(name=None, function_call=None)" ] }, - "execution_count": 9, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } diff --git a/docs/01-save-load-from-file.ipynb b/docs/01-save-load-from-file.ipynb index 715679ceedcb95b5b34b6812382e57c114a612ea..43937d2b7d74f1161073d866128df7b43ce87dca 100644 --- a/docs/01-save-load-from-file.ipynb +++ b/docs/01-save-load-from-file.ipynb @@ -36,7 +36,7 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -qU semantic-router==0.0.14" + "!pip install -qU semantic-router==0.0.15" ] }, { @@ -64,17 +64,7 @@ "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", - "None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.\n" - ] - } - ], + "outputs": [], "source": [ "from semantic_router import Route\n", "\n", @@ -106,19 +96,19 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We define a route layer using these routes and using the default Cohere encoder." + "We define a route layer using these routes and using the Cohere encoder." ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2023-12-28 19:16:54 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" + "\u001b[32m2024-01-07 18:10:03 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" ] } ], @@ -126,13 +116,16 @@ "import os\n", "from getpass import getpass\n", "from semantic_router import RouteLayer\n", + "from semantic_router.encoders import CohereEncoder\n", "\n", "# dashboard.cohere.ai\n", "os.environ[\"COHERE_API_KEY\"] = os.getenv(\"COHERE_API_KEY\") or getpass(\n", " \"Enter Cohere API Key: \"\n", ")\n", "\n", - "rl = RouteLayer(routes=routes)" + "encoder = CohereEncoder()\n", + "\n", + "rl = RouteLayer(encoder=encoder, routes=routes)" ] }, { @@ -144,14 +137,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2023-12-28 19:17:03 INFO semantic_router.utils.logger Saving route config to layer.json\u001b[0m\n" + "\u001b[32m2024-01-07 18:10:05 INFO semantic_router.utils.logger Saving route config to layer.json\u001b[0m\n" ] } ], @@ -175,14 +168,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'encoder_type': 'cohere', 'encoder_name': 'embed-english-v3.0', 'routes': [{'name': 'politics', 'utterances': [\"isn't politics the best thing ever\", \"why don't you tell me about your political opinions\", \"don't you just love the presidentdon't you just hate the president\", \"they're going to destroy this country!\", 'they will save the country!'], 'description': None, 'function_schema': None}, {'name': 'chitchat', 'utterances': [\"how's the weather today?\", 'how are things going?', 'lovely weather today', 'the weather is horrendous', \"let's go to the chippy\"], 'description': None, 'function_schema': None}]}\n" + "{'encoder_type': 'cohere', 'encoder_name': 'embed-english-v3.0', 'routes': [{'name': 'politics', 'utterances': [\"isn't politics the best thing ever\", \"why don't you tell me about your political opinions\", \"don't you just love the presidentdon't you just hate the president\", \"they're going to destroy this country!\", 'they will save the country!'], 'description': None, 'function_schema': None, 'llm': None}, {'name': 'chitchat', 'utterances': [\"how's the weather today?\", 'how are things going?', 'lovely weather today', 'the weather is horrendous', \"let's go to the chippy\"], 'description': None, 'function_schema': None, 'llm': None}]}\n" ] } ], @@ -204,15 +197,15 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2023-12-28 19:17:08 INFO semantic_router.utils.logger Loading route config from layer.json\u001b[0m\n", - "\u001b[32m2023-12-28 19:17:08 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" + "\u001b[32m2024-01-07 18:10:14 INFO semantic_router.utils.logger Loading route config from layer.json\u001b[0m\n", + "\u001b[32m2024-01-07 18:10:14 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" ] } ], @@ -229,16 +222,16 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "layer.encoder.type='cohere'\n", - "layer.encoder.name='embed-english-v3.0'\n", - "layer.routes=[Route(name='politics', utterances=[\"isn't politics the best thing ever\", \"why don't you tell me about your political opinions\", \"don't you just love the presidentdon't you just hate the president\", \"they're going to destroy this country!\", 'they will save the country!'], description=None, function_schema=None), Route(name='chitchat', utterances=[\"how's the weather today?\", 'how are things going?', 'lovely weather today', 'the weather is horrendous', \"let's go to the chippy\"], description=None, function_schema=None)]\n" + "rl.encoder.type='cohere'\n", + "rl.encoder.name='embed-english-v3.0'\n", + "rl.routes=[Route(name='politics', utterances=[\"isn't politics the best thing ever\", \"why don't you tell me about your political opinions\", \"don't you just love the presidentdon't you just hate the president\", \"they're going to destroy this country!\", 'they will save the country!'], description=None, function_schema=None, llm=None), Route(name='chitchat', utterances=[\"how's the weather today?\", 'how are things going?', 'lovely weather today', 'the weather is horrendous', \"let's go to the chippy\"], description=None, function_schema=None, llm=None)]\n" ] } ], diff --git a/docs/02-dynamic-routes.ipynb b/docs/02-dynamic-routes.ipynb index c695838e5713e7504258bfc51480e7cb6965659b..70c5eced9ece37a822ac0af0174f03f9ec07768a 100644 --- a/docs/02-dynamic-routes.ipynb +++ b/docs/02-dynamic-routes.ipynb @@ -108,7 +108,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-07 15:23:12 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" + "\u001b[32m2024-01-07 18:11:05 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" ] } ], @@ -204,7 +204,7 @@ { "data": { "text/plain": [ - "'09:23'" + "'12:11'" ] }, "execution_count": 5, @@ -289,7 +289,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-07 15:23:16 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n" + "\u001b[32m2024-01-07 18:11:20 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n" ] } ], @@ -313,8 +313,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[33m2024-01-07 15:23:17 WARNING semantic_router.utils.logger No LLM provided for dynamic route, will use OpenAI LLM default. Ensure API key is set in OPENAI_API_KEY environment variable.\u001b[0m\n", - "\u001b[32m2024-01-07 15:23:17 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" + "\u001b[33m2024-01-07 18:11:23 WARNING semantic_router.utils.logger No LLM provided for dynamic route, will use OpenAI LLM default. Ensure API key is set in OPENAI_API_KEY environment variable.\u001b[0m\n", + "\u001b[32m2024-01-07 18:11:23 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" ] }, { @@ -337,6 +337,13 @@ "rl(\"what is the time in new york city?\")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Our dynamic route provides both the route itself _and_ the input parameters required to use the route." + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/docs/03-basic-langchain-agent.ipynb b/docs/03-basic-langchain-agent.ipynb index 3bfd3ba52bb97ed97084b0ea58cb5d98a5dde08d..c8c48b3dbedf5c6a09243ff2c93a1071f40c916d 100644 --- a/docs/03-basic-langchain-agent.ipynb +++ b/docs/03-basic-langchain-agent.ipynb @@ -78,7 +78,7 @@ ], "source": [ "!pip install -qU \\\n", - " semantic-router==0.0.14 \\\n", + " semantic-router==0.0.15 \\\n", " langchain==0.0.352 \\\n", " openai==1.6.1" ] @@ -458,7 +458,7 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.memory import ConversationBufferWindowMemory\n", "\n", - "llm = ChatOpenAI(openai_api_key=\"\", model=\"gpt-3.5-turbo-1106\")\n", + "llm = ChatOpenAI(model=\"gpt-3.5-turbo-1106\")\n", "\n", "memory1 = ConversationBufferWindowMemory(\n", " memory_key=\"chat_history\", k=5, return_messages=True, output_key=\"output\"\n",