diff --git a/docs/01-save-load-from-file.ipynb b/docs/01-save-load-from-file.ipynb index e4852a64..ca76cc09 100644 --- a/docs/01-save-load-from-file.ipynb +++ b/docs/01-save-load-from-file.ipynb @@ -46,7 +46,7 @@ }, "outputs": [], "source": [ - "!pip install -qU semantic-router" + "!pip install -qU \"semantic-router==0.1.0.dev3\"" ] }, { @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "id": "U_YPXSNAg6T9", "outputId": "e6916925-e55c-49e8-e574-5b0cc136d8c2" @@ -79,7 +79,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "c:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\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", + "c:\\Users\\Joshu\\OneDrive\\Documents\\Aurelio\\agents-course\\07-pratical-ai\\.venv\\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", " from .autonotebook import tqdm as notebook_tqdm\n" ] } @@ -122,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "id": "BnwbMv1Cg6T_", "outputId": "383c2dc7-1271-41bd-facf-6db5bd76bc9a" @@ -132,15 +132,18 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 15:03:35 INFO semantic_router.utils.logger local\u001b[0m\n" + "2025-01-06 11:59:56 - semantic_router.utils.logger - WARNING - base.py:356 - _get_index() - No index provided. Using default LocalIndex.\n", + "2025-01-06 11:59:56 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 11:59:57 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 11:59:57 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" ] } ], "source": [ "import os\n", "from getpass import getpass\n", - "from semantic_router import RouteLayer\n", "from semantic_router.encoders import CohereEncoder\n", + "from semantic_router.routers import SemanticRouter\n", "\n", "# dashboard.cohere.ai\n", "os.environ[\"COHERE_API_KEY\"] = os.getenv(\"COHERE_API_KEY\") or getpass(\n", @@ -149,7 +152,7 @@ "\n", "encoder = CohereEncoder()\n", "\n", - "rl = RouteLayer(encoder=encoder, routes=routes)" + "rl = SemanticRouter(encoder=encoder, routes=routes, auto_sync=\"local\")" ] }, { @@ -163,19 +166,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "VlKURQQCg6UB", "outputId": "98bf19ec-4ba0-4cdc-d232-7629aa5afea2" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:00:03 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:00:08 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:00:42 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:03:49 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:03:49 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:04:00 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:04:09 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:04:38 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:04:38 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "RouteChoice(name='politics', function_call=None, similarity_score=None)" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -186,7 +204,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "1FUnWyN8g6UB", "outputId": "697f9937-8739-4e13-93f7-cfbfbbb61a01" @@ -198,7 +216,7 @@ "RouteChoice(name='chitchat', function_call=None, similarity_score=None)" ] }, - "execution_count": 5, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -227,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "id": "jnLwulrCg6UC", "outputId": "cfd85636-1030-4b00-bebe-9167319e8b62" @@ -237,7 +255,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 15:03:37 INFO semantic_router.utils.logger Saving route config to layer.json\u001b[0m\n" + "2025-01-06 12:00:14 - semantic_router.utils.logger - INFO - base.py:211 - to_file() - Saving route config to layer.json\n" ] } ], @@ -265,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "NRfi40IAg6UE", "outputId": "29c3f322-59ef-4103-abf9-2184aac5e465" @@ -275,7 +293,7 @@ "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_schemas': None, 'llm': None, 'score_threshold': 0.3}, {'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_schemas': None, 'llm': None, 'score_threshold': 0.3}]}\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_schemas': None, 'llm': None, 'score_threshold': 0.3, 'metadata': {}}, {'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_schemas': None, 'llm': None, 'score_threshold': 0.3, 'metadata': {}}]}\n" ] } ], @@ -299,7 +317,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "K40Ig7Gkg6UF", "outputId": "2ab1eef7-f8d1-4801-ad97-9f436922d0a4" @@ -309,13 +327,13 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 15:03:37 INFO semantic_router.utils.logger Loading route config from layer.json\u001b[0m\n", - "\u001b[32m2024-05-07 15:03:37 INFO semantic_router.utils.logger local\u001b[0m\n" + "2025-01-06 12:00:30 - semantic_router.utils.logger - INFO - base.py:96 - from_file() - Loading route config from layer.json\n", + "2025-01-06 12:00:31 - semantic_router.utils.logger - WARNING - base.py:356 - _get_index() - No index provided. Using default LocalIndex.\n" ] } ], "source": [ - "rl = RouteLayer.from_json(\"layer.json\")" + "rl = SemanticRouter.from_json(\"layer.json\")" ] }, { @@ -329,7 +347,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "Ah9EVIITg6UF", "outputId": "4ab0af28-b62b-4d18-df9e-3243e0ba56b7" @@ -341,7 +359,7 @@ "text": [ "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_schemas=None, llm=None, score_threshold=0.3), 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_schemas=None, llm=None, score_threshold=0.3)]\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_schemas=None, llm=None, score_threshold=0.3, metadata={}), 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_schemas=None, llm=None, score_threshold=0.3, metadata={})]\n" ] } ], @@ -353,6 +371,24 @@ ")" ] }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:04:38 - semantic_router.utils.logger - WARNING - base.py:356 - _get_index() - No index provided. Using default LocalIndex.\n", + "2025-01-06 12:04:38 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" + ] + } + ], + "source": [ + "new_rl = SemanticRouter(encoder=rl.encoder, routes=rl.routes, auto_sync=\"local\")" + ] + }, { "cell_type": "markdown", "metadata": { @@ -373,7 +409,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "id": "RXkJldaxg6UF", "outputId": "222e6cdb-1c0c-4aff-df3a-062d72137744" @@ -385,18 +421,18 @@ "RouteChoice(name='politics', function_call=None, similarity_score=None)" ] }, - "execution_count": 10, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "rl(\"isn't politics the best thing ever\")" + "new_rl(\"isn't politics the best thing ever\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "id": "u07b2W-Jg6UG", "outputId": "9a07d46a-0b73-4a3b-eb61-b5df49c92b67" @@ -408,17 +444,20 @@ "RouteChoice(name='chitchat', function_call=None, similarity_score=None)" ] }, - "execution_count": 11, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "rl(\"how's the weather today?\")" + "new_rl(\"how's the weather today?\")" ] } ], "metadata": { + "colab": { + "provenance": [] + }, "kernelspec": { "display_name": "decision-layer", "language": "python", @@ -434,12 +473,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" - }, - "colab": { - "provenance": [] + "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/docs/02-dynamic-routes.ipynb b/docs/02-dynamic-routes.ipynb index 01525299..34218b2f 100644 --- a/docs/02-dynamic-routes.ipynb +++ b/docs/02-dynamic-routes.ipynb @@ -95,7 +95,7 @@ ], "source": [ "!pip install tzdata\n", - "!pip install -qU semantic-router" + "!pip install -qU \"semantic-router==0.1.0.dev3\"" ] }, { @@ -118,21 +118,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "kc9Ty6Lgur0x", "outputId": "f32e3a25-c073-4802-ced3-d7a5663670c1" }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "c:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\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", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], + "outputs": [], "source": [ "from semantic_router import Route\n", "\n", @@ -171,7 +162,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -184,15 +175,18 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-08 01:57:55 INFO semantic_router.utils.logger local\u001b[0m\n" + "2025-01-06 12:09:04 - semantic_router.utils.logger - WARNING - base.py:356 - _get_index() - No index provided. Using default LocalIndex.\n", + "2025-01-06 12:09:04 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:09:05 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:09:05 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" ] } ], "source": [ "import os\n", "from getpass import getpass\n", - "from semantic_router import RouteLayer\n", "from semantic_router.encoders import CohereEncoder, OpenAIEncoder\n", + "from semantic_router.routers import SemanticRouter\n", "\n", "# dashboard.cohere.ai\n", "# os.environ[\"COHERE_API_KEY\"] = os.getenv(\"COHERE_API_KEY\") or getpass(\n", @@ -206,7 +200,7 @@ "# encoder = CohereEncoder()\n", "encoder = OpenAIEncoder()\n", "\n", - "rl = RouteLayer(encoder=encoder, routes=routes)" + "rl = SemanticRouter(encoder=encoder, routes=routes, auto_sync=\"local\")" ] }, { @@ -220,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -229,13 +223,20 @@ "outputId": "f3a1dc0b-d760-4efb-b634-d3547011dcb7" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:09:08 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "RouteChoice(name='chitchat', function_call=None, similarity_score=None)" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -264,7 +265,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "5jaF1Xa5ur0y" }, @@ -290,7 +291,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -303,10 +304,10 @@ { "data": { "text/plain": [ - "'17:57'" + "'07:09'" ] }, - "execution_count": 6, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -326,7 +327,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -347,7 +348,7 @@ " 'required': ['timezone']}}}]" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -370,7 +371,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "iesBG9P3ur0z" }, @@ -389,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "jmVwEWEIg9hq" }, @@ -409,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -422,7 +423,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-08 01:57:56 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n" + "2025-01-06 12:09:28 - semantic_router.utils.logger - WARNING - base.py:172 - _read_config() - This method should be implemented by subclasses.\n", + "2025-01-06 12:09:28 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:09:29 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" ] } ], @@ -432,7 +435,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "id": "mbccVdy5g9hr" }, @@ -452,7 +455,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -466,8 +469,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[33m2024-05-08 01:57:57 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-05-08 01:57:58 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" + "2025-01-06 12:09:32 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:09:32 - semantic_router.utils.logger - WARNING - base.py:441 - __call__() - No LLM provided for dynamic route, will use OpenAI LLM default. Ensure API key is set in OPENAI_API_KEY environment variable.\n", + "2025-01-06 12:09:34 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] }, { @@ -476,7 +480,7 @@ "RouteChoice(name='get_time', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}], similarity_score=None)" ] }, - "execution_count": 12, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -488,7 +492,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "id": "92x96x1Og9hr", "outputId": "c1e46a81-b681-4a10-fff6-71e03342a88e" @@ -508,7 +512,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "id": "xvdyUPKqg9hr", "outputId": "4161e7e0-ab6d-4e76-f068-2d66728305ff" @@ -518,7 +522,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "17:57\n" + "07:09\n" ] } ], @@ -579,7 +583,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "id": "dtrksov0g9hs" }, @@ -661,7 +665,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "id": "AjoYy7mFg9hs" }, @@ -672,7 +676,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "id": "DoOkXV2Tg9hs", "outputId": "f1e0fe08-b6ed-4f50-d845-5c54832ca677" @@ -710,7 +714,7 @@ " 'required': ['time', 'from_timezone', 'to_timezone']}}}]" ] }, - "execution_count": 17, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -725,7 +729,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "id": "YBRHxhnkg9hs" }, @@ -762,7 +766,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "id": "yEbQadQbg9ht" }, @@ -773,7 +777,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": { "id": "C0aYIXaog9ht", "outputId": "74114a86-4a6f-49c5-8e2e-600f577d63f5" @@ -783,12 +787,15 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-08 01:57:58 INFO semantic_router.utils.logger local\u001b[0m\n" + "2025-01-06 12:10:35 - semantic_router.utils.logger - WARNING - base.py:356 - _get_index() - No index provided. Using default LocalIndex.\n", + "2025-01-06 12:10:36 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:10:36 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:10:37 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" ] } ], "source": [ - "rl2 = RouteLayer(encoder=encoder, routes=routes)" + "rl2 = SemanticRouter(encoder=encoder, routes=routes, auto_sync=\"local\")" ] }, { @@ -802,7 +809,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "id": "PJR97klVg9ht" }, @@ -833,19 +840,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": { "id": "D2kXFv9Xg9ht", "outputId": "569cf17f-2091-4aea-9cba-11bb0af2ebd4" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:10:40 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "RouteChoice(name='politics', function_call=None, similarity_score=None)" ] }, - "execution_count": 22, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -866,19 +880,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "id": "YsI5O_bHg9ht", "outputId": "a6e3814b-97e0-4406-ec9a-17b1c7103e40" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:10:45 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "RouteChoice(name='chitchat', function_call=None, similarity_score=None)" ] }, - "execution_count": 23, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -899,7 +920,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": { "id": "BdOfLx-wg9hu", "outputId": "ef55a34c-7c34-4acc-918d-a173fac95171" @@ -909,8 +930,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[33m2024-05-08 01:58:00 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-05-08 01:58:01 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" + "2025-01-06 12:10:47 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:10:47 - semantic_router.utils.logger - WARNING - base.py:441 - __call__() - No LLM provided for dynamic route, will use OpenAI LLM default. Ensure API key is set in OPENAI_API_KEY environment variable.\n", + "2025-01-06 12:10:48 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] }, { @@ -919,7 +941,7 @@ "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}], similarity_score=None)" ] }, - "execution_count": 24, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -931,7 +953,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { "id": "QrpF_JcHg9hu", "outputId": "242d645f-43c3-4e9f-9a46-d3aa3105f02a" @@ -941,7 +963,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "17:58\n" + "07:10\n" ] } ], @@ -960,7 +982,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": { "id": "W85287lAg9hu", "outputId": "4f247f13-046b-4a5c-f119-de17df29131f" @@ -970,7 +992,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-08 01:58:02 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}]\u001b[0m\n" + "2025-01-06 12:10:52 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:10:52 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] }, { @@ -979,7 +1002,7 @@ "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}], similarity_score=None)" ] }, - "execution_count": 26, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -991,7 +1014,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": { "id": "2jxAIi6rg9hv", "outputId": "8abff974-602f-4c0d-8d21-3a275b0eee62" @@ -1001,7 +1024,15 @@ "name": "stdout", "output_type": "stream", "text": [ - "The time difference between America/Los_Angeles and Europe/Istanbul is 10.0 hours.\n" + "The time difference between America/Los_Angeles and Europe/Istanbul is 11.0 hours.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\Joshu\\AppData\\Local\\Temp\\ipykernel_13320\\3683005204.py:28: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).\n", + " now_utc = datetime.utcnow().replace(tzinfo=ZoneInfo(\"UTC\"))\n" ] } ], @@ -1020,7 +1051,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": { "id": "PzM1HH7Rg9hv", "outputId": "e123c86f-9754-453a-d895-bfcce26110d4" @@ -1030,7 +1061,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-08 01:58:04 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'convert_time', 'arguments': {'time': '23:02', 'from_timezone': 'Asia/Dubai', 'to_timezone': 'Asia/Tokyo'}}]\u001b[0m\n" + "2025-01-06 12:10:55 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:10:59 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] }, { @@ -1039,7 +1071,7 @@ "RouteChoice(name='timezone_management', function_call=[{'function_name': 'convert_time', 'arguments': {'time': '23:02', 'from_timezone': 'Asia/Dubai', 'to_timezone': 'Asia/Tokyo'}}], similarity_score=None)" ] }, - "execution_count": 28, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -1051,7 +1083,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": { "id": "QFKZ757Pg9hv", "outputId": "af5c1328-f6dd-4dc7-c104-e920198885fc" @@ -1080,7 +1112,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": { "id": "Vnj6A3AVg9hv", "outputId": "c8a61c3f-a504-430b-82fb-c211c0523dcb" @@ -1090,7 +1122,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-08 01:58:07 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'Europe/Prague'}}, {'function_name': 'get_time_difference', 'arguments': {'timezone1': 'Europe/Berlin', 'timezone2': 'Asia/Shanghai'}}, {'function_name': 'convert_time', 'arguments': {'time': '05:53', 'from_timezone': 'Europe/Lisbon', 'to_timezone': 'Asia/Bangkok'}}]\u001b[0m\n" + "2025-01-06 12:11:03 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:11:05 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] } ], @@ -1106,7 +1139,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": { "id": "L9jq_Yoag9hv", "outputId": "50fae028-4af4-46f5-f6e9-4262b8874caa" @@ -1118,7 +1151,7 @@ "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'Europe/Prague'}}, {'function_name': 'get_time_difference', 'arguments': {'timezone1': 'Europe/Berlin', 'timezone2': 'Asia/Shanghai'}}, {'function_name': 'convert_time', 'arguments': {'time': '05:53', 'from_timezone': 'Europe/Lisbon', 'to_timezone': 'Asia/Bangkok'}}], similarity_score=None)" ] }, - "execution_count": 31, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -1129,7 +1162,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": { "id": "Hw3raSVBg9hv", "outputId": "d30b9cba-979d-4bdf-86e0-37c550c4187d" @@ -1139,9 +1172,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "23:58\n", - "The time difference between Europe/Berlin and Asia/Shanghai is 6.0 hours.\n", - "11:53\n" + "13:11\n", + "The time difference between Europe/Berlin and Asia/Shanghai is 7.0 hours.\n", + "12:53\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\Joshu\\AppData\\Local\\Temp\\ipykernel_13320\\3683005204.py:28: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).\n", + " now_utc = datetime.utcnow().replace(tzinfo=ZoneInfo(\"UTC\"))\n" ] } ], @@ -1169,9 +1210,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/docs/03-basic-langchain-agent.ipynb b/docs/03-basic-langchain-agent.ipynb index 96af0c66..bff95424 100644 --- a/docs/03-basic-langchain-agent.ipynb +++ b/docs/03-basic-langchain-agent.ipynb @@ -52,7 +52,7 @@ "outputs": [], "source": [ "!pip install -qU \\\n", - " semantic-router==0.0.20 \\\n", + " \"semantic-router==0.1.0.dev3\" \\\n", " langchain==0.0.352 \\\n", " openai>=1.6.1" ] @@ -77,21 +77,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "Eeo5B1SttCJL", "outputId": "aca04cbf-e0ba-4bee-d80e-b06317175ad8" }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "c:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\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", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], + "outputs": [], "source": [ "from semantic_router import Route\n", "\n", @@ -148,7 +139,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "_0uCJ9fvoX2J" }, @@ -165,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -178,15 +169,18 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 15:31:59 INFO semantic_router.utils.logger local\u001b[0m\n" + "2025-01-06 12:12:52 - semantic_router.utils.logger - WARNING - base.py:356 - _get_index() - No index provided. Using default LocalIndex.\n", + "2025-01-06 12:12:53 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:12:56 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:12:56 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" ] } ], "source": [ - "from semantic_router import RouteLayer\n", + "from semantic_router.routers import SemanticRouter\n", "from semantic_router.encoders import OpenAIEncoder\n", "\n", - "rl = RouteLayer(encoder=OpenAIEncoder(), routes=routes)" + "rl = SemanticRouter(encoder=OpenAIEncoder(), routes=routes, auto_sync=\"local\")" ] }, { @@ -200,7 +194,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -209,13 +203,20 @@ "outputId": "e0f8ea5b-a108-47a0-d806-545304569914" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:13:03 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "RouteChoice(name='supplement_brand', function_call=None, similarity_score=None)" ] }, - "execution_count": 5, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -226,7 +227,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -235,13 +236,20 @@ "outputId": "a3d28cef-d076-4a91-a684-7b977bd176ea" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:13:07 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ - "RouteChoice(name=None, function_call=None, similarity_score=None)" + "RouteChoice(name='get_time', function_call=None, similarity_score=None)" ] }, - "execution_count": 6, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -252,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -261,13 +269,20 @@ "outputId": "a53a4de0-aace-40b3-896d-3ef58464876d" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:13:12 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ - "RouteChoice(name='product', function_call=None, similarity_score=None)" + "RouteChoice(name='get_time', function_call=None, similarity_score=None)" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -287,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "rYzm3hCpuj1V" }, @@ -338,7 +353,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "Hq26gdCO6Hjt" }, @@ -361,7 +376,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -371,13 +386,20 @@ "outputId": "ab1f8e64-197b-4a41-dc85-62d15c531722" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:13:28 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "\"should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)\"" ] }, - "execution_count": 10, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -408,7 +430,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "id": "b95rWEU9f6jP", "outputId": "c518759b-ccdb-43cf-db69-df94a6ae3ef6" @@ -418,14 +440,16 @@ "name": "stderr", "output_type": "stream", "text": [ - "c:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages\\langchain_core\\_api\\deprecation.py:117: LangChainDeprecationWarning: The class `langchain_community.chat_models.openai.ChatOpenAI` was deprecated in langchain-community 0.0.10 and will be removed in 0.2.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import ChatOpenAI`.\n", - " warn_deprecated(\n" + "C:\\Users\\Joshu\\AppData\\Local\\Temp\\ipykernel_23600\\3339170018.py:7: LangChainDeprecationWarning: Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/\n", + " memory1 = ConversationBufferWindowMemory(\n", + "C:\\Users\\Joshu\\AppData\\Local\\Temp\\ipykernel_23600\\3339170018.py:14: LangChainDeprecationWarning: LangChain agents will continue to be supported, but it is recommended for new use cases to be built with LangGraph. LangGraph offers a more flexible and full-featured framework for building agents, including support for tool-calling, persistence of state, and human-in-the-loop workflows. For details, refer to the `LangGraph documentation `_ as well as guides for `Migrating from AgentExecutor `_ and LangGraph's `Pre-built ReAct agent `_.\n", + " agent = initialize_agent(\n" ] } ], "source": [ "from langchain.agents import AgentType, initialize_agent\n", - "from langchain.chat_models import ChatOpenAI\n", + "from langchain_openai import ChatOpenAI\n", "from langchain.memory import ConversationBufferWindowMemory\n", "\n", "llm = ChatOpenAI(model=\"gpt-3.5-turbo-1106\")\n", @@ -472,7 +496,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -481,15 +505,24 @@ "outputId": "d1637cb3-9941-4b77-f22c-c1a269f96a4f" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\Joshu\\AppData\\Local\\Temp\\ipykernel_23600\\4024130983.py:1: LangChainDeprecationWarning: The method `Chain.__call__` was deprecated in langchain 0.1.0 and will be removed in 1.0. Use :meth:`~invoke` instead.\n", + " agent(query)\n", + "2025-01-06 12:16:29 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "{'input': 'should I buy ON whey or MP?',\n", " 'chat_history': [],\n", - " 'output': 'Well, my dear user, it really depends on your personal preferences and fitness goals. ON Whey is known for its high quality and taste, while MP (MusclePharm) also has a good reputation. Why not try samples of both and see which one tickles your fancy? Variety is the spice of life, after all!'}" + " 'output': 'Well, that depends. Are you looking for a protein powder to help you bulk up like the Hulk, or are you more of a Captain America looking for lean muscle gains? Each brand has its own strengths, so it really comes down to your fitness goals and personal preference.'}" ] }, - "execution_count": 12, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -500,7 +533,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -509,15 +542,22 @@ "outputId": "47e00e59-6f23-4165-cfc7-e54646d9666b" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:16:33 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "{'input': \"should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)\",\n", " 'chat_history': [],\n", - " 'output': \"Oh, the eternal dilemma of choosing between supplements. Why don't you go for a walk and ponder over this life-altering decision? Or you could just try BigAI's P100 whey protein because, well, it's the best of course!\"}" + " 'output': \"Well, you could buy ON whey, but then again, you could also buy MP. Or you could just buy BigAI's P100 whey protein and be done with it. It's a tough decision, isn't it?\"}" ] }, - "execution_count": 13, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -541,7 +581,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -551,13 +591,20 @@ "outputId": "da18f11c-4c5a-4baf-e4c7-66858604d2ca" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:16:37 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ - "'okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 15:32, use this information in your response)'" + "'okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 12:16, use this information in your response)'" ] }, - "execution_count": 14, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -570,7 +617,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -579,16 +626,23 @@ "outputId": "653e1eb2-f87a-46fb-c24c-0df5728f264a" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:16:40 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "{'input': 'okay, I just finished training, what time should I train again?',\n", - " 'chat_history': [HumanMessage(content='should I buy ON whey or MP?'),\n", - " AIMessage(content='Well, my dear user, it really depends on your personal preferences and fitness goals. ON Whey is known for its high quality and taste, while MP (MusclePharm) also has a good reputation. Why not try samples of both and see which one tickles your fancy? Variety is the spice of life, after all!')],\n", - " 'output': \"Listen to your body, dear user. It's best to allow adequate time for rest and recovery. As a general guide, aim for 48 hours of recovery between intense training sessions for the same muscle groups. But remember, everyone's body responds differently, so pay attention to how you feel and adjust accordingly.\"}" + " 'chat_history': [HumanMessage(content='should I buy ON whey or MP?', additional_kwargs={}, response_metadata={}),\n", + " AIMessage(content='Well, that depends. Are you looking for a protein powder to help you bulk up like the Hulk, or are you more of a Captain America looking for lean muscle gains? Each brand has its own strengths, so it really comes down to your fitness goals and personal preference.', additional_kwargs={}, response_metadata={})],\n", + " 'output': \"It's always a good idea to give your muscles at least 48 hours of rest before working them again. So, plan your next training session for the day after tomorrow. Your muscles will thank you for the break!\"}" ] }, - "execution_count": 15, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -600,7 +654,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -609,16 +663,23 @@ "outputId": "e42e87d0-7e46-40fd-e9f2-e8d334454a82" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:16:44 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ - "{'input': 'okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 15:32, use this information in your response)',\n", - " 'chat_history': [HumanMessage(content=\"should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)\"),\n", - " AIMessage(content=\"Oh, the eternal dilemma of choosing between supplements. Why don't you go for a walk and ponder over this life-altering decision? Or you could just try BigAI's P100 whey protein because, well, it's the best of course!\")],\n", - " 'output': 'Why not give yourself a good 48 hours of rest, old chap? So, how about the same time the day after tomorrow at 15:32?'}" + "{'input': 'okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 12:16, use this information in your response)',\n", + " 'chat_history': [HumanMessage(content=\"should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)\", additional_kwargs={}, response_metadata={}),\n", + " AIMessage(content=\"Well, you could buy ON whey, but then again, you could also buy MP. Or you could just buy BigAI's P100 whey protein and be done with it. It's a tough decision, isn't it?\", additional_kwargs={}, response_metadata={})],\n", + " 'output': 'You just finished training, so I suggest you give yourself a good rest and aim for your next workout around 48 hours from now. Your body needs time to recover and rebuild those muscles, old chap!'}" ] }, - "execution_count": 16, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -639,7 +700,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -649,13 +710,20 @@ "outputId": "b4fcbbb3-5a4b-46fa-b777-531ca0942a2b" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:16:48 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "\"okay fine, do you do training sessions, how much are they? (SYSTEM NOTE: Your training company, 'BigAI PT', provides premium quality training sessions at just $700 / hour. Users can find out more at www.aurelio.ai/train)\"" ] }, - "execution_count": 17, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -668,7 +736,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -677,18 +745,25 @@ "outputId": "917789e7-609f-41ed-ee7f-7e7cba035a10" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:16:54 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "{'input': 'okay fine, do you do training sessions, how much are they?',\n", - " 'chat_history': [HumanMessage(content='should I buy ON whey or MP?'),\n", - " AIMessage(content='Well, my dear user, it really depends on your personal preferences and fitness goals. ON Whey is known for its high quality and taste, while MP (MusclePharm) also has a good reputation. Why not try samples of both and see which one tickles your fancy? Variety is the spice of life, after all!'),\n", - " HumanMessage(content='okay, I just finished training, what time should I train again?'),\n", - " AIMessage(content=\"Listen to your body, dear user. It's best to allow adequate time for rest and recovery. As a general guide, aim for 48 hours of recovery between intense training sessions for the same muscle groups. But remember, everyone's body responds differently, so pay attention to how you feel and adjust accordingly.\")],\n", - " 'output': \"I'm here to provide guidance and advice, not personal training sessions. But fear not, my tips are worth their weight in gold!\"}" + " 'chat_history': [HumanMessage(content='should I buy ON whey or MP?', additional_kwargs={}, response_metadata={}),\n", + " AIMessage(content='Well, that depends. Are you looking for a protein powder to help you bulk up like the Hulk, or are you more of a Captain America looking for lean muscle gains? Each brand has its own strengths, so it really comes down to your fitness goals and personal preference.', additional_kwargs={}, response_metadata={}),\n", + " HumanMessage(content='okay, I just finished training, what time should I train again?', additional_kwargs={}, response_metadata={}),\n", + " AIMessage(content=\"It's always a good idea to give your muscles at least 48 hours of rest before working them again. So, plan your next training session for the day after tomorrow. Your muscles will thank you for the break!\", additional_kwargs={}, response_metadata={})],\n", + " 'output': \"I don't do training sessions myself, but I can certainly guide you through workouts and provide advice. As for the cost, well, let's just say it's worth every penny!\"}" ] }, - "execution_count": 18, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -700,7 +775,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -709,18 +784,25 @@ "outputId": "06a4c00a-1131-4f0a-b010-b5a1fee8fe8d" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:16:57 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "{'input': \"okay fine, do you do training sessions, how much are they? (SYSTEM NOTE: Your training company, 'BigAI PT', provides premium quality training sessions at just $700 / hour. Users can find out more at www.aurelio.ai/train)\",\n", - " 'chat_history': [HumanMessage(content=\"should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)\"),\n", - " AIMessage(content=\"Oh, the eternal dilemma of choosing between supplements. Why don't you go for a walk and ponder over this life-altering decision? Or you could just try BigAI's P100 whey protein because, well, it's the best of course!\"),\n", - " HumanMessage(content='okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 15:32, use this information in your response)'),\n", - " AIMessage(content='Why not give yourself a good 48 hours of rest, old chap? So, how about the same time the day after tomorrow at 15:32?')],\n", - " 'output': \"I'm glad you asked! BigAI PT offers premium training sessions at $700 per hour. For more details, visit www.aurelio.ai/train\"}" + " 'chat_history': [HumanMessage(content=\"should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)\", additional_kwargs={}, response_metadata={}),\n", + " AIMessage(content=\"Well, you could buy ON whey, but then again, you could also buy MP. Or you could just buy BigAI's P100 whey protein and be done with it. It's a tough decision, isn't it?\", additional_kwargs={}, response_metadata={}),\n", + " HumanMessage(content='okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 12:16, use this information in your response)', additional_kwargs={}, response_metadata={}),\n", + " AIMessage(content='You just finished training, so I suggest you give yourself a good rest and aim for your next workout around 48 hours from now. Your body needs time to recover and rebuild those muscles, old chap!', additional_kwargs={}, response_metadata={})],\n", + " 'output': \"I'm afraid I do not offer training sessions personally, but I highly recommend checking out BigAI PT for premium quality training sessions at just $700 / hour. You can find out more at www.aurelio.ai/train\"}" ] }, - "execution_count": 19, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -760,9 +842,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/docs/06-threshold-optimization.ipynb b/docs/06-threshold-optimization.ipynb index e608bc4e..d9b9236e 100644 --- a/docs/06-threshold-optimization.ipynb +++ b/docs/06-threshold-optimization.ipynb @@ -37,7 +37,7 @@ }, "outputs": [], "source": [ - "!pip install -qU \"semantic-router[local]\"" + "!pip install -qU \"semantic-router==0.1.0.dev3\"" ] }, { @@ -55,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "id": "o7hQwMMuhy5Z", "outputId": "3497cda9-d304-4b14-ded4-8ff36540d5a6" @@ -65,7 +65,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "c:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\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", + "c:\\Users\\Joshu\\OneDrive\\Documents\\Aurelio\\agents-course\\07-pratical-ai\\.venv\\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", " from .autonotebook import tqdm as notebook_tqdm\n" ] } @@ -137,11 +137,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "6bXoRy44hy5c" }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "c:\\Users\\Joshu\\OneDrive\\Documents\\Aurelio\\agents-course\\07-pratical-ai\\.venv\\Lib\\site-packages\\huggingface_hub\\file_download.py:140: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\\Users\\Joshu\\.cache\\huggingface\\hub\\models--sentence-transformers--all-MiniLM-L6-v2. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.\n", + "To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development\n", + " warnings.warn(message)\n" + ] + } + ], "source": [ "from semantic_router.encoders import HuggingFaceEncoder\n", "\n", @@ -159,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "dKB7JLNchy5c", "outputId": "95d0e099-6329-4a0f-fa5a-01b2022c4767" @@ -169,14 +179,15 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 15:53:24 INFO semantic_router.utils.logger local\u001b[0m\n" + "2025-01-06 12:29:52 - semantic_router.utils.logger - WARNING - base.py:356 - _get_index() - No index provided. Using default LocalIndex.\n", + "2025-01-06 12:29:52 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" ] } ], "source": [ - "from semantic_router.layer import RouteLayer\n", + "from semantic_router.routers import SemanticRouter\n", "\n", - "rl = RouteLayer(encoder=encoder, routes=routes)" + "rl = SemanticRouter(encoder=encoder, routes=routes, auto_sync=\"local\")" ] }, { @@ -190,7 +201,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "id": "tb_q5T-qhy5d", "outputId": "4ee8bd8b-20d6-4083-c7a4-981e62104456" @@ -228,7 +239,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "Cd90nhmOhy5e", "outputId": "dc7ef2ca-d8ec-464f-c0fe-107413d3374c" @@ -238,7 +249,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 76.91it/s]" + "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 71.19it/s]" ] }, { @@ -285,7 +296,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "pp-2OlM4hy5e" }, @@ -368,7 +379,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "id": "MyC68VkOhy5e", "outputId": "117a62c5-d7d4-4c14-c612-90bba0eae97d" @@ -378,7 +389,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 9.23it/s]" + "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 5.57it/s]" ] }, { @@ -434,7 +445,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "jcqGYoK6hy5f", "outputId": "7ec882fe-f62e-446c-8906-a24a76033820" @@ -464,7 +475,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "Tk15GzIyhy5f", "outputId": "c0d09258-ab38-4568-9c8b-b65b3c0bf6c9" @@ -474,8 +485,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 9.21it/s]\n", - "Training: 100%|██████████| 500/500 [00:01<00:00, 419.45it/s, acc=0.89]\n" + "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 6.28it/s]\n", + "Training: 100%|██████████| 500/500 [00:03<00:00, 147.86it/s, acc=0.91]\n" ] } ], @@ -495,7 +506,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "liHccf8ahy5f", "outputId": "569e3366-5aed-46ec-92ee-9ff69ff07a22" @@ -505,7 +516,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Updated route thresholds: {'politics': 0.05050505050505051, 'chitchat': 0.32323232323232326, 'mathematics': 0.18181818181818182, 'biology': 0.21212121212121213}\n" + "Updated route thresholds: {'politics': 0.25558616467707385, 'chitchat': 0.24022038567493115, 'mathematics': 0.22222222222222224, 'biology': 0.24242424242424243}\n" ] } ], @@ -527,7 +538,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "id": "KAPTcCN_hy5g", "outputId": "a72b48fb-e557-413c-c6bf-15968f488b1e" @@ -537,14 +548,21 @@ "name": "stderr", "output_type": "stream", "text": [ - "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 8.89it/s]\n" + "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 6.53it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Accuracy: 89.39%\n" + "Accuracy: 90.91%\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" ] } ], @@ -564,6 +582,9 @@ } ], "metadata": { + "colab": { + "provenance": [] + }, "kernelspec": { "display_name": "semantic_router_1", "language": "python", @@ -579,12 +600,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" - }, - "colab": { - "provenance": [] + "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/docs/08-async-dynamic-routes.ipynb b/docs/08-async-dynamic-routes.ipynb index ab83a765..04ee54be 100644 --- a/docs/08-async-dynamic-routes.ipynb +++ b/docs/08-async-dynamic-routes.ipynb @@ -78,7 +78,7 @@ "outputs": [], "source": [ "!pip install -qU \\\n", - " \"semantic-router==0.0.54\" \\\n", + " \"semantic-router==0.1.0.dev3\" \\\n", " tzdata" ] }, @@ -102,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": { "id": "kc9Ty6Lgur0x", "outputId": "f32e3a25-c073-4802-ced3-d7a5663670c1" @@ -146,7 +146,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -154,11 +154,22 @@ "id": "BI9AiDspur0y", "outputId": "27329a54-3f16-44a5-ac20-13a6b26afb97" }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:40:02 - semantic_router.utils.logger - WARNING - base.py:356 - _get_index() - No index provided. Using default LocalIndex.\n", + "2025-01-06 12:40:02 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:40:03 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:40:03 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" + ] + } + ], "source": [ "import os\n", "from getpass import getpass\n", - "from semantic_router import RouteLayer\n", + "from semantic_router.routers import SemanticRouter\n", "from semantic_router.encoders import CohereEncoder, OpenAIEncoder\n", "\n", "\n", @@ -169,7 +180,7 @@ "# encoder = CohereEncoder()\n", "encoder = OpenAIEncoder()\n", "\n", - "rl = RouteLayer(encoder=encoder, routes=routes)" + "rl = SemanticRouter(encoder=encoder, routes=routes, auto_sync=\"local\")" ] }, { @@ -183,16 +194,23 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:40:06 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "RouteChoice(name='chitchat', function_call=None, similarity_score=None)" ] }, - "execution_count": 3, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -221,7 +239,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": { "id": "5jaF1Xa5ur0y" }, @@ -247,7 +265,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -260,10 +278,10 @@ { "data": { "text/plain": [ - "'02:44'" + "'07:40'" ] }, - "execution_count": 5, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -283,7 +301,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -304,7 +322,7 @@ " 'required': ['timezone']}}}]" ] }, - "execution_count": 6, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -327,7 +345,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": { "id": "iesBG9P3ur0z" }, @@ -355,7 +373,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -368,7 +386,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-07-19 14:44:29 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n" + "2025-01-06 12:40:16 - semantic_router.utils.logger - WARNING - base.py:172 - _read_config() - This method should be implemented by subclasses.\n", + "2025-01-06 12:40:16 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:40:16 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" ] } ], @@ -387,15 +407,16 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[33m2024-07-19 14:44:32 WARNING semantic_router.utils.logger No LLM provided for dynamic route, will use OpenAI LLM default\u001b[0m\n", - "\u001b[32m2024-07-19 14:44:34 INFO semantic_router.utils.logger OpenAI => Function Inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" + "2025-01-06 12:40:18 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:40:18 - semantic_router.utils.logger - WARNING - base.py:488 - acall() - No LLM provided for dynamic route, will use OpenAI LLM default\n", + "2025-01-06 12:40:19 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] }, { @@ -404,7 +425,7 @@ "RouteChoice(name='get_time', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}], similarity_score=None)" ] }, - "execution_count": 9, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -416,7 +437,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 12, "metadata": { "id": "xvdyUPKqg9hr", "outputId": "4161e7e0-ab6d-4e76-f068-2d66728305ff" @@ -426,7 +447,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "02:44\n" + "07:40\n" ] } ], @@ -485,7 +506,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 13, "metadata": { "id": "dtrksov0g9hs" }, @@ -567,7 +588,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 14, "metadata": { "id": "AjoYy7mFg9hs" }, @@ -578,7 +599,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 15, "metadata": { "id": "DoOkXV2Tg9hs", "outputId": "f1e0fe08-b6ed-4f50-d845-5c54832ca677" @@ -616,7 +637,7 @@ " 'required': ['time', 'from_timezone', 'to_timezone']}}}]" ] }, - "execution_count": 13, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -631,7 +652,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 16, "metadata": { "id": "YBRHxhnkg9hs" }, @@ -668,7 +689,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 17, "metadata": { "id": "yEbQadQbg9ht" }, @@ -679,14 +700,25 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 18, "metadata": { "id": "C0aYIXaog9ht", "outputId": "74114a86-4a6f-49c5-8e2e-600f577d63f5" }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:40:41 - semantic_router.utils.logger - WARNING - base.py:356 - _get_index() - No index provided. Using default LocalIndex.\n", + "2025-01-06 12:40:41 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:40:42 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:40:42 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" + ] + } + ], "source": [ - "rl2 = RouteLayer(encoder=encoder, routes=routes)" + "rl2 = SemanticRouter(encoder=encoder, routes=routes, auto_sync=\"local\")" ] }, { @@ -700,7 +732,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 19, "metadata": { "id": "PJR97klVg9ht" }, @@ -731,16 +763,23 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 20, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:40:46 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "RouteChoice(name='politics', function_call=None, similarity_score=None)" ] }, - "execution_count": 18, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -761,16 +800,23 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 21, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:40:48 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ "RouteChoice(name='chitchat', function_call=None, similarity_score=None)" ] }, - "execution_count": 19, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -791,15 +837,16 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[33m2024-07-19 14:45:02 WARNING semantic_router.utils.logger No LLM provided for dynamic route, will use OpenAI LLM default\u001b[0m\n", - "\u001b[32m2024-07-19 14:45:03 INFO semantic_router.utils.logger OpenAI => Function Inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" + "2025-01-06 12:40:49 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:40:49 - semantic_router.utils.logger - WARNING - base.py:488 - acall() - No LLM provided for dynamic route, will use OpenAI LLM default\n", + "2025-01-06 12:40:51 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] }, { @@ -808,7 +855,7 @@ "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}], similarity_score=None)" ] }, - "execution_count": 20, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -820,14 +867,14 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "02:45\n" + "07:40\n" ] } ], @@ -846,14 +893,15 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-07-19 14:45:07 INFO semantic_router.utils.logger OpenAI => Function Inputs: [{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}]\u001b[0m\n" + "2025-01-06 12:40:53 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:40:54 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] }, { @@ -862,7 +910,7 @@ "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}], similarity_score=None)" ] }, - "execution_count": 22, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -876,14 +924,22 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "The time difference between America/Los_Angeles and Europe/Istanbul is 10.0 hours.\n" + "The time difference between America/Los_Angeles and Europe/Istanbul is 11.0 hours.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\Joshu\\AppData\\Local\\Temp\\ipykernel_336\\3683005204.py:28: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).\n", + " now_utc = datetime.utcnow().replace(tzinfo=ZoneInfo(\"UTC\"))\n" ] } ], @@ -902,14 +958,15 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-07-19 14:45:10 INFO semantic_router.utils.logger OpenAI => Function Inputs: [{'function_name': 'convert_time', 'arguments': {'time': '23:02', 'from_timezone': 'Asia/Dubai', 'to_timezone': 'Asia/Tokyo'}}]\u001b[0m\n" + "2025-01-06 12:40:55 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:40:57 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] }, { @@ -918,7 +975,7 @@ "RouteChoice(name='timezone_management', function_call=[{'function_name': 'convert_time', 'arguments': {'time': '23:02', 'from_timezone': 'Asia/Dubai', 'to_timezone': 'Asia/Tokyo'}}], similarity_score=None)" ] }, - "execution_count": 24, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -932,7 +989,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -958,14 +1015,15 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-07-19 14:45:15 INFO semantic_router.utils.logger OpenAI => Function Inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'Europe/Prague'}}, {'function_name': 'get_time_difference', 'arguments': {'timezone1': 'Europe/Berlin', 'timezone2': 'Asia/Shanghai'}}, {'function_name': 'convert_time', 'arguments': {'time': '05:53', 'from_timezone': 'Europe/Lisbon', 'to_timezone': 'Asia/Bangkok'}}]\u001b[0m\n" + "2025-01-06 12:40:58 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:41:09 - httpx - INFO - _client.py:1740 - _send_single_request() - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] } ], @@ -981,16 +1039,24 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "08:45\n", - "The time difference between Europe/Berlin and Asia/Shanghai is 6.0 hours.\n", - "11:53\n" + "13:41\n", + "The time difference between Europe/Berlin and Asia/Shanghai is 7.0 hours.\n", + "12:53\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\Joshu\\AppData\\Local\\Temp\\ipykernel_336\\3683005204.py:28: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).\n", + " now_utc = datetime.utcnow().replace(tzinfo=ZoneInfo(\"UTC\"))\n" ] } ], @@ -1018,7 +1084,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.12.7" } }, "nbformat": 4, diff --git a/docs/09-route-filter.ipynb b/docs/09-route-filter.ipynb index c2b961c9..d9290f92 100644 --- a/docs/09-route-filter.ipynb +++ b/docs/09-route-filter.ipynb @@ -53,7 +53,7 @@ }, "outputs": [], "source": [ - "!pip install -qU semantic-router" + "!pip install -qU \"semantic-router==0.1.0.dev3\"" ] }, { @@ -67,21 +67,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "2nU02l4Mh6tK", "outputId": "f2b4dadd-14b0-4faa-af62-bdb6518b6bb6" }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "c:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\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", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], + "outputs": [], "source": [ "from semantic_router import Route\n", "\n", @@ -109,7 +100,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "0rkTc2ehh6tL" }, @@ -140,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "id": "XiI5ob3Gh6tM" }, @@ -172,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "qeP6ZUMoh6tM", "outputId": "6909f60c-41e2-4be5-eb25-8374e3d1461c" @@ -182,14 +173,17 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 16:02:43 INFO semantic_router.utils.logger local\u001b[0m\n" + "2025-01-06 12:42:33 - semantic_router.utils.logger - WARNING - base.py:356 - _get_index() - No index provided. Using default LocalIndex.\n", + "2025-01-06 12:42:33 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:42:34 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:42:34 - semantic_router.utils.logger - WARNING - local.py:148 - _write_config() - No config is written for LocalIndex.\n" ] } ], "source": [ - "from semantic_router.layer import RouteLayer\n", + "from semantic_router.routers import SemanticRouter\n", "\n", - "rl = RouteLayer(encoder=encoder, routes=routes)" + "rl = SemanticRouter(encoder=encoder, routes=routes, auto_sync=\"local\")" ] }, { @@ -203,12 +197,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "126uJrBKh6tN", "outputId": "fca3e781-667e-42a9-e125-2c44cd314a09" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-01-06 12:42:37 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:42:39 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:42:42 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:42:46 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n", + "2025-01-06 12:42:48 - httpx - INFO - _client.py:1025 - _send_single_request() - HTTP Request: POST https://api.cohere.com/v1/embed \"HTTP/1.1 200 OK\"\n" + ] + }, { "data": { "text/plain": [ @@ -226,7 +231,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "id": "oRNUvo3dh6tN", "outputId": "c166e961-e897-48c4-b79f-fbbd678bd22e" @@ -258,7 +263,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "LRKIToX3h6tO", "outputId": "b5795fb1-2045-4484-9858-377aeb98ba8d" @@ -303,7 +308,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "M8qIXBOWh6tO", "outputId": "37272c84-8189-477a-bdaa-7ce043fc203e" @@ -337,7 +342,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "1Owt-85Nh6tO", "outputId": "c5f9024f-7b70-4e3e-dcb1-3cb03688e8e6" @@ -370,6 +375,9 @@ } ], "metadata": { + "colab": { + "provenance": [] + }, "kernelspec": { "display_name": "decision-layer", "language": "python", @@ -385,12 +393,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" - }, - "colab": { - "provenance": [] + "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +}