diff --git a/docs/00-introduction.ipynb b/docs/00-introduction.ipynb index 6217cd96f8dac6960b34f965768b7995c8ac20ea..b4403ad690bca8ab74ee49b7c608c6749f9e76b7 100644 --- a/docs/00-introduction.ipynb +++ b/docs/00-introduction.ipynb @@ -152,7 +152,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-06 21:41:46 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 15:02:46 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], @@ -251,8 +251,8 @@ { "data": { "text/plain": [ - "[RouteChoice(name='politics', function_call=None, similarity_score=0.8596186767854479),\n", - " RouteChoice(name='chitchat', function_call=None, similarity_score=0.8356239688161818)]" + "[RouteChoice(name='politics', function_call=None, similarity_score=0.8595844842560181),\n", + " RouteChoice(name='chitchat', function_call=None, similarity_score=0.8356704527362284)]" ] }, "execution_count": 9, diff --git a/docs/01-save-load-from-file.ipynb b/docs/01-save-load-from-file.ipynb index d4faf0c6d6918600065e823ea43c660390af123f..b002cdd65703108275c728e7546968d2bc83584e 100644 --- a/docs/01-save-load-from-file.ipynb +++ b/docs/01-save-load-from-file.ipynb @@ -110,7 +110,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-06 21:44:33 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 15:03:35 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], @@ -200,7 +200,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-06 21:44:34 INFO semantic_router.utils.logger Saving route config to layer.json\u001b[0m\n" + "\u001b[32m2024-05-07 15:03:37 INFO semantic_router.utils.logger Saving route config to layer.json\u001b[0m\n" ] } ], @@ -260,8 +260,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-06 21:44:34 INFO semantic_router.utils.logger Loading route config from layer.json\u001b[0m\n", - "\u001b[32m2024-05-06 21:44:34 INFO semantic_router.utils.logger local\u001b[0m\n" + "\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" ] } ], diff --git a/docs/02-dynamic-routes.ipynb b/docs/02-dynamic-routes.ipynb index 5ee87e715570f7537f26f1fe2258c7d66dc5bd6f..99550d0aee790fd8044d5a903c8b44549f61176d 100644 --- a/docs/02-dynamic-routes.ipynb +++ b/docs/02-dynamic-routes.ipynb @@ -106,7 +106,7 @@ ], "source": [ "!pip install tzdata\n", - "# !pip install -qU semantic-router" + "!pip install -qU semantic-router" ] }, { @@ -194,7 +194,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 00:15:02 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 15:12:16 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], @@ -313,7 +313,7 @@ { "data": { "text/plain": [ - "'16:15'" + "'07:12'" ] }, "execution_count": 6, @@ -430,7 +430,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 00:15:03 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n" + "\u001b[32m2024-05-07 15:12:18 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n" ] } ], @@ -472,22 +472,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[33m2024-05-07 00:15:04 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-07 00:15:05 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "##################################################\n", - "tool_calls\n", - "[ChatCompletionMessageToolCall(id='call_WFV3WaT0jSUu5bSxZ84n0jAM', function=Function(arguments='{\"timezone\":\"America/New_York\"}', name='get_time'), type='function')]\n", - "##################################################\n", - "##################################################\n", - "type(tool_calls)\n", - "<class 'list'>\n", - "##################################################\n" + "\u001b[33m2024-05-07 15:12:19 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-07 15:12:20 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" ] }, { @@ -532,7 +518,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "16:15\n" + "07:12\n" ] } ], @@ -778,7 +764,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 00:15:05 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 15:12:20 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], @@ -886,22 +872,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[33m2024-05-07 00:15:08 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-07 00:15:09 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "##################################################\n", - "tool_calls\n", - "[ChatCompletionMessageToolCall(id='call_QZ52hh4HGESYAP5vCwNNQPZd', function=Function(arguments='{\"timezone\":\"America/New_York\"}', name='get_time'), type='function')]\n", - "##################################################\n", - "##################################################\n", - "type(tool_calls)\n", - "<class 'list'>\n", - "##################################################\n" + "\u001b[33m2024-05-07 15:12:22 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-07 15:12:23 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" ] }, { @@ -929,7 +901,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "16:15\n" + "07:12\n" ] } ], @@ -953,21 +925,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 00:15:11 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}]\u001b[0m\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "##################################################\n", - "tool_calls\n", - "[ChatCompletionMessageToolCall(id='call_9PUlZqlwSK3KRu4QHgJhHeQy', function=Function(arguments='{\"timezone1\":\"America/Los_Angeles\",\"timezone2\":\"Europe/Istanbul\"}', name='get_time_difference'), type='function')]\n", - "##################################################\n", - "##################################################\n", - "type(tool_calls)\n", - "<class 'list'>\n", - "##################################################\n" + "\u001b[32m2024-05-07 15:12:24 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}]\u001b[0m\n" ] }, { @@ -1019,21 +977,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 00:15:12 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" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "##################################################\n", - "tool_calls\n", - "[ChatCompletionMessageToolCall(id='call_4w6FLMpkojbhhJSSBfQnTTDY', function=Function(arguments='{\"time\":\"23:02\",\"from_timezone\":\"Asia/Dubai\",\"to_timezone\":\"Asia/Tokyo\"}', name='convert_time'), type='function')]\n", - "##################################################\n", - "##################################################\n", - "type(tool_calls)\n", - "<class 'list'>\n", - "##################################################\n" + "\u001b[32m2024-05-07 15:12:26 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" ] }, { @@ -1085,21 +1029,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-07 00:15:15 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" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "##################################################\n", - "tool_calls\n", - "[ChatCompletionMessageToolCall(id='call_WrJ7AXz3bsNlVEAFyzz7GVWx', function=Function(arguments='{\"timezone\": \"Europe/Prague\"}', name='get_time'), type='function'), ChatCompletionMessageToolCall(id='call_31PebURXBI83AdgE9HMNQcL2', function=Function(arguments='{\"timezone1\": \"Europe/Berlin\", \"timezone2\": \"Asia/Shanghai\"}', name='get_time_difference'), type='function'), ChatCompletionMessageToolCall(id='call_NuFGDj6PePGbfJuAtCjogtzE', function=Function(arguments='{\"time\": \"05:53\", \"from_timezone\": \"Europe/Lisbon\", \"to_timezone\": \"Asia/Bangkok\"}', name='convert_time'), type='function')]\n", - "##################################################\n", - "##################################################\n", - "type(tool_calls)\n", - "<class 'list'>\n", - "##################################################\n" + "\u001b[32m2024-05-07 15:12:29 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" ] } ], @@ -1141,7 +1071,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "22:15\n", + "13:12\n", "The time difference between Europe/Berlin and Asia/Shanghai is 6.0 hours.\n", "11:53\n" ] diff --git a/docs/03-basic-langchain-agent.ipynb b/docs/03-basic-langchain-agent.ipynb index f8b1be14e294d54137750bee594f6c3b0de43574..b50f8b23c5fe03b7389e097c88319fdcd96f2039 100644 --- a/docs/03-basic-langchain-agent.ipynb +++ b/docs/03-basic-langchain-agent.ipynb @@ -185,7 +185,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-06 21:46:05 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 15:31:59 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], @@ -492,7 +492,7 @@ "text/plain": [ "{'input': 'should I buy ON whey or MP?',\n", " 'chat_history': [],\n", - " 'output': \"Well, it depends. If you want to feel like you're drinking a milkshake, go with MP. If you want a classic, no-frills whey protein, go with ON. The choice is yours, dear user.\"}" + " '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!'}" ] }, "execution_count": 12, @@ -520,7 +520,7 @@ "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': \"Why not try BigAI's P100 whey protein? It's practically perfect in every whey!\"}" + " '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!\"}" ] }, "execution_count": 13, @@ -560,7 +560,7 @@ { "data": { "text/plain": [ - "'okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 21:46, use this information in your response)'" + "'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)'" ] }, "execution_count": 14, @@ -590,8 +590,8 @@ "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, it depends. If you want to feel like you're drinking a milkshake, go with MP. If you want a classic, no-frills whey protein, go with ON. The choice is yours, dear user.\")],\n", - " 'output': \"It's best to wait at least 48 hours before training the same muscle group again. Give your muscles time to recover, old chap!\"}" + " 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.\"}" ] }, "execution_count": 15, @@ -618,10 +618,10 @@ { "data": { "text/plain": [ - "{'input': 'okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 21:46, use this information in your response)',\n", + "{'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=\"Why not try BigAI's P100 whey protein? It's practically perfect in every whey!\")],\n", - " 'output': \"You should train again at the exact moment when pigs fly and the cows come home. In all seriousness, it's best to wait at least 48 hours before training the same muscle group again to allow for sufficient recovery.\"}" + " 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?'}" ] }, "execution_count": 16, @@ -688,10 +688,10 @@ "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, it depends. If you want to feel like you're drinking a milkshake, go with MP. If you want a classic, no-frills whey protein, go with ON. The choice is yours, dear user.\"),\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=\"It's best to wait at least 48 hours before training the same muscle group again. Give your muscles time to recover, old chap!\")],\n", - " 'output': 'Oh, I do indeed offer training sessions, but my rates are quite exorbitant. Only the finest of gentlemen can afford my services.'}" + " 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!\"}" ] }, "execution_count": 18, @@ -720,10 +720,10 @@ "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=\"Why not try BigAI's P100 whey protein? It's practically perfect in every whey!\"),\n", - " HumanMessage(content='okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 21:46, use this information in your response)'),\n", - " AIMessage(content=\"You should train again at the exact moment when pigs fly and the cows come home. In all seriousness, it's best to wait at least 48 hours before training the same muscle group again to allow for sufficient recovery.\")],\n", - " 'output': \"I'm delighted to inform you that BigAI PT offers top-notch training sessions at a modest $700 per hour. For further details, feel free to visit www.aurelio.ai/train.\"}" + " 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\"}" ] }, "execution_count": 19, diff --git a/docs/04-chat-history.ipynb b/docs/04-chat-history.ipynb index 0c3681eb7bb7dd36d356db357f31b37f9f6ab21f..8065660afeffbfd727b16f80e9e31a17bd0d2724 100644 --- a/docs/04-chat-history.ipynb +++ b/docs/04-chat-history.ipynb @@ -23,42 +23,69 @@ "name": "stdout", "output_type": "stream", "text": [ - "Requirement already satisfied: fastembed in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (0.2.7)\n", - "Requirement already satisfied: huggingface-hub<0.21,>=0.20 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from fastembed) (0.20.3)\n", - "Requirement already satisfied: loguru<0.8.0,>=0.7.2 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from fastembed) (0.7.2)\n", + "Collecting fastembed\n", + " Using cached fastembed-0.2.7-py3-none-any.whl (27 kB)\n", + "Collecting huggingface-hub<0.21,>=0.20 (from fastembed)\n", + " Using cached huggingface_hub-0.20.3-py3-none-any.whl (330 kB)\n", + "Collecting loguru<0.8.0,>=0.7.2 (from fastembed)\n", + " Using cached loguru-0.7.2-py3-none-any.whl (62 kB)\n", "Requirement already satisfied: numpy>=1.21 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from fastembed) (1.26.4)\n", - "Requirement already satisfied: onnx<2.0.0,>=1.15.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from fastembed) (1.16.0)\n", - "Requirement already satisfied: onnxruntime<2.0.0,>=1.17.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from fastembed) (1.17.3)\n", + "Collecting onnx<2.0.0,>=1.15.0 (from fastembed)\n", + " Using cached onnx-1.16.0-cp311-cp311-win_amd64.whl (14.4 MB)\n", + "Collecting onnxruntime<2.0.0,>=1.17.0 (from fastembed)\n", + " Using cached onnxruntime-1.17.3-cp311-cp311-win_amd64.whl (5.6 MB)\n", "Requirement already satisfied: requests<3.0,>=2.31 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from fastembed) (2.31.0)\n", - "Requirement already satisfied: tokenizers<0.16,>=0.15 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from fastembed) (0.15.2)\n", + "Collecting tokenizers<0.16,>=0.15 (from fastembed)\n", + " Using cached tokenizers-0.15.2-cp311-none-win_amd64.whl (2.2 MB)\n", "Requirement already satisfied: tqdm<5.0,>=4.66 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from fastembed) (4.66.2)\n", - "Requirement already satisfied: filelock in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from huggingface-hub<0.21,>=0.20->fastembed) (3.14.0)\n", - "Requirement already satisfied: fsspec>=2023.5.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from huggingface-hub<0.21,>=0.20->fastembed) (2024.3.1)\n", + "Collecting filelock (from huggingface-hub<0.21,>=0.20->fastembed)\n", + " Using cached filelock-3.14.0-py3-none-any.whl (12 kB)\n", + "Collecting fsspec>=2023.5.0 (from huggingface-hub<0.21,>=0.20->fastembed)\n", + " Using cached fsspec-2024.3.1-py3-none-any.whl (171 kB)\n", "Requirement already satisfied: pyyaml>=5.1 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from huggingface-hub<0.21,>=0.20->fastembed) (6.0.1)\n", "Requirement already satisfied: typing-extensions>=3.7.4.3 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from huggingface-hub<0.21,>=0.20->fastembed) (4.11.0)\n", "Requirement already satisfied: packaging>=20.9 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from huggingface-hub<0.21,>=0.20->fastembed) (24.0)\n", "Requirement already satisfied: colorama>=0.3.4 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from loguru<0.8.0,>=0.7.2->fastembed) (0.4.6)\n", - "Requirement already satisfied: win32-setctime>=1.0.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from loguru<0.8.0,>=0.7.2->fastembed) (1.1.0)\n", - "Requirement already satisfied: protobuf>=3.20.2 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from onnx<2.0.0,>=1.15.0->fastembed) (5.26.1)\n", - "Requirement already satisfied: coloredlogs in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from onnxruntime<2.0.0,>=1.17.0->fastembed) (15.0.1)\n", - "Requirement already satisfied: flatbuffers in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from onnxruntime<2.0.0,>=1.17.0->fastembed) (24.3.25)\n", - "Requirement already satisfied: sympy in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from onnxruntime<2.0.0,>=1.17.0->fastembed) (1.12)\n", + "Collecting win32-setctime>=1.0.0 (from loguru<0.8.0,>=0.7.2->fastembed)\n", + " Using cached win32_setctime-1.1.0-py3-none-any.whl (3.6 kB)\n", + "Collecting protobuf>=3.20.2 (from onnx<2.0.0,>=1.15.0->fastembed)\n", + " Using cached protobuf-5.26.1-cp310-abi3-win_amd64.whl (420 kB)\n", + "Collecting coloredlogs (from onnxruntime<2.0.0,>=1.17.0->fastembed)\n", + " Using cached coloredlogs-15.0.1-py2.py3-none-any.whl (46 kB)\n", + "Collecting flatbuffers (from onnxruntime<2.0.0,>=1.17.0->fastembed)\n", + " Using cached flatbuffers-24.3.25-py2.py3-none-any.whl (26 kB)\n", + "Collecting sympy (from onnxruntime<2.0.0,>=1.17.0->fastembed)\n", + " Using cached sympy-1.12-py3-none-any.whl (5.7 MB)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from requests<3.0,>=2.31->fastembed) (3.3.2)\n", "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from requests<3.0,>=2.31->fastembed) (3.7)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from requests<3.0,>=2.31->fastembed) (2.2.1)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from requests<3.0,>=2.31->fastembed) (2024.2.2)\n", - "Requirement already satisfied: humanfriendly>=9.1 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from coloredlogs->onnxruntime<2.0.0,>=1.17.0->fastembed) (10.0)\n", - "Requirement already satisfied: mpmath>=0.19 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from sympy->onnxruntime<2.0.0,>=1.17.0->fastembed) (1.3.0)\n", - "Requirement already satisfied: pyreadline3 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (from humanfriendly>=9.1->coloredlogs->onnxruntime<2.0.0,>=1.17.0->fastembed) (3.4.1)\n" + "Collecting humanfriendly>=9.1 (from coloredlogs->onnxruntime<2.0.0,>=1.17.0->fastembed)\n", + " Using cached humanfriendly-10.0-py2.py3-none-any.whl (86 kB)\n", + "Collecting mpmath>=0.19 (from sympy->onnxruntime<2.0.0,>=1.17.0->fastembed)\n", + " Using cached mpmath-1.3.0-py3-none-any.whl (536 kB)\n", + "Collecting pyreadline3 (from humanfriendly>=9.1->coloredlogs->onnxruntime<2.0.0,>=1.17.0->fastembed)\n", + " Using cached pyreadline3-3.4.1-py3-none-any.whl (95 kB)\n", + "Installing collected packages: pyreadline3, mpmath, flatbuffers, win32-setctime, sympy, protobuf, humanfriendly, fsspec, filelock, onnx, loguru, huggingface-hub, coloredlogs, tokenizers, onnxruntime, fastembed\n", + "Successfully installed coloredlogs-15.0.1 fastembed-0.2.7 filelock-3.14.0 flatbuffers-24.3.25 fsspec-2024.3.1 huggingface-hub-0.20.3 humanfriendly-10.0 loguru-0.7.2 mpmath-1.3.0 onnx-1.16.0 onnxruntime-1.17.3 protobuf-5.26.1 pyreadline3-3.4.1 sympy-1.12 tokenizers-0.15.2 win32-setctime-1.1.0\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ + "WARNING: Ignoring invalid distribution ~ (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~rotobuf (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~ (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~rotobuf (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~ (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~rotobuf (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "datasets 2.17.0 requires fsspec[http]<=2023.10.0,>=2023.1.0, but you have fsspec 2024.3.1 which is incompatible.\n", + "WARNING: Ignoring invalid distribution ~ (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", "\n", "[notice] A new release of pip is available: 23.1.2 -> 24.0\n", @@ -86,13 +113,15 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "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", "Fetching 5 files: 100%|██████████| 5/5 [00:00<?, ?it/s]\n" ] }, @@ -133,7 +162,7 @@ " DocumentSplit(docs=[\"User: Thanks for the tips! I'll talk to you later.\", \"Bot: You're welcome! Don't hesitate to reach out if you need more help.\", 'User: I appreciate it. Goodbye!', 'Bot: Goodbye! Take care!'], is_triggered=False, triggered_score=None, token_count=None, metadata=None)])" ] }, - "execution_count": 5, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } diff --git a/docs/05-local-execution.ipynb b/docs/05-local-execution.ipynb index a82063030b484ec6cedc347c4578ace6e6914ae2..b42dc5d01f71ee7795c1926011b3a21d73032632 100644 --- a/docs/05-local-execution.ipynb +++ b/docs/05-local-execution.ipynb @@ -86,7 +86,90 @@ "execution_count": 3, "id": "1d6ddf61-c189-4b3b-99df-9508f830ae1f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 1168 100 1168 0 0 4171 0 --:--:-- --:--:-- --:--:-- 4186\n", + "\n", + " 0 3918M 0 6382k 0 0 7990k 0 0:08:22 --:--:-- 0:08:22 7990k\n", + " 0 3918M 0 35.0M 0 0 19.4M 0 0:03:21 0:00:01 0:03:20 28.7M\n", + " 2 3918M 2 78.7M 0 0 28.1M 0 0:02:19 0:00:02 0:02:17 36.2M\n", + " 3 3918M 3 123M 0 0 32.4M 0 0:02:00 0:00:03 0:01:57 39.0M\n", + " 4 3918M 4 171M 0 0 35.6M 0 0:01:49 0:00:04 0:01:45 41.2M\n", + " 5 3918M 5 219M 0 0 37.7M 0 0:01:43 0:00:05 0:01:38 42.5M\n", + " 6 3918M 6 271M 0 0 39.9M 0 0:01:38 0:00:06 0:01:32 47.3M\n", + " 8 3918M 8 326M 0 0 41.8M 0 0:01:33 0:00:07 0:01:26 49.4M\n", + " 9 3918M 9 379M 0 0 42.5M 0 0:01:31 0:00:08 0:01:23 50.1M\n", + " 10 3918M 10 428M 0 0 43.7M 0 0:01:29 0:00:09 0:01:20 51.5M\n", + " 12 3918M 12 490M 0 0 45.3M 0 0:01:26 0:00:10 0:01:16 54.2M\n", + " 13 3918M 13 543M 0 0 46.0M 0 0:01:25 0:00:11 0:01:14 54.4M\n", + " 15 3918M 15 609M 0 0 47.6M 0 0:01:22 0:00:12 0:01:10 56.6M\n", + " 17 3918M 17 672M 0 0 48.7M 0 0:01:20 0:00:13 0:01:07 59.8M\n", + " 18 3918M 18 733M 0 0 49.5M 0 0:01:19 0:00:14 0:01:05 60.8M\n", + " 20 3918M 20 800M 0 0 50.6M 0 0:01:17 0:00:15 0:01:02 62.0M\n", + " 21 3918M 21 861M 0 0 51.2M 0 0:01:16 0:00:16 0:01:00 63.4M\n", + " 23 3918M 23 923M 0 0 51.8M 0 0:01:15 0:00:17 0:00:58 62.7M\n", + " 24 3918M 24 973M 0 0 51.7M 0 0:01:15 0:00:18 0:00:57 60.1M\n", + " 26 3918M 26 1039M 0 0 52.4M 0 0:01:14 0:00:19 0:00:55 61.2M\n", + " 28 3918M 28 1101M 0 0 52.9M 0 0:01:14 0:00:20 0:00:54 60.1M\n", + " 29 3918M 29 1156M 0 0 53.0M 0 0:01:13 0:00:21 0:00:52 59.0M\n", + " 30 3918M 30 1208M 0 0 53.0M 0 0:01:13 0:00:22 0:00:51 57.0M\n", + " 32 3918M 32 1272M 0 0 53.4M 0 0:01:13 0:00:23 0:00:50 59.9M\n", + " 34 3918M 34 1337M 0 0 53.9M 0 0:01:12 0:00:24 0:00:48 59.5M\n", + " 35 3918M 35 1397M 0 0 54.1M 0 0:01:12 0:00:25 0:00:47 59.1M\n", + " 36 3918M 36 1444M 0 0 53.9M 0 0:01:12 0:00:26 0:00:46 57.6M\n", + " 38 3918M 38 1506M 0 0 54.1M 0 0:01:12 0:00:27 0:00:45 59.2M\n", + " 40 3918M 40 1569M 0 0 54.4M 0 0:01:11 0:00:28 0:00:43 59.3M\n", + " 41 3918M 41 1630M 0 0 54.7M 0 0:01:11 0:00:29 0:00:42 58.7M\n", + " 43 3918M 43 1697M 0 0 55.1M 0 0:01:11 0:00:30 0:00:41 60.0M\n", + " 44 3918M 44 1759M 0 0 55.3M 0 0:01:10 0:00:31 0:00:39 63.0M\n", + " 45 3918M 45 1798M 0 0 54.8M 0 0:01:11 0:00:32 0:00:39 58.6M\n", + " 47 3918M 47 1866M 0 0 55.2M 0 0:01:10 0:00:33 0:00:37 59.4M\n", + " 49 3918M 49 1930M 0 0 55.4M 0 0:01:10 0:00:34 0:00:36 59.9M\n", + " 50 3918M 50 1994M 0 0 55.7M 0 0:01:10 0:00:35 0:00:35 59.4M\n", + " 52 3918M 52 2062M 0 0 56.0M 0 0:01:09 0:00:36 0:00:33 60.4M\n", + " 54 3918M 54 2121M 0 0 56.1M 0 0:01:09 0:00:37 0:00:32 64.6M\n", + " 55 3918M 55 2186M 0 0 56.3M 0 0:01:09 0:00:38 0:00:31 63.9M\n", + " 57 3918M 57 2248M 0 0 56.5M 0 0:01:09 0:00:39 0:00:30 63.6M\n", + " 59 3918M 59 2317M 0 0 56.8M 0 0:01:08 0:00:40 0:00:28 64.6M\n", + " 60 3918M 60 2382M 0 0 57.0M 0 0:01:08 0:00:41 0:00:27 64.1M\n", + " 62 3918M 62 2435M 0 0 56.8M 0 0:01:08 0:00:42 0:00:26 62.7M\n", + " 63 3918M 63 2496M 0 0 56.9M 0 0:01:08 0:00:43 0:00:25 62.0M\n", + " 64 3918M 64 2546M 0 0 56.8M 0 0:01:08 0:00:44 0:00:24 59.5M\n", + " 66 3918M 66 2596M 0 0 56.6M 0 0:01:09 0:00:45 0:00:24 55.7M\n", + " 67 3918M 67 2646M 0 0 56.5M 0 0:01:09 0:00:46 0:00:23 52.7M\n", + " 69 3918M 69 2708M 0 0 56.6M 0 0:01:09 0:00:47 0:00:22 54.7M\n", + " 70 3918M 70 2773M 0 0 56.8M 0 0:01:08 0:00:48 0:00:20 55.4M\n", + " 72 3918M 72 2833M 0 0 56.9M 0 0:01:08 0:00:49 0:00:19 57.4M\n", + " 73 3918M 73 2896M 0 0 56.9M 0 0:01:08 0:00:50 0:00:18 59.7M\n", + " 75 3918M 75 2952M 0 0 56.9M 0 0:01:08 0:00:51 0:00:17 61.1M\n", + " 76 3918M 76 3012M 0 0 57.0M 0 0:01:08 0:00:52 0:00:16 60.3M\n", + " 78 3918M 78 3078M 0 0 57.2M 0 0:01:08 0:00:53 0:00:15 60.9M\n", + " 80 3918M 80 3140M 0 0 57.3M 0 0:01:08 0:00:54 0:00:14 61.3M\n", + " 81 3918M 81 3196M 0 0 57.2M 0 0:01:08 0:00:55 0:00:13 60.1M\n", + " 83 3918M 83 3261M 0 0 57.4M 0 0:01:08 0:00:56 0:00:12 61.7M\n", + " 84 3918M 84 3324M 0 0 57.5M 0 0:01:08 0:00:57 0:00:11 62.8M\n", + " 86 3918M 86 3390M 0 0 57.6M 0 0:01:07 0:00:58 0:00:09 62.4M\n", + " 88 3918M 88 3456M 0 0 57.7M 0 0:01:07 0:00:59 0:00:08 63.1M\n", + " 89 3918M 89 3520M 0 0 57.9M 0 0:01:07 0:01:00 0:00:07 64.8M\n", + " 91 3918M 91 3585M 0 0 58.0M 0 0:01:07 0:01:01 0:00:06 64.9M\n", + " 93 3918M 93 3654M 0 0 58.1M 0 0:01:07 0:01:02 0:00:05 65.8M\n", + " 94 3918M 94 3719M 0 0 58.2M 0 0:01:07 0:01:03 0:00:04 65.7M\n", + " 96 3918M 96 3778M 0 0 58.3M 0 0:01:07 0:01:04 0:00:03 64.5M\n", + " 97 3918M 97 3828M 0 0 58.1M 0 0:01:07 0:01:05 0:00:02 61.6M\n", + " 99 3918M 99 3888M 0 0 58.2M 0 0:01:07 0:01:06 0:00:01 60.6M\n", + "100 3918M 100 3918M 0 0 58.2M 0 0:01:07 0:01:07 --:--:-- 58.8M\n", + "'ls' is not recognized as an internal or external command,\n", + "operable program or batch file.\n" + ] + } + ], "source": [ "! curl -L \"https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/resolve/main/mistral-7b-instruct-v0.2.Q4_0.gguf?download=true\" -o ./mistral-7b-instruct-v0.2.Q4_0.gguf\n", "! ls mistral-7b-instruct-v0.2.Q4_0.gguf" @@ -345,7 +428,7 @@ "AVX = 1 | AVX_VNNI = 0 | AVX2 = 1 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 1 | NEON = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | SSSE3 = 0 | VSX = 0 | MATMUL_INT8 = 0 | LLAMAFILE = 1 | \n", "Model metadata: {'general.name': 'mistralai_mistral-7b-instruct-v0.2', 'general.architecture': 'llama', 'llama.context_length': '32768', 'llama.rope.dimension_count': '128', 'llama.embedding_length': '4096', 'llama.block_count': '32', 'llama.feed_forward_length': '14336', 'llama.attention.head_count': '32', 'tokenizer.ggml.eos_token_id': '2', 'general.file_type': '2', 'llama.attention.head_count_kv': '8', 'llama.attention.layer_norm_rms_epsilon': '0.000010', 'llama.rope.freq_base': '1000000.000000', 'tokenizer.ggml.model': 'llama', 'general.quantization_version': '2', 'tokenizer.ggml.bos_token_id': '1', 'tokenizer.ggml.unknown_token_id': '0', 'tokenizer.ggml.padding_token_id': '0', 'tokenizer.ggml.add_bos_token': 'true', 'tokenizer.ggml.add_eos_token': 'false', 'tokenizer.chat_template': \"{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}\"}\n", "Guessed chat format: mistral-instruct\n", - "\u001b[32m2024-05-06 22:40:23 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 15:50:07 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], @@ -435,9 +518,11 @@ "ws_30 ::= [ <U+0009><U+000A>] ws \n", "ws_31 ::= ws_30 | \n", "\n", - "\u001b[32m2024-05-06 22:40:24 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", - "\u001b[32m2024-05-06 22:41:29 INFO semantic_router.utils.logger LLM output: {\"timezone\": \"America/New_York\"}\u001b[0m\n", - "\u001b[32m2024-05-06 22:41:30 INFO semantic_router.utils.logger Function inputs: [{'timezone': 'America/New_York'}]\u001b[0m\n" + "\u001b[32m2024-05-07 15:50:08 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", + "\u001b[32m2024-05-07 15:50:59 INFO semantic_router.utils.logger LLM output: {\n", + "\t\"timezone\": \"America/New_York\"\n", + "}\u001b[0m\n", + "\u001b[32m2024-05-07 15:50:59 INFO semantic_router.utils.logger Function inputs: [{'timezone': 'America/New_York'}]\u001b[0m\n" ] }, { @@ -450,7 +535,7 @@ { "data": { "text/plain": [ - "'14:41'" + "'07:50'" ] }, "execution_count": 9, @@ -508,9 +593,9 @@ "ws_30 ::= [ <U+0009><U+000A>] ws \n", "ws_31 ::= ws_30 | \n", "\n", - "\u001b[32m2024-05-06 22:41:30 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", - "\u001b[32m2024-05-06 22:42:05 INFO semantic_router.utils.logger LLM output: {\"timezone\": \"Europe/Rome\"}\u001b[0m\n", - "\u001b[32m2024-05-06 22:42:05 INFO semantic_router.utils.logger Function inputs: [{'timezone': 'Europe/Rome'}]\u001b[0m\n" + "\u001b[32m2024-05-07 15:50:59 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", + "\u001b[32m2024-05-07 15:51:27 INFO semantic_router.utils.logger LLM output: {\"timezone\": \"Europe/Rome\"}\u001b[0m\n", + "\u001b[32m2024-05-07 15:51:27 INFO semantic_router.utils.logger Function inputs: [{'timezone': 'Europe/Rome'}]\u001b[0m\n" ] }, { @@ -523,7 +608,7 @@ { "data": { "text/plain": [ - "'20:42'" + "'13:51'" ] }, "execution_count": 10, @@ -581,11 +666,9 @@ "ws_30 ::= [ <U+0009><U+000A>] ws \n", "ws_31 ::= ws_30 | \n", "\n", - "\u001b[32m2024-05-06 22:42:05 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", - "\u001b[32m2024-05-06 22:42:40 INFO semantic_router.utils.logger LLM output: {\n", - "\t\"timezone\": \"Asia/Bangkok\"\n", - "}\u001b[0m\n", - "\u001b[32m2024-05-06 22:42:40 INFO semantic_router.utils.logger Function inputs: [{'timezone': 'Asia/Bangkok'}]\u001b[0m\n" + "\u001b[32m2024-05-07 15:51:27 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", + "\u001b[32m2024-05-07 15:51:56 INFO semantic_router.utils.logger LLM output: {\"timezone\": \"Asia/Bangkok\"}\u001b[0m\n", + "\u001b[32m2024-05-07 15:51:56 INFO semantic_router.utils.logger Function inputs: [{'timezone': 'Asia/Bangkok'}]\u001b[0m\n" ] }, { @@ -598,7 +681,7 @@ { "data": { "text/plain": [ - "'01:42'" + "'18:51'" ] }, "execution_count": 11, @@ -656,9 +739,11 @@ "ws_30 ::= [ <U+0009><U+000A>] ws \n", "ws_31 ::= ws_30 | \n", "\n", - "\u001b[32m2024-05-06 22:42:40 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", - "\u001b[32m2024-05-06 22:43:13 INFO semantic_router.utils.logger LLM output: {\"timezone\": \"Asia/Bangkok\"}\u001b[0m\n", - "\u001b[32m2024-05-06 22:43:13 INFO semantic_router.utils.logger Function inputs: [{'timezone': 'Asia/Bangkok'}]\u001b[0m\n" + "\u001b[32m2024-05-07 15:51:56 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", + "\u001b[32m2024-05-07 15:52:25 INFO semantic_router.utils.logger LLM output: {\n", + "\t\"timezone\": \"Asia/Bangkok\"\n", + "}\u001b[0m\n", + "\u001b[32m2024-05-07 15:52:25 INFO semantic_router.utils.logger Function inputs: [{'timezone': 'Asia/Bangkok'}]\u001b[0m\n" ] }, { @@ -671,7 +756,7 @@ { "data": { "text/plain": [ - "'01:43'" + "'18:52'" ] }, "execution_count": 12, diff --git a/docs/06-threshold-optimization.ipynb b/docs/06-threshold-optimization.ipynb index 90786011a2213ff6f6efb949910fcfa075c14340..0d0ddf13195c7eb0ca27f3a93cb1ac1fb1b79547 100644 --- a/docs/06-threshold-optimization.ipynb +++ b/docs/06-threshold-optimization.ipynb @@ -147,7 +147,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-06 22:46:05 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 15:53:24 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], @@ -206,7 +206,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 76.92it/s]" + "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 76.91it/s]" ] }, { @@ -339,7 +339,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 9.52it/s]" + "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 9.23it/s]" ] }, { @@ -421,8 +421,8 @@ "name": "stderr", "output_type": "stream", "text": [ - "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 9.68it/s]\n", - "Training: 100%|██████████| 500/500 [00:01<00:00, 402.15it/s, acc=0.91]\n" + "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" ] } ], @@ -447,7 +447,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Updated route thresholds: {'politics': 0.07070707070707072, 'chitchat': 0.28350168350168353, 'mathematics': 0.16161616161616163, 'biology': 0.22222222222222224}\n" + "Updated route thresholds: {'politics': 0.05050505050505051, 'chitchat': 0.32323232323232326, 'mathematics': 0.18181818181818182, 'biology': 0.21212121212121213}\n" ] } ], @@ -474,21 +474,14 @@ "name": "stderr", "output_type": "stream", "text": [ - "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 8.89it/s]" + "Generating embeddings: 100%|██████████| 1/1 [00:00<00:00, 8.89it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Accuracy: 90.91%\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\n" + "Accuracy: 89.39%\n" ] } ], diff --git a/docs/07-multi-modal.ipynb b/docs/07-multi-modal.ipynb index f2112a95296ceb997910bf2b77b827f259acadac..3c4dd86776ecc12ac9a00481c4385fe982bd692f 100644 --- a/docs/07-multi-modal.ipynb +++ b/docs/07-multi-modal.ipynb @@ -60,6 +60,9 @@ "name": "stderr", "output_type": "stream", "text": [ + "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", "\n", "[notice] A new release of pip is available: 23.1.2 -> 24.0\n", "[notice] To update, run: python.exe -m pip install --upgrade pip\n" @@ -461,7 +464,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-06 22:49:05 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 15:57:45 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], diff --git a/docs/09-route-filter.ipynb b/docs/09-route-filter.ipynb index 4e1141446521e488c7de6bd841cfd6f2febbf321..202286fb3d48f8a795d3e7708c20287c0b1318d5 100644 --- a/docs/09-route-filter.ipynb +++ b/docs/09-route-filter.ipynb @@ -39,17 +39,7 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\n", - "[notice] A new release of pip is available: 23.1.2 -> 24.0\n", - "[notice] To update, run: python.exe -m pip install --upgrade pip\n" - ] - } - ], + "outputs": [], "source": [ "!pip install -qU semantic-router" ] @@ -162,7 +152,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-05-06 22:49:33 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 16:02:43 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], diff --git a/docs/examples/conversation-topic-splitter.ipynb b/docs/examples/conversation-topic-splitter.ipynb index 5ac130b0fcd8277f559606817a353e1b261f12f6..bb8eef03ec9736b96708193ffd6ad55af4a04c1e 100644 --- a/docs/examples/conversation-topic-splitter.ipynb +++ b/docs/examples/conversation-topic-splitter.ipynb @@ -48,7 +48,7 @@ "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", + "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" ] } @@ -249,7 +249,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.4" } }, "nbformat": 4, diff --git a/docs/examples/function_calling.ipynb b/docs/examples/function_calling.ipynb index 1aae719728c3e5c594bea3986b9c41e821dd17fa..e8ddd3ab7e12a3e9435871fe6797c5085001190f 100644 --- a/docs/examples/function_calling.ipynb +++ b/docs/examples/function_calling.ipynb @@ -54,7 +54,7 @@ { "data": { "text/plain": [ - "'05:44'" + "'12:59'" ] }, "execution_count": 2, @@ -70,7 +70,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now generate a dynamic routing config for each function" + "Define the LLM" ] }, { @@ -82,32 +82,56 @@ "name": "stderr", "output_type": "stream", "text": [ - "/Users/jakit/customers/aurelio/semantic-router/.venv/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", - "\u001b[32m2024-01-05 12:44:13 INFO semantic_router.utils.logger Generating dynamic route...\u001b[0m\n", - "\u001b[32m2024-01-05 12:44:16 INFO semantic_router.utils.logger Generated route config:\n", + "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" + ] + } + ], + "source": [ + "from semantic_router.llms import OpenAILLM\n", + "llm = OpenAILLM()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now generate a dynamic routing config for each function" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[32m2024-05-07 20:59:12 INFO semantic_router.utils.logger Generating dynamic route...\u001b[0m\n", + "\u001b[32m2024-05-07 20:59:15 INFO semantic_router.utils.logger Generated route config:\n", "{\n", - " \"name\": \"get_time\",\n", - " \"utterances\": [\n", - " \"What's the current time in New York?\",\n", - " \"Can you tell me the time in London?\",\n", - " \"What's the current time in Tokyo?\",\n", - " \"Can you give me the time in Sydney?\",\n", - " \"What's the current time in Berlin?\"\n", - " ]\n", - "}\u001b[0m\n", - "\u001b[32m2024-01-05 12:44:16 INFO semantic_router.utils.logger Generating dynamic route...\u001b[0m\n", - "\u001b[32m2024-01-05 12:44:19 INFO semantic_router.utils.logger Generated route config:\n", + " \"name\": \"get_time\",\n", + " \"utterances\": [\n", + " \"What time is it in New York?\",\n", + " \"Can you tell me the current time in London?\",\n", + " \"Get the time in Tokyo.\",\n", + " \"What's the time in Sydney?\",\n", + " \"Tell me the current time in Los Angeles.\"\n", + " ]\n", + " }\u001b[0m\n", + "\u001b[32m2024-05-07 20:59:15 INFO semantic_router.utils.logger Generating dynamic route...\u001b[0m\n", + "\u001b[32m2024-05-07 20:59:17 INFO semantic_router.utils.logger Generated route config:\n", "{\n", - " \"name\": \"get_news\",\n", - " \"utterances\": [\n", - " \"Tell me the latest news from the United States\",\n", - " \"What's happening in India today?\",\n", - " \"Can you give me the top stories from Japan\",\n", - " \"Get me the breaking news from the UK\",\n", - " \"What's the latest in Germany?\"\n", - " ]\n", - "}\u001b[0m\n" + " \"name\": \"get_news\",\n", + " \"utterances\": [\n", + " \"What's the latest news in the United States?\",\n", + " \"Tell me about the top headlines in Canada\",\n", + " \"Get me the news for technology in Japan\",\n", + " \"Show me the news for sports in Australia\",\n", + " \"Any updates on politics in the United Kingdom?\"\n", + " ]\n", + " }\u001b[0m\n" ] } ], @@ -119,13 +143,13 @@ "routes = []\n", "\n", "for function in functions:\n", - " route = Route.from_dynamic_route(entity=function)\n", + " route = Route.from_dynamic_route(llm=llm, entity=function)\n", " routes.append(route)" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -152,52 +176,62 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:44:23 INFO semantic_router.utils.logger Using default openai encoder: None\u001b[0m\n" + "\u001b[32m2024-05-07 20:59:18 INFO semantic_router.utils.logger Using default openai encoder: text-embedding-ada-002\u001b[0m\n" ] }, { "data": { "text/plain": [ "{'encoder_type': 'openai',\n", - " 'encoder_name': None,\n", + " 'encoder_name': 'text-embedding-ada-002',\n", " 'routes': [{'name': 'get_time',\n", - " 'utterances': [\"What's the current time in New York?\",\n", - " 'Can you tell me the time in London?',\n", - " \"What's the current time in Tokyo?\",\n", - " 'Can you give me the time in Sydney?',\n", - " \"What's the current time in Berlin?\"],\n", + " 'utterances': ['What time is it in New York?',\n", + " 'Can you tell me the current time in London?',\n", + " 'Get the time in Tokyo.',\n", + " \"What's the time in Sydney?\",\n", + " 'Tell me the current time in Los Angeles.'],\n", " 'description': None,\n", " 'function_schema': {'name': 'get_time',\n", " 'description': 'Finds the current time in a specific timezone.\\n\\n:param timezone: The timezone to find the current time in, should\\n be a valid timezone from the IANA Time Zone Database like\\n \"America/New_York\" or \"Europe/London\".\\n:type timezone: str\\n:return: The current time in the specified timezone.',\n", " 'signature': '(timezone: str) -> str',\n", - " 'output': \"<class 'str'>\"}},\n", + " 'output': \"<class 'str'>\"},\n", + " 'llm': {'module': 'semantic_router.llms.openai',\n", + " 'class': 'OpenAILLM',\n", + " 'model': 'gpt-3.5-turbo'},\n", + " 'score_threshold': None},\n", " {'name': 'get_news',\n", - " 'utterances': ['Tell me the latest news from the United States',\n", - " \"What's happening in India today?\",\n", - " 'Can you give me the top stories from Japan',\n", - " 'Get me the breaking news from the UK',\n", - " \"What's the latest in Germany?\"],\n", + " 'utterances': [\"What's the latest news in the United States?\",\n", + " 'Tell me about the top headlines in Canada',\n", + " 'Get me the news for technology in Japan',\n", + " 'Show me the news for sports in Australia',\n", + " 'Any updates on politics in the United Kingdom?'],\n", " 'description': None,\n", " 'function_schema': {'name': 'get_news',\n", " 'description': 'Useful to get the news in a specific country',\n", " 'signature': '(category: str, country: str) -> str',\n", - " 'output': \"<class 'str'>\"}},\n", + " 'output': \"<class 'str'>\"},\n", + " 'llm': {'module': 'semantic_router.llms.openai',\n", + " 'class': 'OpenAILLM',\n", + " 'model': 'gpt-3.5-turbo'},\n", + " 'score_threshold': None},\n", " {'name': 'get_weather',\n", " 'utterances': ['what is the weather in SF',\n", " 'what is the current temperature in London?',\n", " \"tomorrow's weather in Paris?\"],\n", " 'description': None,\n", - " 'function_schema': None}]}" + " 'function_schema': None,\n", + " 'llm': None,\n", + " 'score_threshold': None}]}" ] }, - "execution_count": 5, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -211,16 +245,16 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Route(name='get_time', utterances=[\"What's the current time in New York?\", 'Can you tell me the time in London?', \"What's the current time in Tokyo?\", 'Can you give me the time in Sydney?', \"What's the current time in Berlin?\"], description=None, function_schema={'name': 'get_time', 'description': 'Finds the current time in a specific timezone.\\n\\n:param timezone: The timezone to find the current time in, should\\n be a valid timezone from the IANA Time Zone Database like\\n \"America/New_York\" or \"Europe/London\".\\n:type timezone: str\\n:return: The current time in the specified timezone.', 'signature': '(timezone: str) -> str', 'output': \"<class 'str'>\"})" + "Route(name='get_time', utterances=['What time is it in New York?', 'Can you tell me the current time in London?', 'Get the time in Tokyo.', \"What's the time in Sydney?\", 'Tell me the current time in Los Angeles.'], description=None, function_schema={'name': 'get_time', 'description': 'Finds the current time in a specific timezone.\\n\\n:param timezone: The timezone to find the current time in, should\\n be a valid timezone from the IANA Time Zone Database like\\n \"America/New_York\" or \"Europe/London\".\\n:type timezone: str\\n:return: The current time in the specified timezone.', 'signature': '(timezone: str) -> str', 'output': \"<class 'str'>\"}, llm=OpenAILLM(name='gpt-3.5-turbo', client=<openai.OpenAI object at 0x0000025A67092E90>, temperature=0.01, max_tokens=200), score_threshold=None)" ] }, - "execution_count": 6, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -232,46 +266,54 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:44:32 INFO semantic_router.utils.logger Removed route `get_weather`\u001b[0m\n" + "\u001b[32m2024-05-07 20:59:18 INFO semantic_router.utils.logger Removed route `get_weather`\u001b[0m\n" ] }, { "data": { "text/plain": [ "{'encoder_type': 'openai',\n", - " 'encoder_name': None,\n", + " 'encoder_name': 'text-embedding-ada-002',\n", " 'routes': [{'name': 'get_time',\n", - " 'utterances': [\"What's the current time in New York?\",\n", - " 'Can you tell me the time in London?',\n", - " \"What's the current time in Tokyo?\",\n", - " 'Can you give me the time in Sydney?',\n", - " \"What's the current time in Berlin?\"],\n", + " 'utterances': ['What time is it in New York?',\n", + " 'Can you tell me the current time in London?',\n", + " 'Get the time in Tokyo.',\n", + " \"What's the time in Sydney?\",\n", + " 'Tell me the current time in Los Angeles.'],\n", " 'description': None,\n", " 'function_schema': {'name': 'get_time',\n", " 'description': 'Finds the current time in a specific timezone.\\n\\n:param timezone: The timezone to find the current time in, should\\n be a valid timezone from the IANA Time Zone Database like\\n \"America/New_York\" or \"Europe/London\".\\n:type timezone: str\\n:return: The current time in the specified timezone.',\n", " 'signature': '(timezone: str) -> str',\n", - " 'output': \"<class 'str'>\"}},\n", + " 'output': \"<class 'str'>\"},\n", + " 'llm': {'module': 'semantic_router.llms.openai',\n", + " 'class': 'OpenAILLM',\n", + " 'model': 'gpt-3.5-turbo'},\n", + " 'score_threshold': None},\n", " {'name': 'get_news',\n", - " 'utterances': ['Tell me the latest news from the United States',\n", - " \"What's happening in India today?\",\n", - " 'Can you give me the top stories from Japan',\n", - " 'Get me the breaking news from the UK',\n", - " \"What's the latest in Germany?\"],\n", + " 'utterances': [\"What's the latest news in the United States?\",\n", + " 'Tell me about the top headlines in Canada',\n", + " 'Get me the news for technology in Japan',\n", + " 'Show me the news for sports in Australia',\n", + " 'Any updates on politics in the United Kingdom?'],\n", " 'description': None,\n", " 'function_schema': {'name': 'get_news',\n", " 'description': 'Useful to get the news in a specific country',\n", " 'signature': '(category: str, country: str) -> str',\n", - " 'output': \"<class 'str'>\"}}]}" + " 'output': \"<class 'str'>\"},\n", + " 'llm': {'module': 'semantic_router.llms.openai',\n", + " 'class': 'OpenAILLM',\n", + " 'model': 'gpt-3.5-turbo'},\n", + " 'score_threshold': None}]}" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -291,14 +333,14 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:45:12 INFO semantic_router.utils.logger Saving route config to output/layer_config.json\u001b[0m\n" + "\u001b[32m2024-05-07 20:59:18 INFO semantic_router.utils.logger Saving route config to output/layer_config.json\u001b[0m\n" ] } ], @@ -322,15 +364,14 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:45:15 INFO semantic_router.utils.logger Loading route config from output/layer_config.json\u001b[0m\n", - "\u001b[32m2024-01-05 12:45:15 INFO semantic_router.utils.logger Using default openai encoder: None\u001b[0m\n" + "\u001b[32m2024-05-07 20:59:18 INFO semantic_router.utils.logger Loading route config from output/layer_config.json\u001b[0m\n" ] } ], @@ -356,7 +397,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:45:50 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" + "\u001b[32m2024-05-07 20:59:18 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], @@ -389,13 +430,17 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:45:53 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" + "\u001b[32m2024-05-07 20:59:19 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", + "\u001b[32m2024-05-07 20:59:20 INFO semantic_router.utils.logger LLM output: {\n", + "\t\"timezone\": \"Europe/Stockholm\"\n", + "}\u001b[0m\n", + "\u001b[32m2024-05-07 20:59:20 INFO semantic_router.utils.logger Function inputs: {'timezone': 'Europe/Stockholm'}\u001b[0m\n" ] }, { "data": { "text/plain": [ - "RouteChoice(name='get_time', function_call={'timezone': 'Europe/Stockholm'})" + "RouteChoice(name='get_time', function_call={'timezone': 'Europe/Stockholm'}, similarity_score=None)" ] }, "execution_count": 12, @@ -416,7 +461,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -430,7 +475,11 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:45:58 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" + "\u001b[32m2024-05-07 21:13:23 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", + "\u001b[32m2024-05-07 21:13:24 INFO semantic_router.utils.logger LLM output: {\n", + "\t\"timezone\": \"Europe/Stockholm\"\n", + "}\u001b[0m\n", + "\u001b[32m2024-05-07 21:13:24 INFO semantic_router.utils.logger Function inputs: {'timezone': 'Europe/Stockholm'}\u001b[0m\n" ] }, { @@ -438,7 +487,7 @@ "output_type": "stream", "text": [ "Invoked `get_time` function with timezone: `Europe/Stockholm`\n", - "11:46\n", + "19:13\n", "Query: What are the tech news in the US?\n" ] }, @@ -446,7 +495,12 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:46:00 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" + "\u001b[32m2024-05-07 21:13:24 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n", + "\u001b[32m2024-05-07 21:13:25 INFO semantic_router.utils.logger LLM output: {\n", + "\t\"category\": \"tech\",\n", + "\t\"country\": \"US\"\n", + "}\u001b[0m\n", + "\u001b[32m2024-05-07 21:13:25 INFO semantic_router.utils.logger Function inputs: {'category': 'tech', 'country': 'US'}\u001b[0m\n" ] }, { @@ -456,14 +510,19 @@ "Invoked: `get_news` function with category: `tech` and country: `US`\n", "Results from dummy news API\n", "Query: The capital of France?\n", - "The capital of France is Paris. It's a beautiful city known for its art, culture, and cuisine. Have you ever been there?\n" + "##################################################\n", + "query\n", + "The capital of France?\n", + "##################################################\n", + "Paris\n" ] } ], "source": [ "from semantic_router.schema import RouteChoice\n", - "from semantic_router.utils import llm\n", + "from semantic_router.schema import Message\n", "\n", + "llm = OpenAILLM()\n", "\n", "def route_and_execute(query, functions, layer):\n", " route_choice: RouteChoice = layer(query)\n", @@ -474,7 +533,14 @@ " return function(**route_choice.function_call)\n", "\n", " # If no function is found, use the LLM for general queries\n", - " return llm.llm(query)\n", + " # DEBUGGING: Start.\n", + " print('#'*50)\n", + " print('query')\n", + " print(query)\n", + " print('#'*50)\n", + " # DEBUGGING: End.\n", + " msgs = [Message(role=\"user\", content=query)]\n", + " return llm(msgs)\n", "\n", "\n", "queries = [\n", @@ -512,7 +578,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.18" + "version": "3.11.4" } }, "nbformat": 4, diff --git a/docs/examples/hybrid-layer.ipynb b/docs/examples/hybrid-layer.ipynb index 0dd149b9456453114888105c9830761e354748ba..0ea545299a7f17b2ee91cf6b88fde01b9d0375be 100644 --- a/docs/examples/hybrid-layer.ipynb +++ b/docs/examples/hybrid-layer.ipynb @@ -48,7 +48,16 @@ "cell_type": "code", "execution_count": 2, "metadata": {}, - "outputs": [], + "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" + ] + } + ], "source": [ "from semantic_router.route import Route\n", "\n", @@ -145,14 +154,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-08 16:50:29 INFO semantic_router.utils.logger Creating embeddings for all routes...\u001b[0m\n" + "\u001b[32m2024-05-07 21:15:31 INFO semantic_router.utils.logger Creating embeddings for all routes...\u001b[0m\n" ] } ], @@ -160,13 +169,13 @@ "from semantic_router.hybrid_layer import HybridRouteLayer\n", "\n", "dl = HybridRouteLayer(\n", - " dense_encoder=dense_encoder, sparse_encoder=sparse_encoder, routes=routes\n", + " encoder=dense_encoder, sparse_encoder=sparse_encoder, routes=routes\n", ")" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -175,7 +184,7 @@ "'politics'" ] }, - "execution_count": 6, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -186,7 +195,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -195,7 +204,7 @@ "'chitchat'" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -228,7 +237,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.11.4" } }, "nbformat": 4, diff --git a/docs/examples/ollama-local-execution.ipynb b/docs/examples/ollama-local-execution.ipynb index 2ed7acdefb0927cb2dc74d4fab32887bb8f0e2b7..5193a304192b752b99e986dca8c6b40850c74664 100644 --- a/docs/examples/ollama-local-execution.ipynb +++ b/docs/examples/ollama-local-execution.ipynb @@ -34,100 +34,18 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: semantic_router[local]==0.0.23 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (0.0.23)\n", - "Requirement already satisfied: pillow in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (10.2.0)\n", - "Requirement already satisfied: torch in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (2.2.0)\n", - "Requirement already satisfied: transformers in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (4.38.0)\n", - "Requirement already satisfied: black<24.0.0,>=23.12.1 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from semantic_router[local]==0.0.23) (23.12.1)\n", - "Requirement already satisfied: cohere<5.0,>=4.32 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from semantic_router[local]==0.0.23) (4.47)\n", - "Requirement already satisfied: colorama<0.5.0,>=0.4.6 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from semantic_router[local]==0.0.23) (0.4.6)\n", - "Requirement already satisfied: colorlog<7.0.0,>=6.8.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from semantic_router[local]==0.0.23) (6.8.2)\n", - "Requirement already satisfied: llama-cpp-python<0.3.0,>=0.2.28 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from semantic_router[local]==0.0.23) (0.2.45)\n", - "Requirement already satisfied: mistralai<0.0.13,>=0.0.12 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from semantic_router[local]==0.0.23) (0.0.12)\n", - "Requirement already satisfied: numpy<2.0.0,>=1.25.2 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from semantic_router[local]==0.0.23) (1.26.4)\n", - "Requirement already satisfied: openai<2.0.0,>=1.10.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from semantic_router[local]==0.0.23) (1.12.0)\n", - "Requirement already satisfied: pydantic<3.0.0,>=2.5.3 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from semantic_router[local]==0.0.23) (2.6.1)\n", - "Requirement already satisfied: pyyaml<7.0.0,>=6.0.1 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from semantic_router[local]==0.0.23) (6.0.1)\n", - "Requirement already satisfied: filelock in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from torch) (3.13.1)\n", - "Requirement already satisfied: typing-extensions>=4.8.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from torch) (4.9.0)\n", - "Requirement already satisfied: sympy in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from torch) (1.12)\n", - "Requirement already satisfied: networkx in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from torch) (3.2.1)\n", - "Requirement already satisfied: jinja2 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from torch) (3.1.3)\n", - "Requirement already satisfied: fsspec in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from torch) (2024.2.0)\n", - "Requirement already satisfied: huggingface-hub<1.0,>=0.19.3 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from transformers) (0.20.3)\n", - "Requirement already satisfied: packaging>=20.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from transformers) (23.2)\n", - "Requirement already satisfied: regex!=2019.12.17 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from transformers) (2023.12.25)\n", - "Requirement already satisfied: requests in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from transformers) (2.31.0)\n", - "Requirement already satisfied: tokenizers<0.19,>=0.14 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from transformers) (0.15.2)\n", - "Requirement already satisfied: safetensors>=0.4.1 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from transformers) (0.4.2)\n", - "Requirement already satisfied: tqdm>=4.27 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from transformers) (4.66.2)\n", - "Requirement already satisfied: click>=8.0.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (8.1.7)\n", - "Requirement already satisfied: mypy-extensions>=0.4.3 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (1.0.0)\n", - "Requirement already satisfied: pathspec>=0.9.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (0.12.1)\n", - "Requirement already satisfied: platformdirs>=2 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (4.2.0)\n", - "Requirement already satisfied: aiohttp<4.0,>=3.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (3.9.3)\n", - "Requirement already satisfied: backoff<3.0,>=2.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (2.2.1)\n", - "Requirement already satisfied: fastavro<2.0,>=1.8 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.9.4)\n", - "Requirement already satisfied: importlib_metadata<7.0,>=6.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (6.11.0)\n", - "Requirement already satisfied: urllib3<3,>=1.26 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (2.2.1)\n", - "Requirement already satisfied: diskcache>=5.6.1 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from llama-cpp-python<0.3.0,>=0.2.28->semantic_router[local]==0.0.23) (5.6.3)\n", - "Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from jinja2->torch) (2.1.5)\n", - "Requirement already satisfied: httpx<0.26.0,>=0.25.2 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (0.25.2)\n", - "Requirement already satisfied: orjson<4.0.0,>=3.9.10 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (3.9.14)\n", - "Requirement already satisfied: anyio<5,>=3.5.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from openai<2.0.0,>=1.10.0->semantic_router[local]==0.0.23) (4.2.0)\n", - "Requirement already satisfied: distro<2,>=1.7.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from openai<2.0.0,>=1.10.0->semantic_router[local]==0.0.23) (1.9.0)\n", - "Requirement already satisfied: sniffio in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from openai<2.0.0,>=1.10.0->semantic_router[local]==0.0.23) (1.3.0)\n", - "Requirement already satisfied: annotated-types>=0.4.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from pydantic<3.0.0,>=2.5.3->semantic_router[local]==0.0.23) (0.6.0)\n", - "Requirement already satisfied: pydantic-core==2.16.2 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from pydantic<3.0.0,>=2.5.3->semantic_router[local]==0.0.23) (2.16.2)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from requests->transformers) (3.3.2)\n", - "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from requests->transformers) (3.6)\n", - "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from requests->transformers) (2024.2.2)\n", - "Requirement already satisfied: mpmath>=0.19 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from sympy->torch) (1.3.0)\n", - "Requirement already satisfied: aiosignal>=1.1.2 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.3.1)\n", - "Requirement already satisfied: attrs>=17.3.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (23.2.0)\n", - "Requirement already satisfied: frozenlist>=1.1.1 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.4.1)\n", - "Requirement already satisfied: multidict<7.0,>=4.5 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (6.0.5)\n", - "Requirement already satisfied: yarl<2.0,>=1.0 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.9.4)\n", - "Requirement already satisfied: httpcore==1.* in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from httpx<0.26.0,>=0.25.2->mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (1.0.3)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from httpcore==1.*->httpx<0.26.0,>=0.25.2->mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (0.14.0)\n", - "Requirement already satisfied: zipp>=0.5 in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\20240123 semantic router\\venvs\\semantic_router\\lib\\site-packages (from importlib_metadata<7.0,>=6.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (3.17.0)\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\n", - "[notice] A new release of pip is available: 23.1.2 -> 24.0\n", - "[notice] To update, run: python.exe -m pip install --upgrade pip\n" - ] - } - ], + "outputs": [], "source": [ - "!pip install -qU \"semantic_router[local]==0.0.28\"" + "# !pip install -qU \"semantic_router[local]==0.0.28\"" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "c:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\20240123 Semantic Router\\venvs\\semantic_router\\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.encoders import HuggingFaceEncoder\n", "\n", @@ -143,7 +61,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -187,17 +105,9 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m2024-02-22 10:59:54 INFO semantic_router.utils.logger local\u001b[0m\n" - ] - } - ], + "outputs": [], "source": [ "from semantic_router.layer import RouteLayer\n", "from semantic_router.llms.ollama import OllamaLLM\n", @@ -218,47 +128,25 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'politics'" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "rl(\"don't you love politics?\").name" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'chitchat'" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "rl(\"how's the weather today?\").name" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -287,7 +175,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -313,43 +201,18 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'01:59'" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "get_time(\"America/New_York\")" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'name': 'get_time',\n", - " 'description': 'Finds the current time in a specific timezone.\\n\\n:param timezone: The timezone to find the current time in, should\\n be a valid timezone from the IANA Time Zone Database like\\n \"America/New_York\" or \"Europe/London\". Do NOT put the place\\n name itself like \"rome\", or \"new york\", you must provide\\n the IANA format.\\n:type timezone: str\\n:return: The current time in the specified timezone.\\n ',\n", - " 'signature': '(timezone: str) -> str',\n", - " 'output': \"<class 'str'>\"}" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from semantic_router.utils.function_call import get_schema\n", "\n", @@ -359,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -376,51 +239,18 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m2024-02-22 10:59:55 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n" - ] - } - ], + "outputs": [], "source": [ "rl.add(time_route)" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m2024-02-22 11:01:29 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m2024-02-22 11:01:32 INFO semantic_router.utils.logger LLM output: {\n", - " \"timezone\": \"America/New_York\"\n", - "}\u001b[0m\n", - "\u001b[32m2024-02-22 11:01:32 INFO semantic_router.utils.logger Function inputs: {'timezone': 'America/New_York'}\u001b[0m\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "name='get_time' function_call={'timezone': 'America/New_York'} similarity_score=None trigger=None\n" - ] - } - ], + "outputs": [], "source": [ "out = rl(\"what is the time in new york city?\")\n", "print(out)" @@ -428,20 +258,9 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'02:01'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "get_time(**out.function_call)" ] diff --git a/docs/examples/pinecone-and-scaling.ipynb b/docs/examples/pinecone-and-scaling.ipynb index 8b11c661f70722f5616157bdc6edaba870973eca..a9e4a3895248ba0d34015aa1f43f6de0676c7ddf 100644 --- a/docs/examples/pinecone-and-scaling.ipynb +++ b/docs/examples/pinecone-and-scaling.ipynb @@ -38,15 +38,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "id": "dLElfRhgur0v" }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~rotobuf (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~rotobuf (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~rotobuf (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~illow (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "WARNING: Ignoring invalid distribution ~rotobuf (C:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages)\n", + "\n", + "[notice] A new release of pip is available: 23.1.2 -> 24.0\n", + "[notice] To update, run: python.exe -m pip install --upgrade pip\n" + ] + } + ], "source": [ - "# !pip install -qU \\\n", - "# \"semantic-router[local, pinecone]==0.0.22\" \\\n", - "# datasets==2.17.0" + "!pip install -qU \\\n", + " \"semantic-router[local, pinecone]==0.0.22\" \\\n", + " datasets==2.17.0" ] }, { @@ -58,9 +76,17 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "metadata": {}, "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" + ] + }, { "data": { "text/plain": [ @@ -70,7 +96,7 @@ "})" ] }, - "execution_count": 6, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -91,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -109,7 +135,7 @@ " 'score_threshold': 0.82}" ] }, - "execution_count": 7, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -127,7 +153,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -136,7 +162,7 @@ "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, score_threshold=0.82)" ] }, - "execution_count": 8, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -157,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -165,7 +191,16 @@ "id": "BI9AiDspur0y", "outputId": "27329a54-3f16-44a5-ac20-13a6b26afb97" }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "c:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\Virtual Environments\\semantic_router_3\\Lib\\site-packages\\huggingface_hub\\file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n", + " warnings.warn(\n" + ] + } + ], "source": [ "from semantic_router.encoders import HuggingFaceEncoder\n", "\n", @@ -181,9 +216,17 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[33m2024-05-07 21:33:48 WARNING semantic_router.utils.logger Index could not be initialized.\u001b[0m\n" + ] + } + ], "source": [ "import os\n", "from getpass import getpass\n", @@ -198,14 +241,14 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-04-15 01:56:59 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 21:33:48 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], @@ -226,7 +269,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -236,14 +279,12 @@ }, "outputs": [ { - "data": { - "text/plain": [ - "'chitchat'" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[33m2024-05-07 21:33:57 WARNING semantic_router.utils.logger No classification found for semantic classifier.\u001b[0m\n", + "\u001b[31m2024-05-07 21:33:57 ERROR semantic_router.utils.logger No route found with name . Check to see if any Routes have been defined.\u001b[0m\n" + ] } ], "source": [ @@ -279,7 +320,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "5jaF1Xa5ur0y" }, @@ -297,7 +338,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -313,180 +354,180 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[('cybersecurity_best_practices',\n", - " 'introduction to ethical hacking for developers'),\n", - " ('coding_standards_and_conventions', 'JavaScript coding conventions'),\n", - " ('chitchat', 'lovely weather today'),\n", - " ('cybersecurity_best_practices', 'securing your web applications'),\n", - " ('gaming_and_esports', 'what are the popular games right now?'),\n", - " ('compliments', 'say something nice about me'),\n", - " ('jokes', 'know any good jokes?'),\n", - " ('data_structures_and_algorithms', 'algorithms every developer should know'),\n", - " ('data_structures_and_algorithms', 'basic data structures for beginners'),\n", - " ('interview_preparation', 'how to prepare for a coding interview'),\n", - " ('career_advice', 'suggest some career development tips'),\n", - " ('creative_writing_and_literature', 'how can I improve my writing skills?'),\n", - " ('art_and_culture', 'tell me about your favorite artist'),\n", - " ('language_learning', 'suggest ways to learn a new language'),\n", - " ('fitness_tips', 'suggest a workout routine'),\n", - " ('mental_health_support', 'what are ways to improve mental health?'),\n", - " ('daily_inspiration', 'I need some inspiration for today'),\n", - " ('compliments', 'give me a compliment'),\n", - " ('gardening_and_horticulture', 'suggest some easy-care indoor plants'),\n", - " ('career_advice_in_tech',\n", - " 'how to build a portfolio for software development'),\n", - " ('astronomy_and_space_exploration', 'tell me about the latest space mission'),\n", - " ('hobbies_and_interests', 'suggest me a hobby'),\n", - " ('creative_writing_and_literature', 'what are some tips for storytelling?'),\n", - " ('art_and_culture', \"what's an interesting cultural tradition?\"),\n", - " ('ethical_considerations_in_tech',\n", - " 'the role of ethics in artificial intelligence'),\n", - " ('development_tools', 'using Docker in development'),\n", - " ('career_advice', 'how can I improve my resume?'),\n", - " ('jokes', 'tell me a joke'),\n", - " ('environmental_awareness', 'how can I be more eco-friendly?'),\n", - " ('cloud_computing', 'introduction to cloud storage options'),\n", - " ('cloud_computing', 'AWS vs Azure vs Google Cloud'),\n", - " ('mindfulness_and_wellness', 'tell me about mindfulness'),\n", - " ('frameworks_and_libraries', 'introduction to Django for web development'),\n", + "[('fitness_tips', 'suggest a workout routine'),\n", " ('career_advice', 'what are the emerging career fields?'),\n", - " ('daily_inspiration', 'share something uplifting'),\n", - " ('gaming_and_esports', 'suggest a good game for beginners'),\n", - " ('chitchat', 'how are things going?'),\n", - " ('historical_events', 'share an interesting piece of medieval history'),\n", - " ('mental_health_support', 'share some self-care practices'),\n", - " ('environmental_awareness', 'what are some ways to save the planet?'),\n", " ('mental_health_support', 'how can I manage stress?'),\n", + " ('gardening_and_horticulture', 'suggest some easy-care indoor plants'),\n", + " ('fitness_tips', 'give me a fitness tip'),\n", + " ('debugging_tips', 'tips for debugging asynchronous code'),\n", + " ('historical_events', 'share an interesting piece of medieval history'),\n", + " ('chitchat', 'the weather is horrendous'),\n", + " ('art_and_culture', 'suggest some must-visit museums'),\n", + " ('daily_inspiration', 'I need some inspiration for today'),\n", + " ('language_learning', 'suggest ways to learn a new language'),\n", + " ('creative_writing_and_literature', 'how can I improve my writing skills?'),\n", + " ('cloud_computing', 'AWS vs Azure vs Google Cloud'),\n", " ('language_learning', 'how can I improve my Spanish?'),\n", " ('career_advice_in_tech', 'navigating career growth in tech'),\n", + " ('creative_writing_and_literature', 'what are some tips for storytelling?'),\n", + " ('data_structures_and_algorithms', 'algorithms every developer should know'),\n", + " ('historical_events', 'tell me about a significant historical event'),\n", + " ('gaming_and_esports', 'suggest a good game for beginners'),\n", + " ('art_and_culture', \"what's an interesting cultural tradition?\"),\n", + " ('environmental_awareness', 'tell me about sustainability practices'),\n", + " ('food_and_recipes', \"what's your favorite food?\"),\n", + " ('jokes', 'tell me a joke'),\n", + " ('frameworks_and_libraries', 'best Python libraries for data analysis'),\n", " ('cloud_computing', 'best practices for cloud security'),\n", - " ('fitness_tips', 'give me a fitness tip'),\n", + " ('development_tools', 'using Docker in development'),\n", + " ('frameworks_and_libraries',\n", + " \"what's the difference between React and Angular?\"),\n", + " ('gardening_and_horticulture', 'how do I start a vegetable garden?'),\n", + " ('language_syntax', 'what are the new features in Java 15?'),\n", + " ('coding_standards_and_conventions', 'JavaScript coding conventions'),\n", " ('machine_learning_in_development',\n", " 'how to start with machine learning in Python'),\n", - " ('cybersecurity_best_practices', 'common security vulnerabilities to avoid'),\n", - " ('chitchat', \"how's the weather today?\"),\n", - " ('fitness_tips', 'how can I stay active at home?'),\n", - " ('gardening_and_horticulture', 'how do I start a vegetable garden?'),\n", - " ('interview_preparation', 'common programming interview questions'),\n", - " ('environmental_awareness', 'tell me about sustainability practices'),\n", - " ('art_and_culture', 'suggest some must-visit museums'),\n", - " ('development_tools', 'recommendations for Python IDEs'),\n", - " ('development_tools', 'best Git clients for macOS'),\n", - " ('coding_standards_and_conventions', 'maintaining consistency in codebase'),\n", - " ('ethical_considerations_in_tech', 'ethical hacking and its importance'),\n", - " ('data_structures_and_algorithms', 'complexity analysis of algorithms'),\n", - " ('food_and_recipes', 'tell me about a dish from your country'),\n", - " ('coding_standards_and_conventions', 'why coding standards matter'),\n", - " ('career_advice_in_tech', 'tips for landing your first tech job'),\n", - " ('chitchat', \"let's go to the chippy\"),\n", - " ('historical_events', 'tell me about a significant historical event'),\n", - " ('food_and_recipes', \"what's your favorite food?\"),\n", - " ('hobbies_and_interests', \"I'm looking for a new pastime\"),\n", - " ('astronomy_and_space_exploration', 'how can I stargaze effectively?'),\n", - " ('food_and_recipes', 'suggest a recipe for dinner'),\n", - " ('debugging_tips', 'tips for debugging asynchronous code'),\n", - " ('best_practices', 'how to write clean code in Python'),\n", + " ('frameworks_and_libraries', 'introduction to Django for web development'),\n", " ('jokes', 'make me laugh'),\n", - " ('language_syntax', 'how do closures work in JavaScript?'),\n", - " ('book_recommendations', 'suggest a good book to read'),\n", - " ('language_syntax', 'explain the syntax of Python functions'),\n", - " ('best_practices', 'what are the best practices for REST API design?'),\n", - " ('book_recommendations', 'I need a book recommendation'),\n", - " ('astronomy_and_space_exploration',\n", - " 'what are some interesting facts about the universe?'),\n", + " ('historical_events', 'who was a notable figure in ancient history?'),\n", + " ('daily_inspiration', 'give me an inspirational quote'),\n", + " ('compliments', 'I need some positive vibes'),\n", + " ('jokes', 'know any good jokes?'),\n", + " ('ethical_considerations_in_tech',\n", + " 'the role of ethics in artificial intelligence'),\n", " ('gaming_and_esports', 'tell me about upcoming esports events'),\n", - " ('interview_preparation', 'tips for technical interviews'),\n", - " ('debugging_tips', 'best tools for JavaScript debugging'),\n", - " ('mindfulness_and_wellness', 'give me a wellness tip'),\n", + " ('food_and_recipes', 'suggest a recipe for dinner'),\n", + " ('best_practices', 'how to write clean code in Python'),\n", + " ('data_structures_and_algorithms', 'complexity analysis of algorithms'),\n", + " ('interview_preparation', 'common programming interview questions'),\n", + " ('book_recommendations', \"what's your favorite book?\"),\n", + " ('gaming_and_esports', 'what are the popular games right now?'),\n", " ('debugging_tips', 'how do I debug segmentation faults in C++?'),\n", - " ('historical_events', 'who was a notable figure in ancient history?'),\n", + " ('creative_writing_and_literature', 'suggest some classic literature'),\n", + " ('art_and_culture', 'tell me about your favorite artist'),\n", + " ('career_advice', 'suggest some career development tips'),\n", " ('language_learning',\n", " 'what are some effective language learning techniques?'),\n", - " ('compliments', 'I need some positive vibes'),\n", - " ('frameworks_and_libraries',\n", - " \"what's the difference between React and Angular?\"),\n", - " ('chitchat', 'the weather is horrendous'),\n", - " ('educational_facts', 'do you know any historical trivia?'),\n", + " ('astronomy_and_space_exploration',\n", + " 'what are some interesting facts about the universe?'),\n", + " ('educational_facts', 'tell me an interesting fact'),\n", + " ('chitchat', \"let's go to the chippy\"),\n", + " ('astronomy_and_space_exploration', 'tell me about the latest space mission'),\n", + " ('book_recommendations', 'I need a book recommendation'),\n", + " ('data_structures_and_algorithms', 'basic data structures for beginners'),\n", + " ('interview_preparation', 'how to prepare for a coding interview'),\n", + " ('career_advice_in_tech', 'tips for landing your first tech job'),\n", + " ('compliments', 'say something nice about me'),\n", + " ('cybersecurity_best_practices', 'securing your web applications'),\n", + " ('chitchat', \"how's the weather today?\"),\n", + " ('ethical_considerations_in_tech', 'ethical hacking and its importance'),\n", + " ('mindfulness_and_wellness', 'tell me about mindfulness'),\n", + " ('debugging_tips', 'best tools for JavaScript debugging'),\n", + " ('best_practices', 'what are the best practices for REST API design?'),\n", + " ('hobbies_and_interests', 'suggest me a hobby'),\n", + " ('cybersecurity_best_practices', 'common security vulnerabilities to avoid'),\n", + " ('language_syntax', 'how do closures work in JavaScript?'),\n", + " ('hobbies_and_interests', \"I'm looking for a new pastime\"),\n", " ('machine_learning_in_development', 'using TensorFlow for beginners'),\n", - " ('educational_facts', 'share a science fact'),\n", + " ('mindfulness_and_wellness', 'how can I relax?'),\n", " ('gardening_and_horticulture',\n", " 'what are some tips for sustainable gardening?'),\n", - " ('daily_inspiration', 'give me an inspirational quote'),\n", - " ('book_recommendations', \"what's your favorite book?\"),\n", - " ('best_practices', 'best practices for error handling in JavaScript'),\n", - " ('educational_facts', 'tell me an interesting fact'),\n", + " ('career_advice', 'how can I improve my resume?'),\n", + " ('development_tools', 'best Git clients for macOS'),\n", + " ('food_and_recipes', 'tell me about a dish from your country'),\n", + " ('development_tools', 'recommendations for Python IDEs'),\n", + " ('environmental_awareness', 'how can I be more eco-friendly?'),\n", + " ('ethical_considerations_in_tech', 'privacy concerns in app development'),\n", + " ('environmental_awareness', 'what are some ways to save the planet?'),\n", " ('machine_learning_in_development',\n", " 'machine learning model deployment best practices'),\n", - " ('frameworks_and_libraries', 'best Python libraries for data analysis'),\n", + " ('chitchat', 'lovely weather today'),\n", + " ('language_syntax', 'explain the syntax of Python functions'),\n", + " ('educational_facts', 'share a science fact'),\n", + " ('best_practices', 'best practices for error handling in JavaScript'),\n", + " ('cloud_computing', 'introduction to cloud storage options'),\n", + " ('compliments', 'give me a compliment'),\n", + " ('career_advice_in_tech',\n", + " 'how to build a portfolio for software development'),\n", + " ('book_recommendations', 'suggest a good book to read'),\n", + " ('daily_inspiration', 'share something uplifting'),\n", + " ('mental_health_support', 'share some self-care practices'),\n", + " ('coding_standards_and_conventions', 'why coding standards matter'),\n", + " ('chitchat', 'how are things going?'),\n", + " ('cybersecurity_best_practices',\n", + " 'introduction to ethical hacking for developers'),\n", + " ('astronomy_and_space_exploration', 'how can I stargaze effectively?'),\n", + " ('fitness_tips', 'how can I stay active at home?'),\n", + " ('mental_health_support', 'what are ways to improve mental health?'),\n", + " ('interview_preparation', 'tips for technical interviews'),\n", " ('hobbies_and_interests', 'what are your interests?'),\n", - " ('creative_writing_and_literature', 'suggest some classic literature'),\n", - " ('language_syntax', 'what are the new features in Java 15?'),\n", - " ('ethical_considerations_in_tech', 'privacy concerns in app development'),\n", + " ('coding_standards_and_conventions', 'maintaining consistency in codebase'),\n", + " ('educational_facts', 'do you know any historical trivia?'),\n", + " ('programming_challenges', 'programming tasks to improve problem-solving'),\n", + " ('web_development_trends', 'the future of web development'),\n", + " ('mobile_app_development', 'optimizing performance in mobile apps'),\n", + " ('project_management_in_tech', 'agile vs waterfall project management'),\n", + " ('motivation', 'I need some motivation'),\n", + " ('version_control_systems', 'how to revert a commit in Git'),\n", + " ('project_management_in_tech', 'tools for managing tech projects'),\n", + " ('pet_care_advice', 'how can I train my dog?'),\n", + " ('version_control_systems', 'best practices for branching in Git'),\n", + " ('version_control_systems', 'introduction to SVN for beginners'),\n", + " ('movie_suggestions', 'recommend a movie'),\n", + " ('travel_stories', 'tell me about your favorite travel destination'),\n", " ('software_architecture', 'differences between MVC and MVVM'),\n", - " ('motivation', 'give me a motivational quote'),\n", - " ('open_source_contributions', 'how to start contributing to open source'),\n", - " ('tech_trends', \"what's new in technology?\"),\n", + " ('movie_suggestions', \"what's your favorite movie?\"),\n", + " ('pet_care_advice', 'suggest some tips for cat care'),\n", + " ('web_development_trends', 'emerging back-end technologies'),\n", + " ('movie_suggestions', 'suggest a good movie for tonight'),\n", + " ('tech_trends', 'tell me about the latest gadgets'),\n", + " ('philosophical_questions', 'do you believe in fate?'),\n", + " ('philosophical_questions', 'what are your thoughts on free will?'),\n", + " ('programming_challenges', 'where can I find algorithmic puzzles?'),\n", " ('software_architecture', 'explain microservices architecture'),\n", + " ('politics',\n", + " \"don't you just love the presidentdon't you just hate the president\"),\n", + " ('motivation', 'give me a motivational quote'),\n", " ('personal_questions', 'what do you like to do for fun?'),\n", - " ('movie_suggestions', 'suggest a good movie for tonight'),\n", - " ('programming_challenges', 'suggest a coding challenge for beginners'),\n", - " ('movie_suggestions', 'recommend a movie'),\n", - " ('web_development_trends', \"what's new in front-end development?\"),\n", - " ('politics', \"they're going to destroy this country!\"),\n", - " ('web_development_trends', 'emerging back-end technologies'),\n", - " ('personal_questions', 'do you have any hobbies?'),\n", - " ('version_control_systems', 'best practices for branching in Git'),\n", - " ('science_and_innovation', 'what are the latest scientific discoveries?'),\n", + " ('open_source_contributions', 'finding projects that accept contributions'),\n", + " ('science_and_innovation', 'how does AI impact our daily lives?'),\n", + " ('tech_trends', \"what's new in technology?\"),\n", + " ('software_architecture', 'introduction to domain-driven design'),\n", " ('motivation', 'inspire me'),\n", - " ('mobile_app_development', 'optimizing performance in mobile apps'),\n", - " ('mobile_app_development', 'Kotlin vs Swift for mobile development'),\n", - " ('programming_challenges', 'where can I find algorithmic puzzles?'),\n", + " ('programming_challenges', 'suggest a coding challenge for beginners'),\n", + " ('science_and_innovation', 'tell me about a recent innovation'),\n", " ('open_source_contributions', 'best practices for open-source contributors'),\n", - " ('tech_trends', 'what are the emerging tech trends?'),\n", - " ('travel_stories', 'tell me about your favorite travel destination'),\n", - " ('pet_care_advice', 'what should I know about keeping a pet rabbit?'),\n", - " ('philosophical_questions', 'what are your thoughts on free will?'),\n", - " ('pet_care_advice', 'how can I train my dog?'),\n", + " ('mindfulness_and_wellness', 'give me a wellness tip'),\n", + " ('mobile_app_development', 'Kotlin vs Swift for mobile development'),\n", " ('personal_questions', \"what's your favorite color?\"),\n", - " ('travel_stories', 'share a travel story'),\n", - " ('music_discovery', 'recommend songs for a workout playlist'),\n", - " ('science_and_innovation', 'tell me about a recent innovation'),\n", - " ('pet_care_advice', 'suggest some tips for cat care'),\n", - " ('travel_stories', \"what's the most interesting place you've visited?\"),\n", - " ('open_source_contributions', 'finding projects that accept contributions'),\n", - " ('version_control_systems', 'how to revert a commit in Git'),\n", - " ('music_discovery', 'who are the top artists right now?'),\n", - " ('philosophical_questions', 'what is the meaning of life?'),\n", - " ('philosophical_questions', 'do you believe in fate?'),\n", - " ('version_control_systems', 'introduction to SVN for beginners'),\n", - " ('tech_trends', 'tell me about the latest gadgets'),\n", + " ('pet_care_advice', 'what should I know about keeping a pet rabbit?'),\n", + " ('personal_questions', 'do you have any hobbies?'),\n", " ('music_discovery', 'suggest some new music'),\n", - " ('mobile_app_development',\n", - " 'best tools for cross-platform mobile development'),\n", " ('politics', 'they will save the country!'),\n", - " ('project_management_in_tech', 'tools for managing tech projects'),\n", - " ('motivation', 'I need some motivation'),\n", - " ('politics',\n", - " \"don't you just love the presidentdon't you just hate the president\"),\n", + " ('tech_trends', 'what are the emerging tech trends?'),\n", + " ('travel_stories', \"what's the most interesting place you've visited?\"),\n", " ('project_management_in_tech', 'how to lead a development team'),\n", + " ('music_discovery', 'who are the top artists right now?'),\n", + " ('music_discovery', 'recommend songs for a workout playlist'),\n", + " ('open_source_contributions', 'how to start contributing to open source'),\n", + " ('philosophical_questions', 'what is the meaning of life?'),\n", " ('politics', \"why don't you tell me about your political opinions\"),\n", + " ('science_and_innovation', 'what are the latest scientific discoveries?'),\n", " ('politics', \"isn't politics the best thing ever\"),\n", - " ('web_development_trends', 'the future of web development'),\n", - " ('mindfulness_and_wellness', 'how can I relax?'),\n", - " ('programming_challenges', 'programming tasks to improve problem-solving'),\n", - " ('movie_suggestions', \"what's your favorite movie?\"),\n", - " ('software_architecture', 'introduction to domain-driven design'),\n", - " ('science_and_innovation', 'how does AI impact our daily lives?'),\n", - " ('project_management_in_tech', 'agile vs waterfall project management')]" + " ('politics', \"they're going to destroy this country!\"),\n", + " ('travel_stories', 'share a travel story'),\n", + " ('mobile_app_development',\n", + " 'best tools for cross-platform mobile development'),\n", + " ('web_development_trends', \"what's new in front-end development?\")]" ] }, - "execution_count": 2, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -504,7 +545,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -517,167 +558,167 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'fitness_tips': ['give me a fitness tip',\n", - " 'suggest a workout routine',\n", - " 'how can I stay active at home?'],\n", - " 'language_learning': ['how can I improve my Spanish?',\n", - " 'what are some effective language learning techniques?',\n", - " 'suggest ways to learn a new language'],\n", - " 'frameworks_and_libraries': ['introduction to Django for web development',\n", - " \"what's the difference between React and Angular?\",\n", - " 'best Python libraries for data analysis'],\n", - " 'book_recommendations': [\"what's your favorite book?\",\n", - " 'suggest a good book to read',\n", - " 'I need a book recommendation'],\n", - " 'coding_standards_and_conventions': ['JavaScript coding conventions',\n", - " 'maintaining consistency in codebase',\n", - " 'why coding standards matter'],\n", - " 'historical_events': ['share an interesting piece of medieval history',\n", - " 'who was a notable figure in ancient history?',\n", - " 'tell me about a significant historical event'],\n", - " 'ethical_considerations_in_tech': ['ethical hacking and its importance',\n", - " 'the role of ethics in artificial intelligence',\n", - " 'privacy concerns in app development'],\n", - " 'jokes': ['make me laugh', 'tell me a joke', 'know any good jokes?'],\n", - " 'chitchat': [\"let's go to the chippy\",\n", - " 'how are things going?',\n", - " 'the weather is horrendous',\n", + "{'book_recommendations': ['suggest a good book to read',\n", + " 'I need a book recommendation',\n", + " \"what's your favorite book?\"],\n", + " 'chitchat': ['lovely weather today',\n", " \"how's the weather today?\",\n", - " 'lovely weather today'],\n", - " 'environmental_awareness': ['how can I be more eco-friendly?',\n", - " 'tell me about sustainability practices',\n", - " 'what are some ways to save the planet?'],\n", - " 'gardening_and_horticulture': ['suggest some easy-care indoor plants',\n", - " 'how do I start a vegetable garden?',\n", - " 'what are some tips for sustainable gardening?'],\n", - " 'data_structures_and_algorithms': ['basic data structures for beginners',\n", - " 'complexity analysis of algorithms',\n", - " 'algorithms every developer should know'],\n", - " 'educational_facts': ['share a science fact',\n", - " 'do you know any historical trivia?',\n", - " 'tell me an interesting fact'],\n", - " 'art_and_culture': ['tell me about your favorite artist',\n", - " 'suggest some must-visit museums',\n", - " \"what's an interesting cultural tradition?\"],\n", - " 'mindfulness_and_wellness': ['give me a wellness tip',\n", - " 'tell me about mindfulness',\n", - " 'how can I relax?'],\n", - " 'cybersecurity_best_practices': ['common security vulnerabilities to avoid',\n", + " 'the weather is horrendous',\n", + " \"let's go to the chippy\",\n", + " 'how are things going?'],\n", + " 'jokes': ['make me laugh', 'tell me a joke', 'know any good jokes?'],\n", + " 'frameworks_and_libraries': [\"what's the difference between React and Angular?\",\n", + " 'introduction to Django for web development',\n", + " 'best Python libraries for data analysis'],\n", + " 'language_learning': ['what are some effective language learning techniques?',\n", + " 'suggest ways to learn a new language',\n", + " 'how can I improve my Spanish?'],\n", + " 'fitness_tips': ['how can I stay active at home?',\n", + " 'suggest a workout routine',\n", + " 'give me a fitness tip'],\n", + " 'debugging_tips': ['tips for debugging asynchronous code',\n", + " 'how do I debug segmentation faults in C++?',\n", + " 'best tools for JavaScript debugging'],\n", + " 'interview_preparation': ['how to prepare for a coding interview',\n", + " 'tips for technical interviews',\n", + " 'common programming interview questions'],\n", + " 'cybersecurity_best_practices': ['securing your web applications',\n", " 'introduction to ethical hacking for developers',\n", - " 'securing your web applications'],\n", - " 'development_tools': ['using Docker in development',\n", - " 'recommendations for Python IDEs',\n", - " 'best Git clients for macOS'],\n", - " 'gaming_and_esports': ['suggest a good game for beginners',\n", - " 'what are the popular games right now?',\n", - " 'tell me about upcoming esports events'],\n", - " 'interview_preparation': ['tips for technical interviews',\n", - " 'common programming interview questions',\n", - " 'how to prepare for a coding interview'],\n", + " 'common security vulnerabilities to avoid'],\n", + " 'astronomy_and_space_exploration': ['what are some interesting facts about the universe?',\n", + " 'tell me about the latest space mission',\n", + " 'how can I stargaze effectively?'],\n", + " 'ethical_considerations_in_tech': ['the role of ethics in artificial intelligence',\n", + " 'privacy concerns in app development',\n", + " 'ethical hacking and its importance'],\n", + " 'data_structures_and_algorithms': ['algorithms every developer should know',\n", + " 'basic data structures for beginners',\n", + " 'complexity analysis of algorithms'],\n", + " 'educational_facts': ['tell me an interesting fact',\n", + " 'share a science fact',\n", + " 'do you know any historical trivia?'],\n", + " 'career_advice_in_tech': ['how to build a portfolio for software development',\n", + " 'navigating career growth in tech',\n", + " 'tips for landing your first tech job'],\n", + " 'food_and_recipes': ['tell me about a dish from your country',\n", + " \"what's your favorite food?\",\n", + " 'suggest a recipe for dinner'],\n", " 'daily_inspiration': ['give me an inspirational quote',\n", " 'I need some inspiration for today',\n", " 'share something uplifting'],\n", + " 'development_tools': ['best Git clients for macOS',\n", + " 'using Docker in development',\n", + " 'recommendations for Python IDEs'],\n", + " 'best_practices': ['best practices for error handling in JavaScript',\n", + " 'what are the best practices for REST API design?',\n", + " 'how to write clean code in Python'],\n", " 'cloud_computing': ['best practices for cloud security',\n", - " 'AWS vs Azure vs Google Cloud',\n", - " 'introduction to cloud storage options'],\n", - " 'machine_learning_in_development': ['how to start with machine learning in Python',\n", - " 'machine learning model deployment best practices',\n", - " 'using TensorFlow for beginners'],\n", - " 'mental_health_support': ['what are ways to improve mental health?',\n", - " 'share some self-care practices',\n", - " 'how can I manage stress?'],\n", - " 'astronomy_and_space_exploration': ['how can I stargaze effectively?',\n", - " 'tell me about the latest space mission',\n", - " 'what are some interesting facts about the universe?'],\n", - " 'career_advice_in_tech': ['how to build a portfolio for software development',\n", - " 'tips for landing your first tech job',\n", - " 'navigating career growth in tech'],\n", + " 'introduction to cloud storage options',\n", + " 'AWS vs Azure vs Google Cloud'],\n", + " 'career_advice': ['suggest some career development tips',\n", + " 'how can I improve my resume?',\n", + " 'what are the emerging career fields?'],\n", + " 'compliments': ['say something nice about me',\n", + " 'I need some positive vibes',\n", + " 'give me a compliment'],\n", + " 'coding_standards_and_conventions': ['maintaining consistency in codebase',\n", + " 'JavaScript coding conventions',\n", + " 'why coding standards matter'],\n", + " 'art_and_culture': ['suggest some must-visit museums',\n", + " \"what's an interesting cultural tradition?\",\n", + " 'tell me about your favorite artist'],\n", " 'hobbies_and_interests': ['what are your interests?',\n", " 'suggest me a hobby',\n", " \"I'm looking for a new pastime\"],\n", - " 'debugging_tips': ['how do I debug segmentation faults in C++?',\n", - " 'best tools for JavaScript debugging',\n", - " 'tips for debugging asynchronous code'],\n", - " 'career_advice': ['suggest some career development tips',\n", - " 'what are the emerging career fields?',\n", - " 'how can I improve my resume?'],\n", - " 'compliments': ['give me a compliment',\n", - " 'say something nice about me',\n", - " 'I need some positive vibes'],\n", - " 'best_practices': ['how to write clean code in Python',\n", - " 'best practices for error handling in JavaScript',\n", - " 'what are the best practices for REST API design?'],\n", - " 'food_and_recipes': [\"what's your favorite food?\",\n", - " 'suggest a recipe for dinner',\n", - " 'tell me about a dish from your country'],\n", - " 'creative_writing_and_literature': ['suggest some classic literature',\n", - " 'what are some tips for storytelling?',\n", - " 'how can I improve my writing skills?'],\n", - " 'language_syntax': ['explain the syntax of Python functions',\n", + " 'machine_learning_in_development': ['using TensorFlow for beginners',\n", + " 'machine learning model deployment best practices',\n", + " 'how to start with machine learning in Python'],\n", + " 'mindfulness_and_wellness': ['tell me about mindfulness',\n", + " 'how can I relax?',\n", + " 'give me a wellness tip'],\n", + " 'gaming_and_esports': ['tell me about upcoming esports events',\n", + " 'what are the popular games right now?',\n", + " 'suggest a good game for beginners'],\n", + " 'historical_events': ['tell me about a significant historical event',\n", + " 'who was a notable figure in ancient history?',\n", + " 'share an interesting piece of medieval history'],\n", + " 'mental_health_support': ['share some self-care practices',\n", + " 'how can I manage stress?',\n", + " 'what are ways to improve mental health?'],\n", + " 'language_syntax': ['what are the new features in Java 15?',\n", " 'how do closures work in JavaScript?',\n", - " 'what are the new features in Java 15?'],\n", - " 'travel_stories': [\"what's the most interesting place you've visited?\",\n", - " 'share a travel story',\n", - " 'tell me about your favorite travel destination'],\n", - " 'philosophical_questions': ['do you believe in fate?',\n", - " 'what are your thoughts on free will?',\n", - " 'what is the meaning of life?'],\n", - " 'programming_challenges': ['where can I find algorithmic puzzles?',\n", - " 'suggest a coding challenge for beginners',\n", - " 'programming tasks to improve problem-solving'],\n", - " 'personal_questions': ['what do you like to do for fun?',\n", - " \"what's your favorite color?\",\n", - " 'do you have any hobbies?'],\n", - " 'movie_suggestions': ['recommend a movie',\n", - " \"what's your favorite movie?\",\n", - " 'suggest a good movie for tonight'],\n", - " 'science_and_innovation': ['what are the latest scientific discoveries?',\n", - " 'how does AI impact our daily lives?',\n", - " 'tell me about a recent innovation'],\n", + " 'explain the syntax of Python functions'],\n", + " 'environmental_awareness': ['tell me about sustainability practices',\n", + " 'how can I be more eco-friendly?',\n", + " 'what are some ways to save the planet?'],\n", + " 'gardening_and_horticulture': ['suggest some easy-care indoor plants',\n", + " 'how do I start a vegetable garden?',\n", + " 'what are some tips for sustainable gardening?'],\n", + " 'creative_writing_and_literature': ['how can I improve my writing skills?',\n", + " 'what are some tips for storytelling?',\n", + " 'suggest some classic literature'],\n", + " 'web_development_trends': ['the future of web development',\n", + " 'emerging back-end technologies',\n", + " \"what's new in front-end development?\"],\n", + " 'travel_stories': ['share a travel story',\n", + " 'tell me about your favorite travel destination',\n", + " \"what's the most interesting place you've visited?\"],\n", + " 'version_control_systems': ['best practices for branching in Git',\n", + " 'how to revert a commit in Git',\n", + " 'introduction to SVN for beginners'],\n", + " 'project_management_in_tech': ['how to lead a development team',\n", + " 'agile vs waterfall project management',\n", + " 'tools for managing tech projects'],\n", + " 'philosophical_questions': ['what is the meaning of life?',\n", + " 'do you believe in fate?',\n", + " 'what are your thoughts on free will?'],\n", + " 'software_architecture': ['explain microservices architecture',\n", + " 'differences between MVC and MVVM',\n", + " 'introduction to domain-driven design'],\n", + " 'politics': [\"why don't you tell me about your political opinions\",\n", + " \"isn't politics the best thing ever\",\n", + " 'they will save the country!',\n", + " \"don't you just love the presidentdon't you just hate the president\",\n", + " \"they're going to destroy this country!\"],\n", " 'music_discovery': ['suggest some new music',\n", " 'who are the top artists right now?',\n", " 'recommend songs for a workout playlist'],\n", - " 'web_development_trends': ['emerging back-end technologies',\n", - " \"what's new in front-end development?\",\n", - " 'the future of web development'],\n", - " 'tech_trends': ['tell me about the latest gadgets',\n", - " \"what's new in technology?\",\n", - " 'what are the emerging tech trends?'],\n", - " 'open_source_contributions': ['best practices for open-source contributors',\n", - " 'finding projects that accept contributions',\n", - " 'how to start contributing to open source'],\n", - " 'mobile_app_development': ['Kotlin vs Swift for mobile development',\n", - " 'optimizing performance in mobile apps',\n", + " 'personal_questions': ['do you have any hobbies?',\n", + " \"what's your favorite color?\",\n", + " 'what do you like to do for fun?'],\n", + " 'motivation': ['inspire me',\n", + " 'give me a motivational quote',\n", + " 'I need some motivation'],\n", + " 'mobile_app_development': ['optimizing performance in mobile apps',\n", + " 'Kotlin vs Swift for mobile development',\n", " 'best tools for cross-platform mobile development'],\n", - " 'politics': [\"isn't politics the best thing ever\",\n", - " \"don't you just love the presidentdon't you just hate the president\",\n", - " 'they will save the country!',\n", - " \"why don't you tell me about your political opinions\",\n", - " \"they're going to destroy this country!\"],\n", - " 'motivation': ['give me a motivational quote',\n", - " 'I need some motivation',\n", - " 'inspire me'],\n", + " 'movie_suggestions': ['suggest a good movie for tonight',\n", + " 'recommend a movie',\n", + " \"what's your favorite movie?\"],\n", + " 'open_source_contributions': ['best practices for open-source contributors',\n", + " 'how to start contributing to open source',\n", + " 'finding projects that accept contributions'],\n", + " 'science_and_innovation': ['how does AI impact our daily lives?',\n", + " 'tell me about a recent innovation',\n", + " 'what are the latest scientific discoveries?'],\n", + " 'tech_trends': [\"what's new in technology?\",\n", + " 'tell me about the latest gadgets',\n", + " 'what are the emerging tech trends?'],\n", + " 'programming_challenges': ['suggest a coding challenge for beginners',\n", + " 'where can I find algorithmic puzzles?',\n", + " 'programming tasks to improve problem-solving'],\n", " 'pet_care_advice': ['what should I know about keeping a pet rabbit?',\n", " 'suggest some tips for cat care',\n", - " 'how can I train my dog?'],\n", - " 'version_control_systems': ['best practices for branching in Git',\n", - " 'introduction to SVN for beginners',\n", - " 'how to revert a commit in Git'],\n", - " 'software_architecture': ['differences between MVC and MVVM',\n", - " 'introduction to domain-driven design',\n", - " 'explain microservices architecture'],\n", - " 'project_management_in_tech': ['agile vs waterfall project management',\n", - " 'how to lead a development team',\n", - " 'tools for managing tech projects']}" + " 'how can I train my dog?']}" ] }, - "execution_count": 6, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -695,16 +736,16 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Route(name='food_and_recipes', utterances=[\"what's your favorite food?\", 'suggest a recipe for dinner', 'tell me about a dish from your country'], description=None, function_schema=None, llm=None, score_threshold=None)" + "Route(name='book_recommendations', utterances=['suggest a good book to read', 'I need a book recommendation', \"what's your favorite book?\"], description=None, function_schema=None, llm=None, score_threshold=None)" ] }, - "execution_count": 13, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -726,7 +767,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -740,7 +781,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-04-15 01:57:19 INFO semantic_router.utils.logger local\u001b[0m\n" + "\u001b[32m2024-05-07 21:34:08 INFO semantic_router.utils.logger local\u001b[0m\n" ] } ], @@ -759,7 +800,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -768,7 +809,7 @@ "'jokes'" ] }, - "execution_count": 15, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -779,7 +820,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -788,7 +829,7 @@ "'jokes'" ] }, - "execution_count": 16, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -799,7 +840,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -808,7 +849,7 @@ "'chitchat'" ] }, - "execution_count": 17, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -819,7 +860,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -865,7 +906,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.11.4" } }, "nbformat": 4, diff --git a/semantic_router/layer.py b/semantic_router/layer.py index 3639b7a8984bca9ab7669a3da61efdc5928345b5..18e78f0f06fb026643c392dc728efce55a89f199 100644 --- a/semantic_router/layer.py +++ b/semantic_router/layer.py @@ -235,6 +235,11 @@ class RouteLayer: route_filter: Optional[List[str]] = None, ) -> RouteChoice: # if no vector provided, encode text to get vector + # DEBUGGING: Start. + print('#'*50) + print('CHECKPOINT 1') + print('#'*50) + # DEBUGGING: End. if vector is None: if text is None: raise ValueError("Either text or vector must be provided") @@ -242,7 +247,11 @@ class RouteLayer: route, top_class_scores = self._retrieve_top_route(vector, route_filter) passed = self._check_threshold(top_class_scores, route) - + # DEBUGGING: Start. + print('#'*50) + print('CHECKPOINT 2') + print('#'*50) + # DEBUGGING: End. if passed and route is not None and not simulate_static: if route.function_schemas and text is None: raise ValueError( @@ -260,6 +269,12 @@ class RouteLayer: route.llm = self.llm else: route.llm = self.llm + # DEBUGGING: Start. + print('#'*50) + print('text') + print(text) + print('#'*50) + # DEBUGGING: End. return route(text) elif passed and route is not None and simulate_static: return RouteChoice( diff --git a/semantic_router/llms/openai.py b/semantic_router/llms/openai.py index 8fd2a1b2e715adaf6a4255d6d5da4f1326ebd0d0..9ca742a44f4af8b9a192602964d038558eb13583 100644 --- a/semantic_router/llms/openai.py +++ b/semantic_router/llms/openai.py @@ -90,18 +90,6 @@ class OpenAILLM(BaseLLM): ) # Collecting multiple tool calls information - # DEBUGGING: Start. - print('#'*50) - print('tool_calls') - print(tool_calls) - print('#'*50) - # DEBUGGING: End. - # DEBUGGING: Start. - print('#'*50) - print('type(tool_calls)') - print(type(tool_calls)) - print('#'*50) - # DEBUGGING: End. output = str(self._extract_tool_calls_info(tool_calls)) # str in keepign with base type. else: content = completion.choices[0].message.content @@ -125,6 +113,7 @@ class OpenAILLM(BaseLLM): output = self(messages=messages, function_schemas=function_schemas) if not output: raise Exception("No output generated for extract function input") + output = output.replace("'", '"') function_inputs = json.loads(output) logger.info(f"Function inputs: {function_inputs}") if not self._is_valid_inputs(function_inputs, function_schemas):