From 6572f3fa83c2d281463821fba29216da06f172cf Mon Sep 17 00:00:00 2001 From: Simonas <20096648+simjak@users.noreply.github.com> Date: Fri, 5 Jan 2024 12:46:33 +0200 Subject: [PATCH] fix: set default layer encoder name to None --- docs/examples/function_calling.ipynb | 81 +++++++++++++++++----------- semantic_router/layer.py | 2 +- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/docs/examples/function_calling.ipynb b/docs/examples/function_calling.ipynb index 7b0347bc..401ab04a 100644 --- a/docs/examples/function_calling.ipynb +++ b/docs/examples/function_calling.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -54,10 +54,10 @@ { "data": { "text/plain": [ - "'05:02'" + "'05:44'" ] }, - "execution_count": 30, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -75,15 +75,17 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:02:35 INFO semantic_router.utils.logger Generating dynamic route...\u001b[0m\n", - "\u001b[32m2024-01-05 12:02:38 INFO semantic_router.utils.logger Generated route config:\n", + "/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", "{\n", " \"name\": \"get_time\",\n", " \"utterances\": [\n", @@ -94,8 +96,8 @@ " \"What's the current time in Berlin?\"\n", " ]\n", "}\u001b[0m\n", - "\u001b[32m2024-01-05 12:02:38 INFO semantic_router.utils.logger Generating dynamic route...\u001b[0m\n", - "\u001b[32m2024-01-05 12:02:41 INFO semantic_router.utils.logger Generated route config:\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", "{\n", " \"name\": \"get_news\",\n", " \"utterances\": [\n", @@ -123,7 +125,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -150,14 +152,21 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 5, "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" + ] + }, { "data": { "text/plain": [ "{'encoder_type': 'openai',\n", - " 'encoder_name': 'text-embedding-ada-002',\n", + " 'encoder_name': None,\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", @@ -188,7 +197,7 @@ " 'function_schema': None}]}" ] }, - "execution_count": 33, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -202,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -211,7 +220,7 @@ "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'>\"})" ] }, - "execution_count": 34, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -223,21 +232,21 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:02:41 INFO semantic_router.utils.logger Removed route `get_weather`\u001b[0m\n" + "\u001b[32m2024-01-05 12:44:32 INFO semantic_router.utils.logger Removed route `get_weather`\u001b[0m\n" ] }, { "data": { "text/plain": [ "{'encoder_type': 'openai',\n", - " 'encoder_name': 'text-embedding-ada-002',\n", + " 'encoder_name': None,\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", @@ -262,7 +271,7 @@ " 'output': \"<class 'str'>\"}}]}" ] }, - "execution_count": 35, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -282,14 +291,14 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:02:41 INFO semantic_router.utils.logger Saving route config to output/layer_config.json\u001b[0m\n" + "\u001b[32m2024-01-05 12:45:12 INFO semantic_router.utils.logger Saving route config to output/layer_config.json\u001b[0m\n" ] } ], @@ -313,14 +322,15 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:02:41 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 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" ] } ], @@ -339,14 +349,14 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:02:41 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" + "\u001b[32m2024-01-05 12:45:50 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n" ] } ], @@ -372,14 +382,14 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:02:42 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" + "\u001b[32m2024-01-05 12:45:53 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" ] }, { @@ -388,7 +398,7 @@ "RouteChoice(name='get_time', function_call={'timezone': 'Europe/Stockholm'})" ] }, - "execution_count": 39, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -406,7 +416,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -420,7 +430,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:03:45 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" + "\u001b[32m2024-01-05 12:45:58 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" ] }, { @@ -428,7 +438,7 @@ "output_type": "stream", "text": [ "Invoked `get_time` function with timezone: `Europe/Stockholm`\n", - "11:03\n", + "11:46\n", "Query: What are the tech news in the US?\n" ] }, @@ -436,7 +446,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-01-05 12:03:47 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" + "\u001b[32m2024-01-05 12:46:00 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n" ] }, { @@ -477,6 +487,13 @@ " print(f\"Query: {query}\")\n", " print(route_and_execute(query, functions, layer))" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/semantic_router/layer.py b/semantic_router/layer.py index 0315a281..e2c8286b 100644 --- a/semantic_router/layer.py +++ b/semantic_router/layer.py @@ -55,7 +55,7 @@ class LayerConfig: self, routes: list[Route] = [], encoder_type: str = "openai", - encoder_name: str | None = "text-embedding-ada-002", + encoder_name: str | None = None, ): self.encoder_type = encoder_type if encoder_name is None: -- GitLab