diff --git a/.gitignore b/.gitignore index c45ff835e404fccfbe848d948eee5ea327bf69c0..2b52a1bc319b8801f556525740365867d676ac99 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ venv/ .env*.local .env mac.env +local.mac.env # Code coverage history .coverage diff --git a/docs/02-dynamic-routes.ipynb b/docs/02-dynamic-routes.ipynb index 3dc13b8b88d014f3f3087efafe0cff4a3956bea4..1197fcc0ff0c25ac90795521d11db9e8685df41d 100644 --- a/docs/02-dynamic-routes.ipynb +++ b/docs/02-dynamic-routes.ipynb @@ -1,1097 +1,1097 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "UxqB7_Ieur0s" - }, - "source": [ - "[](https://colab.research.google.com/github/aurelio-labs/semantic-router/blob/main/docs/02-dynamic-routes.ipynb) [](https://nbviewer.org/github/aurelio-labs/semantic-router/blob/main/docs/02-dynamic-routes.ipynb)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "EduhQaNAur0u" - }, - "source": [ - "# Dynamic Routes" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "_4JgNeX4ur0v" - }, - "source": [ - "In semantic-router there are two types of routes that can be chosen. Both routes belong to the `Route` object, the only difference between them is that _static_ routes return a `Route.name` when chosen, whereas _dynamic_ routes use an LLM call to produce parameter input values.\n", - "\n", - "For example, a _static_ route will tell us if a query is talking about mathematics by returning the route name (which could be `\"math\"` for example). A _dynamic_ route does the same thing, but it also extracts key information from the input utterance to be used in a function associated with that route. \n", - "\n", - "For example we could provide a dynamic route with associated utterances: \n", - "\n", - "```\n", - "\"what is x to the power of y?\"\n", - "\"what is 9 to the power of 4?\"\n", - "\"calculate the result of base x and exponent y\"\n", - "\"calculate the result of base 10 and exponent 3\"\n", - "\"return x to the power of y\"\n", - "```\n", - "\n", - "and we could also provide the route with a schema outlining key features of the function:\n", - "\n", - "```\n", - "def power(base: float, exponent: float) -> float:\n", - " \"\"\"Raise base to the power of exponent.\n", - "\n", - " Args:\n", - " base (float): The base number.\n", - " exponent (float): The exponent to which the base is raised.\n", - "\n", - " Returns:\n", - " float: The result of base raised to the power of exponent.\n", - " \"\"\"\n", - " return base ** exponent\n", - "```\n", - "\n", - "Then, if the users input utterance is \"What is 2 to the power of 3?\", the route will be triggered, as the input utterance is semantically similar to the route utterances. Furthermore, the route utilizes an LLM to identify that `base=2` and `expoenent=3`. These values are returned in such a way that they can be used in the above `power` function. That is, the dynamic router automates the process of calling relevant functions from natural language inputs. \n", - "\n", - "***âš ï¸ Note: We have a fully local version of dynamic routes available at [docs/05-local-execution.ipynb](https://github.com/aurelio-labs/semantic-router/blob/main/docs/05-local-execution.ipynb). The local 05 version tends to outperform the OpenAI version we demo in this notebook, so we'd recommend trying [05](https://github.com/aurelio-labs/semantic-router/blob/main/docs/05-local-execution.ipynb)!***" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "bbmw8CO4ur0v" - }, - "source": [ - "## Installing the Library" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "id": "dLElfRhgur0v" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: tzdata in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (2024.1)\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" - ] - } - ], - "source": [ - "!pip install tzdata\n", - "!pip install -qU semantic-router" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "BixZd6Eour0w" - }, - "source": [ - "## Initializing Routes and RouteLayer" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "PxnW9qBvur0x" - }, - "source": [ - "Dynamic routes are treated in the same way as static routes, let's begin by initializing a `RouteLayer` consisting of static routes." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "id": "kc9Ty6Lgur0x" - }, - "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 import Route\n", - "\n", - "politics = Route(\n", - " name=\"politics\",\n", - " utterances=[\n", - " \"isn't politics the best thing ever\",\n", - " \"why don't you tell me about your political opinions\",\n", - " \"don't you just love the president\" \"don't you just hate the president\",\n", - " \"they're going to destroy this country!\",\n", - " \"they will save the country!\",\n", - " ],\n", - ")\n", - "chitchat = Route(\n", - " name=\"chitchat\",\n", - " utterances=[\n", - " \"how's the weather today?\",\n", - " \"how are things going?\",\n", - " \"lovely weather today\",\n", - " \"the weather is horrendous\",\n", - " \"let's go to the chippy\",\n", - " ],\n", - ")\n", - "\n", - "routes = [politics, chitchat]" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "voWyqmffur0x" - }, - "source": [ - "We initialize our `RouteLayer` with our `encoder` and `routes`. We can use popular encoder APIs like `CohereEncoder` and `OpenAIEncoder`, or local alternatives like `FastEmbedEncoder`." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "BI9AiDspur0y", - "outputId": "27329a54-3f16-44a5-ac20-13a6b26afb97" - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m2024-05-08 01:57:55 INFO semantic_router.utils.logger local\u001b[0m\n" - ] - } - ], - "source": [ - "import os\n", - "from getpass import getpass\n", - "from semantic_router import RouteLayer\n", - "from semantic_router.encoders import CohereEncoder, OpenAIEncoder\n", - "\n", - "# dashboard.cohere.ai\n", - "# os.environ[\"COHERE_API_KEY\"] = os.getenv(\"COHERE_API_KEY\") or getpass(\n", - "# \"Enter Cohere API Key: \"\n", - "# )\n", - "# platform.openai.com\n", - "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\") or getpass(\n", - " \"Enter OpenAI API Key: \"\n", - ")\n", - "\n", - "# encoder = CohereEncoder()\n", - "encoder = OpenAIEncoder()\n", - "\n", - "rl = RouteLayer(encoder=encoder, routes=routes)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "GuLCeIS5ur0y" - }, - "source": [ - "We run the solely static routes layer:" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "_rNREh7gur0y", - "outputId": "f3a1dc0b-d760-4efb-b634-d3547011dcb7" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "RouteChoice(name='chitchat', function_call=None, similarity_score=None)" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "rl(\"how's the weather today?\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "McbLKO26ur0y" - }, - "source": [ - "## Creating a Dynamic Route" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ANAoEjxYur0y" - }, - "source": [ - "As with static routes, we must create a dynamic route before adding it to our route layer. To make a route dynamic, we need to provide the `function_schemas` as a list. Each function schema provides instructions on what a function is, so that an LLM can decide how to use it correctly." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "id": "5jaF1Xa5ur0y" - }, - "outputs": [], - "source": [ - "from datetime import datetime\n", - "from zoneinfo import ZoneInfo\n", - "\n", - "\n", - "def get_time(timezone: str) -> str:\n", - " \"\"\"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", - " now = datetime.now(ZoneInfo(timezone))\n", - " return now.strftime(\"%H:%M\")" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 35 - }, - "id": "YyFKV8jMur0z", - "outputId": "29cf80f4-552c-47bb-fbf9-019f5dfdf00a" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'17:57'" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "get_time(\"America/New_York\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "4qyaRuNXur0z" - }, - "source": [ - "To get the function schema we can use the `get_schema` function from the `function_call` module." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "tOjuhp5Xur0z", - "outputId": "ca88a3ea-d70a-4950-be9a-63fab699de3b" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'type': 'function',\n", - " 'function': {'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", - " 'parameters': {'type': 'object',\n", - " 'properties': {'timezone': {'type': 'string',\n", - " 'description': '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", - " 'required': ['timezone']}}}]" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from semantic_router.llms.openai import get_schemas_openai\n", - "\n", - "schemas = get_schemas_openai([get_time])\n", - "schemas" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "HcF7jGjAur0z" - }, - "source": [ - "We use this to define our dynamic route:" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": { - "id": "iesBG9P3ur0z" - }, - "outputs": [], - "source": [ - "time_route = Route(\n", - " name=\"get_time\",\n", - " utterances=[\n", - " \"what is the time in new york city?\",\n", - " \"what is the time in london?\",\n", - " \"I live in Rome, what time is it?\",\n", - " ],\n", - " function_schemas=schemas,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "time_route.llm" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ZiUs3ovpur0z" - }, - "source": [ - "Add the new route to our `layer`:" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "-0vY8PRXur0z", - "outputId": "db01e14c-eab3-4f93-f4c2-e30f508c8b5d" - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m2024-05-08 01:57:56 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n" - ] - } - ], - "source": [ - "rl.add(time_route)" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "time_route.llm" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "7yoE0IrNur0z" - }, - "source": [ - "Now we can ask our layer a time related question to trigger our new dynamic route." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 53 - }, - "id": "Wfb68M0-ur0z", - "outputId": "79923883-2a4d-4744-f8ce-e818cb5f14c3" - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[33m2024-05-08 01:57:57 WARNING semantic_router.utils.logger No LLM provided for dynamic route, will use OpenAI LLM default. Ensure API key is set in OPENAI_API_KEY environment variable.\u001b[0m\n", - "\u001b[32m2024-05-08 01:57:58 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "RouteChoice(name='get_time', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}], similarity_score=None)" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response = rl(\"what is the time in new york city?\")\n", - "response\n" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\n" - ] - } - ], - "source": [ - "print(response.function_call)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "17:57\n" - ] - } - ], - "source": [ - "import json\n", - "\n", - "for call in response.function_call:\n", - " if call['function_name'] == 'get_time':\n", - " args = call['arguments']\n", - " result = get_time(**args)\n", - "print(result)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "Qt0vkq2Xur00" - }, - "source": [ - "Our dynamic route provides both the route itself _and_ the input parameters required to use the route." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Dynamic Routes with Multiple Functions" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "J0oD1dxIur00" - }, - "source": [ - "---" - ] - }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "UxqB7_Ieur0s" + }, + "source": [ + "[](https://colab.research.google.com/github/aurelio-labs/semantic-router/blob/main/docs/02-dynamic-routes.ipynb) [](https://nbviewer.org/github/aurelio-labs/semantic-router/blob/main/docs/02-dynamic-routes.ipynb)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EduhQaNAur0u" + }, + "source": [ + "# Dynamic Routes" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_4JgNeX4ur0v" + }, + "source": [ + "In semantic-router there are two types of routes that can be chosen. Both routes belong to the `Route` object, the only difference between them is that _static_ routes return a `Route.name` when chosen, whereas _dynamic_ routes use an LLM call to produce parameter input values.\n", + "\n", + "For example, a _static_ route will tell us if a query is talking about mathematics by returning the route name (which could be `\"math\"` for example). A _dynamic_ route does the same thing, but it also extracts key information from the input utterance to be used in a function associated with that route. \n", + "\n", + "For example we could provide a dynamic route with associated utterances: \n", + "\n", + "```\n", + "\"what is x to the power of y?\"\n", + "\"what is 9 to the power of 4?\"\n", + "\"calculate the result of base x and exponent y\"\n", + "\"calculate the result of base 10 and exponent 3\"\n", + "\"return x to the power of y\"\n", + "```\n", + "\n", + "and we could also provide the route with a schema outlining key features of the function:\n", + "\n", + "```\n", + "def power(base: float, exponent: float) -> float:\n", + " \"\"\"Raise base to the power of exponent.\n", + "\n", + " Args:\n", + " base (float): The base number.\n", + " exponent (float): The exponent to which the base is raised.\n", + "\n", + " Returns:\n", + " float: The result of base raised to the power of exponent.\n", + " \"\"\"\n", + " return base ** exponent\n", + "```\n", + "\n", + "Then, if the users input utterance is \"What is 2 to the power of 3?\", the route will be triggered, as the input utterance is semantically similar to the route utterances. Furthermore, the route utilizes an LLM to identify that `base=2` and `expoenent=3`. These values are returned in such a way that they can be used in the above `power` function. That is, the dynamic router automates the process of calling relevant functions from natural language inputs. \n", + "\n", + "***âš ï¸ Note: We have a fully local version of dynamic routes available at [docs/05-local-execution.ipynb](https://github.com/aurelio-labs/semantic-router/blob/main/docs/05-local-execution.ipynb). The local 05 version tends to outperform the OpenAI version we demo in this notebook, so we'd recommend trying [05](https://github.com/aurelio-labs/semantic-router/blob/main/docs/05-local-execution.ipynb)!***" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "bbmw8CO4ur0v" + }, + "source": [ + "## Installing the Library" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "dLElfRhgur0v" + }, + "outputs": [ { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Routes can be assigned multiple functions. Then, when that particular Route is selected by the Route Layer, a number of those functions might be invoked due to the users utterance containing relevant information that fits their arguments. " - ] + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: tzdata in c:\\users\\siraj\\documents\\personal\\work\\aurelio\\virtual environments\\semantic_router_3\\lib\\site-packages (2024.1)\n" + ] }, { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's define a Route that has multiple functions." - ] - }, + "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" + ] + } + ], + "source": [ + "!pip install tzdata\n", + "!pip install -qU semantic-router" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "BixZd6Eour0w" + }, + "source": [ + "## Initializing Routes and RouteLayer" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "PxnW9qBvur0x" + }, + "source": [ + "Dynamic routes are treated in the same way as static routes, let's begin by initializing a `RouteLayer` consisting of static routes." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "kc9Ty6Lgur0x" + }, + "outputs": [ { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [], - "source": [ - "from datetime import datetime, timedelta\n", - "from zoneinfo import ZoneInfo\n", - "\n", - "# Function with one argument\n", - "def get_time(timezone: str) -> str:\n", - " \"\"\"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", - " now = datetime.now(ZoneInfo(timezone))\n", - " return now.strftime(\"%H:%M\")\n", - "\n", - "\n", - "\n", - "def get_time_difference(timezone1: str, timezone2: str) -> str:\n", - " \"\"\"Calculates the time difference between two timezones.\n", - " :param timezone1: The first timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".\n", - " :param timezone2: The second timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".\n", - " :type timezone1: str\n", - " :type timezone2: str\n", - " :return: The time difference in hours between the two timezones.\"\"\"\n", - " # Get the current time in UTC\n", - " now_utc = datetime.utcnow().replace(tzinfo=ZoneInfo('UTC'))\n", - " \n", - " # Convert the UTC time to the specified timezones\n", - " tz1_time = now_utc.astimezone(ZoneInfo(timezone1))\n", - " tz2_time = now_utc.astimezone(ZoneInfo(timezone2))\n", - " \n", - " # Calculate the difference in offsets from UTC\n", - " tz1_offset = tz1_time.utcoffset().total_seconds()\n", - " tz2_offset = tz2_time.utcoffset().total_seconds()\n", - " \n", - " # Calculate the difference in hours\n", - " hours_difference = (tz2_offset - tz1_offset) / 3600\n", - " \n", - " return f\"The time difference between {timezone1} and {timezone2} is {hours_difference} hours.\"\n", - "\n", - "# Function with three arguments\n", - "def convert_time(time: str, from_timezone: str, to_timezone: str) -> str:\n", - " \"\"\"Converts a specific time from one timezone to another.\n", - " :param time: The time to convert in HH:MM format.\n", - " :param from_timezone: The original timezone of the time, should be a valid IANA timezone.\n", - " :param to_timezone: The target timezone for the time, should be a valid IANA timezone.\n", - " :type time: str\n", - " :type from_timezone: str\n", - " :type to_timezone: str\n", - " :return: The converted time in the target timezone.\n", - " :raises ValueError: If the time format or timezone strings are invalid.\n", - " \n", - " Example:\n", - " convert_time(\"12:30\", \"America/New_York\", \"Asia/Tokyo\") -> \"03:30\"\n", - " \"\"\"\n", - " try:\n", - " # Use today's date to avoid historical timezone issues\n", - " today = datetime.now().date()\n", - " datetime_string = f\"{today} {time}\"\n", - " time_obj = datetime.strptime(datetime_string, \"%Y-%m-%d %H:%M\").replace(tzinfo=ZoneInfo(from_timezone))\n", - " \n", - " converted_time = time_obj.astimezone(ZoneInfo(to_timezone))\n", - " \n", - " formatted_time = converted_time.strftime(\"%H:%M\")\n", - " return formatted_time\n", - " except Exception as e:\n", - " raise ValueError(f\"Error converting time: {e}\")\n", - "\n", - "\n" - ] + "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 import Route\n", + "\n", + "politics = Route(\n", + " name=\"politics\",\n", + " utterances=[\n", + " \"isn't politics the best thing ever\",\n", + " \"why don't you tell me about your political opinions\",\n", + " \"don't you just love the president\" \"don't you just hate the president\",\n", + " \"they're going to destroy this country!\",\n", + " \"they will save the country!\",\n", + " ],\n", + ")\n", + "chitchat = Route(\n", + " name=\"chitchat\",\n", + " utterances=[\n", + " \"how's the weather today?\",\n", + " \"how are things going?\",\n", + " \"lovely weather today\",\n", + " \"the weather is horrendous\",\n", + " \"let's go to the chippy\",\n", + " ],\n", + ")\n", + "\n", + "routes = [politics, chitchat]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "voWyqmffur0x" + }, + "source": [ + "We initialize our `RouteLayer` with our `encoder` and `routes`. We can use popular encoder APIs like `CohereEncoder` and `OpenAIEncoder`, or local alternatives like `FastEmbedEncoder`." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, + "id": "BI9AiDspur0y", + "outputId": "27329a54-3f16-44a5-ac20-13a6b26afb97" + }, + "outputs": [ { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [], - "source": [ - "functions = [get_time, get_time_difference, convert_time]" - ] + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[32m2024-05-08 01:57:55 INFO semantic_router.utils.logger local\u001b[0m\n" + ] + } + ], + "source": [ + "import os\n", + "from getpass import getpass\n", + "from semantic_router import RouteLayer\n", + "from semantic_router.encoders import CohereEncoder, OpenAIEncoder\n", + "\n", + "# dashboard.cohere.ai\n", + "# os.environ[\"COHERE_API_KEY\"] = os.getenv(\"COHERE_API_KEY\") or getpass(\n", + "# \"Enter Cohere API Key: \"\n", + "# )\n", + "# platform.openai.com\n", + "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\") or getpass(\n", + " \"Enter OpenAI API Key: \"\n", + ")\n", + "\n", + "# encoder = CohereEncoder()\n", + "encoder = OpenAIEncoder()\n", + "\n", + "rl = RouteLayer(encoder=encoder, routes=routes)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "GuLCeIS5ur0y" + }, + "source": [ + "We run the solely static routes layer:" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, + "id": "_rNREh7gur0y", + "outputId": "f3a1dc0b-d760-4efb-b634-d3547011dcb7" + }, + "outputs": [ { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'type': 'function',\n", - " 'function': {'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", - " 'parameters': {'type': 'object',\n", - " 'properties': {'timezone': {'type': 'string',\n", - " 'description': '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", - " 'required': ['timezone']}}},\n", - " {'type': 'function',\n", - " 'function': {'name': 'get_time_difference',\n", - " 'description': 'Calculates the time difference between two timezones.\\n:param timezone1: The first timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".\\n:param timezone2: The second timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".\\n:type timezone1: str\\n:type timezone2: str\\n:return: The time difference in hours between the two timezones.',\n", - " 'parameters': {'type': 'object',\n", - " 'properties': {'timezone1': {'type': 'string',\n", - " 'description': 'The first timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".'},\n", - " 'timezone2': {'type': 'string',\n", - " 'description': 'The second timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".'}},\n", - " 'required': ['timezone1', 'timezone2']}}},\n", - " {'type': 'function',\n", - " 'function': {'name': 'convert_time',\n", - " 'description': 'Converts a specific time from one timezone to another.\\n:param time: The time to convert in HH:MM format.\\n:param from_timezone: The original timezone of the time, should be a valid IANA timezone.\\n:param to_timezone: The target timezone for the time, should be a valid IANA timezone.\\n:type time: str\\n:type from_timezone: str\\n:type to_timezone: str\\n:return: The converted time in the target timezone.\\n:raises ValueError: If the time format or timezone strings are invalid.\\n\\nExample:\\n convert_time(\"12:30\", \"America/New_York\", \"Asia/Tokyo\") -> \"03:30\"',\n", - " 'parameters': {'type': 'object',\n", - " 'properties': {'time': {'type': 'string',\n", - " 'description': 'The time to convert in HH:MM format.'},\n", - " 'from_timezone': {'type': 'string',\n", - " 'description': 'The original timezone of the time, should be a valid IANA timezone.'},\n", - " 'to_timezone': {'type': 'string',\n", - " 'description': 'The target timezone for the time, should be a valid IANA timezone.'}},\n", - " 'required': ['time', 'from_timezone', 'to_timezone']}}}]" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Generate schemas for all functions\n", - "from semantic_router.llms.openai import get_schemas_openai\n", - "schemas = get_schemas_openai(functions)\n", - "schemas\n" + "data": { + "text/plain": [ + "RouteChoice(name='chitchat', function_call=None, similarity_score=None)" ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rl(\"how's the weather today?\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "McbLKO26ur0y" + }, + "source": [ + "## Creating a Dynamic Route" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ANAoEjxYur0y" + }, + "source": [ + "As with static routes, we must create a dynamic route before adding it to our route layer. To make a route dynamic, we need to provide the `function_schemas` as a list. Each function schema provides instructions on what a function is, so that an LLM can decide how to use it correctly." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "5jaF1Xa5ur0y" + }, + "outputs": [], + "source": [ + "from datetime import datetime\n", + "from zoneinfo import ZoneInfo\n", + "\n", + "\n", + "def get_time(timezone: str) -> str:\n", + " \"\"\"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", + " now = datetime.now(ZoneInfo(timezone))\n", + " return now.strftime(\"%H:%M\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 }, + "id": "YyFKV8jMur0z", + "outputId": "29cf80f4-552c-47bb-fbf9-019f5dfdf00a" + }, + "outputs": [ { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [], - "source": [ - "# Define the dynamic route with multiple functions\n", - "multi_function_route = Route(\n", - " name=\"timezone_management\",\n", - " utterances=[\n", - " # Utterances for get_time function\n", - " \"what is the time in New York?\",\n", - " \"current time in Berlin?\",\n", - " \"tell me the time in Moscow right now\",\n", - " \"can you show me the current time in Tokyo?\",\n", - " \"please provide the current time in London\",\n", - "\n", - " # Utterances for get_time_difference function\n", - " \"how many hours ahead is Tokyo from London?\",\n", - " \"time difference between Sydney and Cairo\",\n", - " \"what's the time gap between Los Angeles and New York?\",\n", - " \"how much time difference is there between Paris and Sydney?\",\n", - " \"calculate the time difference between Dubai and Toronto\",\n", - "\n", - " # Utterances for convert_time function\n", - " \"convert 15:00 from New York time to Berlin time\",\n", - " \"change 09:00 from Paris time to Moscow time\",\n", - " \"adjust 20:00 from Rome time to London time\",\n", - " \"convert 12:00 from Madrid time to Chicago time\",\n", - " \"change 18:00 from Beijing time to Los Angeles time\"\n", - "\n", - " # All three functions\n", - " \"What is the time in Seattle? What is the time difference between Mumbai and Tokyo? What is 5:53 Toronto time in Sydney time?\"\n", - " ],\n", - " function_schemas=schemas\n", - ")\n" + "data": { + "text/plain": [ + "'17:57'" ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_time(\"America/New_York\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4qyaRuNXur0z" + }, + "source": [ + "To get the function schema we can use the `get_schema` function from the `function_call` module." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, + "id": "tOjuhp5Xur0z", + "outputId": "ca88a3ea-d70a-4950-be9a-63fab699de3b" + }, + "outputs": [ { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [], - "source": [ - "routes = [politics, chitchat, multi_function_route]" + "data": { + "text/plain": [ + "[{'type': 'function',\n", + " 'function': {'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", + " 'parameters': {'type': 'object',\n", + " 'properties': {'timezone': {'type': 'string',\n", + " 'description': '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", + " 'required': ['timezone']}}}]" ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from semantic_router.llms.openai import get_schemas_openai\n", + "\n", + "schemas = get_schemas_openai([get_time])\n", + "schemas" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "HcF7jGjAur0z" + }, + "source": [ + "We use this to define our dynamic route:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "iesBG9P3ur0z" + }, + "outputs": [], + "source": [ + "time_route = Route(\n", + " name=\"get_time\",\n", + " utterances=[\n", + " \"what is the time in new york city?\",\n", + " \"what is the time in london?\",\n", + " \"I live in Rome, what time is it?\",\n", + " ],\n", + " function_schemas=schemas,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "time_route.llm" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZiUs3ovpur0z" + }, + "source": [ + "Add the new route to our `layer`:" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, + "id": "-0vY8PRXur0z", + "outputId": "db01e14c-eab3-4f93-f4c2-e30f508c8b5d" + }, + "outputs": [ { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m2024-05-08 01:57:58 INFO semantic_router.utils.logger local\u001b[0m\n" - ] - } - ], - "source": [ - "rl2 = RouteLayer(encoder=encoder, routes=routes)" - ] + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[32m2024-05-08 01:57:56 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n" + ] + } + ], + "source": [ + "rl.add(time_route)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "time_route.llm" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7yoE0IrNur0z" + }, + "source": [ + "Now we can ask our layer a time related question to trigger our new dynamic route." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 53 }, + "id": "Wfb68M0-ur0z", + "outputId": "79923883-2a4d-4744-f8ce-e818cb5f14c3" + }, + "outputs": [ { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Function to Parse Route Layer Responses" - ] + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[33m2024-05-08 01:57:57 WARNING semantic_router.utils.logger No LLM provided for dynamic route, will use OpenAI LLM default. Ensure API key is set in OPENAI_API_KEY environment variable.\u001b[0m\n", + "\u001b[32m2024-05-08 01:57:58 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" + ] }, { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [], - "source": [ - "def parse_response(response: str):\n", - "\n", - " for call in response.function_call:\n", - " args = call['arguments']\n", - " if call['function_name'] == 'get_time':\n", - " result = get_time(**args)\n", - " print(result)\n", - " if call['function_name'] == 'get_time_difference':\n", - " result = get_time_difference(**args)\n", - " print(result)\n", - " if call['function_name'] == 'convert_time':\n", - " result = convert_time(**args)\n", - " print(result)" + "data": { + "text/plain": [ + "RouteChoice(name='get_time', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}], similarity_score=None)" ] - }, + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = rl(\"what is the time in new york city?\")\n", + "response" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Checking that Politics Non-Dynamic Route Still Works" - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\n" + ] + } + ], + "source": [ + "print(response.function_call)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "RouteChoice(name='politics', function_call=None, similarity_score=None)" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response = rl2(\"What is your political leaning?\")\n", - "response" - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "17:57\n" + ] + } + ], + "source": [ + "import json\n", + "\n", + "for call in response.function_call:\n", + " if call[\"function_name\"] == \"get_time\":\n", + " args = call[\"arguments\"]\n", + " result = get_time(**args)\n", + "print(result)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Qt0vkq2Xur00" + }, + "source": [ + "Our dynamic route provides both the route itself _and_ the input parameters required to use the route." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Dynamic Routes with Multiple Functions" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "J0oD1dxIur00" + }, + "source": [ + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Routes can be assigned multiple functions. Then, when that particular Route is selected by the Route Layer, a number of those functions might be invoked due to the users utterance containing relevant information that fits their arguments. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's define a Route that has multiple functions." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "from datetime import datetime, timedelta\n", + "from zoneinfo import ZoneInfo\n", + "\n", + "\n", + "# Function with one argument\n", + "def get_time(timezone: str) -> str:\n", + " \"\"\"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", + " now = datetime.now(ZoneInfo(timezone))\n", + " return now.strftime(\"%H:%M\")\n", + "\n", + "\n", + "def get_time_difference(timezone1: str, timezone2: str) -> str:\n", + " \"\"\"Calculates the time difference between two timezones.\n", + " :param timezone1: The first timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".\n", + " :param timezone2: The second timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".\n", + " :type timezone1: str\n", + " :type timezone2: str\n", + " :return: The time difference in hours between the two timezones.\"\"\"\n", + " # Get the current time in UTC\n", + " now_utc = datetime.utcnow().replace(tzinfo=ZoneInfo(\"UTC\"))\n", + "\n", + " # Convert the UTC time to the specified timezones\n", + " tz1_time = now_utc.astimezone(ZoneInfo(timezone1))\n", + " tz2_time = now_utc.astimezone(ZoneInfo(timezone2))\n", + "\n", + " # Calculate the difference in offsets from UTC\n", + " tz1_offset = tz1_time.utcoffset().total_seconds()\n", + " tz2_offset = tz2_time.utcoffset().total_seconds()\n", + "\n", + " # Calculate the difference in hours\n", + " hours_difference = (tz2_offset - tz1_offset) / 3600\n", + "\n", + " return f\"The time difference between {timezone1} and {timezone2} is {hours_difference} hours.\"\n", + "\n", + "\n", + "# Function with three arguments\n", + "def convert_time(time: str, from_timezone: str, to_timezone: str) -> str:\n", + " \"\"\"Converts a specific time from one timezone to another.\n", + " :param time: The time to convert in HH:MM format.\n", + " :param from_timezone: The original timezone of the time, should be a valid IANA timezone.\n", + " :param to_timezone: The target timezone for the time, should be a valid IANA timezone.\n", + " :type time: str\n", + " :type from_timezone: str\n", + " :type to_timezone: str\n", + " :return: The converted time in the target timezone.\n", + " :raises ValueError: If the time format or timezone strings are invalid.\n", + "\n", + " Example:\n", + " convert_time(\"12:30\", \"America/New_York\", \"Asia/Tokyo\") -> \"03:30\"\n", + " \"\"\"\n", + " try:\n", + " # Use today's date to avoid historical timezone issues\n", + " today = datetime.now().date()\n", + " datetime_string = f\"{today} {time}\"\n", + " time_obj = datetime.strptime(datetime_string, \"%Y-%m-%d %H:%M\").replace(\n", + " tzinfo=ZoneInfo(from_timezone)\n", + " )\n", + "\n", + " converted_time = time_obj.astimezone(ZoneInfo(to_timezone))\n", + "\n", + " formatted_time = converted_time.strftime(\"%H:%M\")\n", + " return formatted_time\n", + " except Exception as e:\n", + " raise ValueError(f\"Error converting time: {e}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "functions = [get_time, get_time_difference, convert_time]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Checking that Chitchat Non-Dynamic Route Still Works" + "data": { + "text/plain": [ + "[{'type': 'function',\n", + " 'function': {'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", + " 'parameters': {'type': 'object',\n", + " 'properties': {'timezone': {'type': 'string',\n", + " 'description': '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", + " 'required': ['timezone']}}},\n", + " {'type': 'function',\n", + " 'function': {'name': 'get_time_difference',\n", + " 'description': 'Calculates the time difference between two timezones.\\n:param timezone1: The first timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".\\n:param timezone2: The second timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".\\n:type timezone1: str\\n:type timezone2: str\\n:return: The time difference in hours between the two timezones.',\n", + " 'parameters': {'type': 'object',\n", + " 'properties': {'timezone1': {'type': 'string',\n", + " 'description': 'The first timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".'},\n", + " 'timezone2': {'type': 'string',\n", + " 'description': 'The second timezone, should be a valid timezone from the IANA Time Zone Database like \"America/New_York\" or \"Europe/London\".'}},\n", + " 'required': ['timezone1', 'timezone2']}}},\n", + " {'type': 'function',\n", + " 'function': {'name': 'convert_time',\n", + " 'description': 'Converts a specific time from one timezone to another.\\n:param time: The time to convert in HH:MM format.\\n:param from_timezone: The original timezone of the time, should be a valid IANA timezone.\\n:param to_timezone: The target timezone for the time, should be a valid IANA timezone.\\n:type time: str\\n:type from_timezone: str\\n:type to_timezone: str\\n:return: The converted time in the target timezone.\\n:raises ValueError: If the time format or timezone strings are invalid.\\n\\nExample:\\n convert_time(\"12:30\", \"America/New_York\", \"Asia/Tokyo\") -> \"03:30\"',\n", + " 'parameters': {'type': 'object',\n", + " 'properties': {'time': {'type': 'string',\n", + " 'description': 'The time to convert in HH:MM format.'},\n", + " 'from_timezone': {'type': 'string',\n", + " 'description': 'The original timezone of the time, should be a valid IANA timezone.'},\n", + " 'to_timezone': {'type': 'string',\n", + " 'description': 'The target timezone for the time, should be a valid IANA timezone.'}},\n", + " 'required': ['time', 'from_timezone', 'to_timezone']}}}]" ] - }, + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Generate schemas for all functions\n", + "from semantic_router.llms.openai import get_schemas_openai\n", + "\n", + "schemas = get_schemas_openai(functions)\n", + "schemas" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "# Define the dynamic route with multiple functions\n", + "multi_function_route = Route(\n", + " name=\"timezone_management\",\n", + " utterances=[\n", + " # Utterances for get_time function\n", + " \"what is the time in New York?\",\n", + " \"current time in Berlin?\",\n", + " \"tell me the time in Moscow right now\",\n", + " \"can you show me the current time in Tokyo?\",\n", + " \"please provide the current time in London\",\n", + " # Utterances for get_time_difference function\n", + " \"how many hours ahead is Tokyo from London?\",\n", + " \"time difference between Sydney and Cairo\",\n", + " \"what's the time gap between Los Angeles and New York?\",\n", + " \"how much time difference is there between Paris and Sydney?\",\n", + " \"calculate the time difference between Dubai and Toronto\",\n", + " # Utterances for convert_time function\n", + " \"convert 15:00 from New York time to Berlin time\",\n", + " \"change 09:00 from Paris time to Moscow time\",\n", + " \"adjust 20:00 from Rome time to London time\",\n", + " \"convert 12:00 from Madrid time to Chicago time\",\n", + " \"change 18:00 from Beijing time to Los Angeles time\"\n", + " # All three functions\n", + " \"What is the time in Seattle? What is the time difference between Mumbai and Tokyo? What is 5:53 Toronto time in Sydney time?\",\n", + " ],\n", + " function_schemas=schemas,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "routes = [politics, chitchat, multi_function_route]" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "RouteChoice(name='chitchat', function_call=None, similarity_score=None)" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response = rl2(\"Hello bot, how are you today?\")\n", - "response" - ] - }, + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[32m2024-05-08 01:57:58 INFO semantic_router.utils.logger local\u001b[0m\n" + ] + } + ], + "source": [ + "rl2 = RouteLayer(encoder=encoder, routes=routes)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Function to Parse Route Layer Responses" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "def parse_response(response: str):\n", + "\n", + " for call in response.function_call:\n", + " args = call[\"arguments\"]\n", + " if call[\"function_name\"] == \"get_time\":\n", + " result = get_time(**args)\n", + " print(result)\n", + " if call[\"function_name\"] == \"get_time_difference\":\n", + " result = get_time_difference(**args)\n", + " print(result)\n", + " if call[\"function_name\"] == \"convert_time\":\n", + " result = convert_time(**args)\n", + " print(result)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Checking that Politics Non-Dynamic Route Still Works" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Testing the `multi_function_route` - The `get_time` Function" + "data": { + "text/plain": [ + "RouteChoice(name='politics', function_call=None, similarity_score=None)" ] - }, + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = rl2(\"What is your political leaning?\")\n", + "response" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Checking that Chitchat Non-Dynamic Route Still Works" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[33m2024-05-08 01:58:00 WARNING semantic_router.utils.logger No LLM provided for dynamic route, will use OpenAI LLM default. Ensure API key is set in OPENAI_API_KEY environment variable.\u001b[0m\n", - "\u001b[32m2024-05-08 01:58:01 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}], similarity_score=None)" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response = rl2(\"what is the time in New York?\")\n", - "response" + "data": { + "text/plain": [ + "RouteChoice(name='chitchat', function_call=None, similarity_score=None)" ] - }, + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = rl2(\"Hello bot, how are you today?\")\n", + "response" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Testing the `multi_function_route` - The `get_time` Function" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "17:58\n" - ] - } - ], - "source": [ - "parse_response(response)" - ] + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[33m2024-05-08 01:58:00 WARNING semantic_router.utils.logger No LLM provided for dynamic route, will use OpenAI LLM default. Ensure API key is set in OPENAI_API_KEY environment variable.\u001b[0m\n", + "\u001b[32m2024-05-08 01:58:01 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}]\u001b[0m\n" + ] }, { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Testing the `multi_function_route` - The `get_time_difference` Function" + "data": { + "text/plain": [ + "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'America/New_York'}}], similarity_score=None)" ] - }, + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = rl2(\"what is the time in New York?\")\n", + "response" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m2024-05-08 01:58:02 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}]\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}], similarity_score=None)" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response = rl2(\"What is the time difference between Los Angeles and Istanbul?\")\n", - "response" - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "17:58\n" + ] + } + ], + "source": [ + "parse_response(response)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Testing the `multi_function_route` - The `get_time_difference` Function" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The time difference between America/Los_Angeles and Europe/Istanbul is 10.0 hours.\n" - ] - } - ], - "source": [ - "parse_response(response)" - ] + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[32m2024-05-08 01:58:02 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}]\u001b[0m\n" + ] }, { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Testing the `multi_function_route` - The `convert_time` Function" + "data": { + "text/plain": [ + "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time_difference', 'arguments': {'timezone1': 'America/Los_Angeles', 'timezone2': 'Europe/Istanbul'}}], similarity_score=None)" ] - }, + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = rl2(\"What is the time difference between Los Angeles and Istanbul?\")\n", + "response" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m2024-05-08 01:58:04 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'convert_time', 'arguments': {'time': '23:02', 'from_timezone': 'Asia/Dubai', 'to_timezone': 'Asia/Tokyo'}}]\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "RouteChoice(name='timezone_management', function_call=[{'function_name': 'convert_time', 'arguments': {'time': '23:02', 'from_timezone': 'Asia/Dubai', 'to_timezone': 'Asia/Tokyo'}}], similarity_score=None)" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response = rl2(\"What is 23:02 Dubai time in Tokyo time? Please and thank you.\")\n", - "response" - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "The time difference between America/Los_Angeles and Europe/Istanbul is 10.0 hours.\n" + ] + } + ], + "source": [ + "parse_response(response)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Testing the `multi_function_route` - The `convert_time` Function" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "04:02\n" - ] - } - ], - "source": [ - "parse_response(response)" - ] + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[32m2024-05-08 01:58:04 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'convert_time', 'arguments': {'time': '23:02', 'from_timezone': 'Asia/Dubai', 'to_timezone': 'Asia/Tokyo'}}]\u001b[0m\n" + ] }, { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### The Cool Bit - Testing `multi_function_route` - Multiple Functions at Once" + "data": { + "text/plain": [ + "RouteChoice(name='timezone_management', function_call=[{'function_name': 'convert_time', 'arguments': {'time': '23:02', 'from_timezone': 'Asia/Dubai', 'to_timezone': 'Asia/Tokyo'}}], similarity_score=None)" ] - }, + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = rl2(\"What is 23:02 Dubai time in Tokyo time? Please and thank you.\")\n", + "response" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[32m2024-05-08 01:58:07 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'Europe/Prague'}}, {'function_name': 'get_time_difference', 'arguments': {'timezone1': 'Europe/Berlin', 'timezone2': 'Asia/Shanghai'}}, {'function_name': 'convert_time', 'arguments': {'time': '05:53', 'from_timezone': 'Europe/Lisbon', 'to_timezone': 'Asia/Bangkok'}}]\u001b[0m\n" - ] - } - ], - "source": [ - "response = rl2(\"\"\"\n", - " What is the time in Prague?\n", - " What is the time difference between Frankfurt and Beijing?\n", - " What is 5:53 Lisbon time in Bangkok time?\n", - "\"\"\" \n", - ")" - ] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "04:02\n" + ] + } + ], + "source": [ + "parse_response(response)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### The Cool Bit - Testing `multi_function_route` - Multiple Functions at Once" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'Europe/Prague'}}, {'function_name': 'get_time_difference', 'arguments': {'timezone1': 'Europe/Berlin', 'timezone2': 'Asia/Shanghai'}}, {'function_name': 'convert_time', 'arguments': {'time': '05:53', 'from_timezone': 'Europe/Lisbon', 'to_timezone': 'Asia/Bangkok'}}], similarity_score=None)" - ] - }, - "execution_count": 31, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response" - ] - }, + "name": "stderr", + "output_type": "stream", + "text": [ + "\u001b[32m2024-05-08 01:58:07 INFO semantic_router.utils.logger Function inputs: [{'function_name': 'get_time', 'arguments': {'timezone': 'Europe/Prague'}}, {'function_name': 'get_time_difference', 'arguments': {'timezone1': 'Europe/Berlin', 'timezone2': 'Asia/Shanghai'}}, {'function_name': 'convert_time', 'arguments': {'time': '05:53', 'from_timezone': 'Europe/Lisbon', 'to_timezone': 'Asia/Bangkok'}}]\u001b[0m\n" + ] + } + ], + "source": [ + "response = rl2(\n", + " \"\"\"\n", + " What is the time in Prague?\n", + " What is the time difference between Frankfurt and Beijing?\n", + " What is 5:53 Lisbon time in Bangkok time?\n", + "\"\"\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "23:58\n", - "The time difference between Europe/Berlin and Asia/Shanghai is 6.0 hours.\n", - "11:53\n" - ] - } - ], - "source": [ - "parse_response(response)" + "data": { + "text/plain": [ + "RouteChoice(name='timezone_management', function_call=[{'function_name': 'get_time', 'arguments': {'timezone': 'Europe/Prague'}}, {'function_name': 'get_time_difference', 'arguments': {'timezone1': 'Europe/Berlin', 'timezone2': 'Asia/Shanghai'}}, {'function_name': 'convert_time', 'arguments': {'time': '05:53', 'from_timezone': 'Europe/Lisbon', 'to_timezone': 'Asia/Bangkok'}}], similarity_score=None)" ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" } - ], - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "display_name": "decision-layer", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.4" + ], + "source": [ + "response" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "23:58\n", + "The time difference between Europe/Berlin and Asia/Shanghai is 6.0 hours.\n", + "11:53\n" + ] } + ], + "source": [ + "parse_response(response)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "decision-layer", + "language": "python", + "name": "python3" }, - "nbformat": 4, - "nbformat_minor": 0 + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 0 } diff --git a/docs/encoders/openai-encoder.ipynb b/docs/encoders/openai-encoder.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..70397c453d3132e46f60f6982806563bf3b5c9aa --- /dev/null +++ b/docs/encoders/openai-encoder.ipynb @@ -0,0 +1,2140 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from semantic_router.encoders.openai import OpenAIEncoder\n", + "import os\n", + "from getpass import getpass\n", + "from dotenv import load_dotenv" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# load your .env file\n", + "load_dotenv(\"../../semantic-router.env\")\n", + "\n", + "# os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\") or getpass(\n", + "# \"Enter OpenAI API Key: \"\n", + "# )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# test to see OPENAI_API_KEY assigned\n", + "!echo $OPENAI_API_KEY" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# document list\n", + "doc_list = [\"doc1.txt\", \"doc2.txt\"]\n", + "\n", + "docs = []\n", + "for doc in doc_list:\n", + " with open(doc, \"r\") as dr:\n", + " doc = dr.read()\n", + " docs.append(doc)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "encoder = OpenAIEncoder(\n", + " name=\"text-embedding-ada-002\", openai_api_key=os.getenv(\"OPENAI_API_KEY\")\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "OpenAIEncoder(name='text-embedding-ada-002', score_threshold=0.82, type='openai', client=<openai.OpenAI object at 0x155c34da0>, dimensions=NOT_GIVEN, token_limit=8192)" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "encoder" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[-0.01257531438022852,\n", + " 0.007780410349369049,\n", + " 0.012338700704276562,\n", + " -0.031288664788007736,\n", + " -0.001347479410469532,\n", + " 0.019193535670638084,\n", + " -0.006826996803283691,\n", + " 0.01962500624358654,\n", + " -0.023508252575993538,\n", + " -0.06647448986768723,\n", + " 0.02786472626030445,\n", + " 0.0397510789334774,\n", + " -0.026124920696020126,\n", + " -0.00020333977590780705,\n", + " 0.007968309335410595,\n", + " 0.01745373010635376,\n", + " 0.02371702902019024,\n", + " 0.004930608905851841,\n", + " 0.010404037311673164,\n", + " -0.008879967965185642,\n", + " 0.006774802692234516,\n", + " -0.001526679378002882,\n", + " -0.02917305938899517,\n", + " -0.00954805314540863,\n", + " -0.006802639923989773,\n", + " 0.013299074023962021,\n", + " 0.032596997916698456,\n", + " -0.027307987213134766,\n", + " -0.0385262556374073,\n", + " 0.005045436322689056,\n", + " -0.0023904929403215647,\n", + " -0.002063409425318241,\n", + " -0.04133778065443039,\n", + " 0.0058770631439983845,\n", + " -0.028866853564977646,\n", + " -0.019680680707097054,\n", + " 0.02425984852015972,\n", + " -0.012916316278278828,\n", + " 0.01642376370728016,\n", + " -0.004620923660695553,\n", + " 0.026639902964234352,\n", + " 0.019235290586948395,\n", + " 0.021406566724181175,\n", + " -0.017871282994747162,\n", + " 0.0028202247340232134,\n", + " 0.02019566297531128,\n", + " 0.021531833335757256,\n", + " -0.023786621168255806,\n", + " -0.018386265262961388,\n", + " 0.006040604785084724,\n", + " 0.011809799820184708,\n", + " 0.03404451534152031,\n", + " -0.02778121456503868,\n", + " 0.015532984398305416,\n", + " -0.011343532241880894,\n", + " -0.019945131614804268,\n", + " 0.01732846349477768,\n", + " 0.02208857052028179,\n", + " 0.017759935930371284,\n", + " 0.00997952464967966,\n", + " 0.007258468773216009,\n", + " 0.010953815653920174,\n", + " -0.026403289288282394,\n", + " 0.03766331076622009,\n", + " -0.009012192487716675,\n", + " -0.020460113883018494,\n", + " -0.017551157623529434,\n", + " 0.005000201053917408,\n", + " 0.013688789680600166,\n", + " -0.01235261932015419,\n", + " 0.004001552704721689,\n", + " 0.005856185685843229,\n", + " 0.003918041940778494,\n", + " -0.0045130555517971516,\n", + " 0.04239558055996895,\n", + " -0.00837890338152647,\n", + " -0.012839765287935734,\n", + " -0.022394776344299316,\n", + " -0.02474699355661869,\n", + " 0.008615517057478428,\n", + " 0.019277045503258705,\n", + " -0.006475556176155806,\n", + " -0.0036744694225490093,\n", + " 0.03649416193366051,\n", + " 0.012944153510034084,\n", + " 0.01924920827150345,\n", + " 0.011232184246182442,\n", + " -0.021253464743494987,\n", + " -0.012770173139870167,\n", + " 0.002075588097795844,\n", + " 0.014224650338292122,\n", + " -0.008163168095052242,\n", + " 0.03248564898967743,\n", + " 0.012714498676359653,\n", + " 0.007060131058096886,\n", + " -0.015658250078558922,\n", + " -0.010668487288057804,\n", + " 0.0006089319358579814,\n", + " -0.010118708945810795,\n", + " -0.020752400159835815,\n", + " -0.00755771528929472,\n", + " 0.0011595804244279861,\n", + " -0.0327640175819397,\n", + " -0.018010467290878296,\n", + " -0.028699832037091255,\n", + " 0.0013866249937564135,\n", + " 0.012116005644202232,\n", + " 0.00017050094902515411,\n", + " 0.0078012882731854916,\n", + " -0.0018180968472734094,\n", + " -0.020599298179149628,\n", + " 0.025025364011526108,\n", + " 0.005208977963775396,\n", + " -0.02700178138911724,\n", + " -0.007738654967397451,\n", + " -0.004704434424638748,\n", + " 0.0076760221272706985,\n", + " -0.009248806163668633,\n", + " -0.0006211106083355844,\n", + " -0.005156783852726221,\n", + " 0.02495577000081539,\n", + " 0.003789296606555581,\n", + " 0.017425892874598503,\n", + " -0.002381793688982725,\n", + " 0.04968884587287903,\n", + " 0.012860642746090889,\n", + " -0.011301777325570583,\n", + " -0.035909585654735565,\n", + " -0.03699522465467453,\n", + " 0.003216900397092104,\n", + " -0.0009099182789213955,\n", + " 0.028003910556435585,\n", + " 0.005132426507771015,\n", + " 0.004864496178925037,\n", + " -0.022840166464447975,\n", + " 0.03958405554294586,\n", + " -0.008803416043519974,\n", + " -0.01798263005912304,\n", + " -0.013438258320093155,\n", + " -0.013382584787905216,\n", + " 0.009652441367506981,\n", + " 0.030843272805213928,\n", + " -0.0011021668324247003,\n", + " 0.0001909436541609466,\n", + " -0.009429746307432652,\n", + " 0.022269511595368385,\n", + " 0.01036228146404028,\n", + " 0.002173017244786024,\n", + " 0.005403836257755756,\n", + " -0.01245700754225254,\n", + " -0.00046061351895332336,\n", + " -0.035547707229852676,\n", + " 0.009471501223742962,\n", + " 0.02892252802848816,\n", + " 0.020460113883018494,\n", + " -0.002682780148461461,\n", + " 0.013994995504617691,\n", + " 0.03437855839729309,\n", + " -0.01180284097790718,\n", + " -0.027057455852627754,\n", + " -0.026361534371972084,\n", + " 0.004259043838828802,\n", + " -0.0003681863599922508,\n", + " 0.01395324058830738,\n", + " 0.0031455685384571552,\n", + " 0.026027491316199303,\n", + " 0.011900270357728004,\n", + " -0.013257318176329136,\n", + " -0.00479490403085947,\n", + " -0.018302753567695618,\n", + " -0.014210731722414494,\n", + " 0.03760763630270958,\n", + " -0.038164373487234116,\n", + " 0.023369068279862404,\n", + " -0.0008272775448858738,\n", + " 0.015950538218021393,\n", + " 0.030258698388934135,\n", + " -0.009638522751629353,\n", + " -0.008692068979144096,\n", + " -0.01550514716655016,\n", + " 0.02384229563176632,\n", + " 0.017147524282336235,\n", + " 0.005831828340888023,\n", + " -0.003211681032553315,\n", + " -0.027683785185217857,\n", + " -0.016729969531297684,\n", + " -0.0022704461589455605,\n", + " -0.006054523400962353,\n", + " 0.007307183463126421,\n", + " -0.024037154391407967,\n", + " 0.019931212067604065,\n", + " 0.035547707229852676,\n", + " 0.008448495529592037,\n", + " -0.011106918565928936,\n", + " -0.5950413346290588,\n", + " -0.008796457201242447,\n", + " 0.0035370246041566133,\n", + " 0.010891182348132133,\n", + " -0.024301603436470032,\n", + " 8.427183274761774e-06,\n", + " -0.00074898632010445,\n", + " 0.0033682635985314846,\n", + " -0.019611088559031487,\n", + " 0.04122643172740936,\n", + " -0.02782297134399414,\n", + " -0.009450623765587807,\n", + " -9.155726729659364e-05,\n", + " -0.02883901633322239,\n", + " -0.006120636127889156,\n", + " -0.02794823609292507,\n", + " -0.008525047451257706,\n", + " -0.02224167436361313,\n", + " 0.01684131845831871,\n", + " -0.002975067589432001,\n", + " -0.018692471086978912,\n", + " 0.009088744409382343,\n", + " 0.012032494880259037,\n", + " 0.019680680707097054,\n", + " -0.03421153500676155,\n", + " 0.005014119669795036,\n", + " 0.007321101613342762,\n", + " -0.004335595294833183,\n", + " 0.011406165547668934,\n", + " 0.008455455303192139,\n", + " -0.03835923224687576,\n", + " 0.00531684560701251,\n", + " -0.0064303213730454445,\n", + " -0.02089158445596695,\n", + " 0.04492873698472977,\n", + " -0.007293264847248793,\n", + " -0.017606832087039948,\n", + " 0.01983378268778324,\n", + " 0.017773853614926338,\n", + " -0.0014692657859995961,\n", + " -0.03518582880496979,\n", + " -0.03345993906259537,\n", + " -0.005762236192822456,\n", + " 0.019764190539717674,\n", + " 0.004596566315740347,\n", + " 0.017913037911057472,\n", + " 0.011197388172149658,\n", + " 0.012213435024023056,\n", + " 0.003086415119469166,\n", + " -0.020167825743556023,\n", + " -0.01785736344754696,\n", + " 0.02978547103703022,\n", + " 0.013361706398427486,\n", + " -0.01228998601436615,\n", + " -0.00703577371314168,\n", + " 4.4093198084738106e-05,\n", + " 0.0239675622433424,\n", + " -0.02613883838057518,\n", + " 0.01806614175438881,\n", + " -0.0020860268268734217,\n", + " -0.0034535140730440617,\n", + " -0.007439408451318741,\n", + " -0.030175186693668365,\n", + " -0.012512682005763054,\n", + " -0.003851929446682334,\n", + " 0.0029159141704440117,\n", + " -0.011232184246182442,\n", + " -0.0004527843848336488,\n", + " -0.004446942824870348,\n", + " -0.00766210351139307,\n", + " -3.191455834894441e-05,\n", + " 0.01257531438022852,\n", + " -0.007564674597233534,\n", + " 0.0024009316693991423,\n", + " -0.009617645293474197,\n", + " 0.026904353871941566,\n", + " 0.012408292852342129,\n", + " -0.0036988265346735716,\n", + " 0.016242824494838715,\n", + " 0.016646459698677063,\n", + " 0.01036924123764038,\n", + " -0.021044688299298286,\n", + " 0.02114211767911911,\n", + " -0.013688789680600166,\n", + " 0.0335991233587265,\n", + " 0.003335207235068083,\n", + " 0.006955742835998535,\n", + " 0.01317380741238594,\n", + " 0.0020268734078854322,\n", + " 0.02474699355661869,\n", + " -0.003333467524498701,\n", + " 0.02658422850072384,\n", + " -0.028073502704501152,\n", + " -0.0397510789334774,\n", + " -0.005014119669795036,\n", + " 0.030620578676462173,\n", + " -0.02474699355661869,\n", + " -0.005710041616111994,\n", + " 0.027558520436286926,\n", + " -0.02154575288295746,\n", + " 0.004551331512629986,\n", + " -0.00755771528929472,\n", + " 0.032262954860925674,\n", + " 0.016938745975494385,\n", + " 0.019110023975372314,\n", + " 0.009701156057417393,\n", + " -0.007453327067196369,\n", + " 0.0016997900092974305,\n", + " 0.02093334123492241,\n", + " -0.023341231048107147,\n", + " 0.01224823109805584,\n", + " 0.0016475958982482553,\n", + " -0.006611261051148176,\n", + " -0.025554263964295387,\n", + " 0.0054490710608661175,\n", + " -0.03593742474913597,\n", + " 0.011865474283695221,\n", + " -0.00612411554902792,\n", + " 0.003034220775589347,\n", + " -0.019986886531114578,\n", + " 0.01880381815135479,\n", + " -0.008100534789264202,\n", + " 0.02249220572412014,\n", + " 0.011065163649618626,\n", + " 0.014447345398366451,\n", + " 0.011218266561627388,\n", + " 0.015797434374690056,\n", + " -0.008358025923371315,\n", + " 0.02499752677977085,\n", + " 0.02577695995569229,\n", + " -0.01532420702278614,\n", + " -0.019597169011831284,\n", + " 0.043202850967645645,\n", + " -0.042423419654369354,\n", + " 0.03073192574083805,\n", + " 0.011503593996167183,\n", + " 0.04679381102323532,\n", + " -0.0009586328524164855,\n", + " 0.004899292252957821,\n", + " -0.019318800419569016,\n", + " -0.02622235007584095,\n", + " 0.0007254988886415958,\n", + " 0.018692471086978912,\n", + " -0.016994420439004898,\n", + " -0.03432288393378258,\n", + " -0.03490746021270752,\n", + " -0.012853683903813362,\n", + " -0.0004095067270100117,\n", + " 0.014419508166611195,\n", + " -0.01087726466357708,\n", + " -0.00821188185364008,\n", + " -0.010223097167909145,\n", + " -0.016869153827428818,\n", + " 0.008399780839681625,\n", + " -0.0100351981818676,\n", + " -0.012143842875957489,\n", + " -0.008072697557508945,\n", + " -0.03379398211836815,\n", + " -0.011955943889915943,\n", + " -0.043369874358177185,\n", + " 0.0076064299792051315,\n", + " 0.020000804215669632,\n", + " -0.004314717836678028,\n", + " 0.026834761723876,\n", + " -0.00112391437869519,\n", + " -0.00981250312179327,\n", + " 0.0014788347762078047,\n", + " 0.003305630525574088,\n", + " -0.02527589537203312,\n", + " -0.02556818164885044,\n", + " 4.0994167648022994e-05,\n", + " -0.041282106190919876,\n", + " 0.005668286699801683,\n", + " 0.024733075872063637,\n", + " -0.02691827155649662,\n", + " -0.006545148324221373,\n", + " 0.009290562011301517,\n", + " 0.008852130733430386,\n", + " -0.011775003746151924,\n", + " -0.014962327666580677,\n", + " 0.01638200879096985,\n", + " 0.025067118927836418,\n", + " -0.0010847687954083085,\n", + " -0.009019152261316776,\n", + " 0.024162419140338898,\n", + " 0.0070914472453296185,\n", + " 0.04417714104056358,\n", + " -0.003432636382058263,\n", + " -0.01450301893055439,\n", + " 0.016952665522694588,\n", + " 0.006572985555976629,\n", + " -0.003048139391466975,\n", + " -0.03176188841462135,\n", + " 0.014196813106536865,\n", + " 0.010640650987625122,\n", + " 0.018038304522633553,\n", + " 0.001282236655242741,\n", + " -0.006653016433119774,\n", + " 0.0036709897685796022,\n", + " 0.017551157623529434,\n", + " 0.008733823895454407,\n", + " 0.006545148324221373,\n", + " 0.0031977626495063305,\n", + " -0.018177488818764687,\n", + " -0.004909731447696686,\n", + " -0.01472571399062872,\n", + " 0.01423856895416975,\n", + " -0.016521193087100983,\n", + " 0.007265428081154823,\n", + " 0.00041581352706998587,\n", + " 0.015185022726655006,\n", + " -0.023369068279862404,\n", + " -0.018692471086978912,\n", + " -0.012867601588368416,\n", + " -0.0029367918614298105,\n", + " 0.026723412796854973,\n", + " 0.012554436922073364,\n", + " 0.007975269109010696,\n", + " -0.01639592833817005,\n", + " 0.006795680616050959,\n", + " -0.01990337483584881,\n", + " 0.007314142771065235,\n", + " 0.019722435623407364,\n", + " 0.006249381694942713,\n", + " -0.011392246931791306,\n", + " 0.0032099413219839334,\n", + " -0.025415079668164253,\n", + " 0.0031821043230593204,\n", + " 0.0012691881274804473,\n", + " -0.014349916018545628,\n", + " -0.004850578028708696,\n", + " 0.012136883102357388,\n", + " 0.022213837131857872,\n", + " 0.010076954029500484,\n", + " 0.010250934399664402,\n", + " -0.003956317901611328,\n", + " 0.03757980093359947,\n", + " 0.003737102262675762,\n", + " 0.03126082569360733,\n", + " -0.01212992426007986,\n", + " -0.00325691606849432,\n", + " 0.019040431827306747,\n", + " -0.008518087677657604,\n", + " -0.021657099947333336,\n", + " 0.02122562751173973,\n", + " -0.01892908476293087,\n", + " 0.02432944066822529,\n", + " 0.0027401938568800688,\n", + " -0.021281301975250244,\n", + " 0.011092999950051308,\n", + " -0.02204681560397148,\n", + " 0.01489273551851511,\n", + " -0.013152929954230785,\n", + " -0.011768044903874397,\n", + " 0.019485821947455406,\n", + " -0.011315695010125637,\n", + " 0.0038936848286539316,\n", + " 0.0027227955870330334,\n", + " 0.02953493967652321,\n", + " 0.012074250727891922,\n", + " -3.879222640534863e-05,\n", + " 0.009882095269858837,\n", + " 0.006771323271095753,\n", + " -0.00122134352568537,\n", + " 0.026278022676706314,\n", + " -0.014294242486357689,\n", + " -0.009868176653981209,\n", + " -0.02384229563176632,\n", + " -0.01688307337462902,\n", + " -0.0076760221272706985,\n", + " -0.029200896620750427,\n", + " -0.016173232346773148,\n", + " 0.02023741789162159,\n", + " -0.02805958315730095,\n", + " 0.01819140650331974,\n", + " 0.022923678159713745,\n", + " 0.001559735625050962,\n", + " 0.025512509047985077,\n", + " 0.024566054344177246,\n", + " 0.045457638800144196,\n", + " -0.03117731586098671,\n", + " -0.042757462710142136,\n", + " 0.013048541732132435,\n", + " -0.0016136696795001626,\n", + " -0.026779087260365486,\n", + " -0.021935468539595604,\n", + " -0.055367570370435715,\n", + " 0.0032516964711248875,\n", + " 0.002971587935462594,\n", + " -0.015644332394003868,\n", + " -0.007028814405202866,\n", + " -0.005066313780844212,\n", + " 0.0023922326508909464,\n", + " 0.00664605712518096,\n", + " -0.008775578811764717,\n", + " 0.015435555018484592,\n", + " 0.030175186693668365,\n", + " -0.004112900234758854,\n", + " -0.011434001848101616,\n", + " -0.012818886898458004,\n", + " 0.0010195260401815176,\n", + " 0.006120636127889156,\n", + " -0.04993937909603119,\n", + " -0.005386438220739365,\n", + " 0.033209409564733505,\n", + " -0.020181745290756226,\n", + " -0.03457341715693474,\n", + " -0.010501466691493988,\n", + " 0.008239719085395336,\n", + " 0.0002616232668515295,\n", + " 0.0029785470105707645,\n", + " 0.0022043336648494005,\n", + " 0.001066500786691904,\n", + " 0.00224782875739038,\n", + " 0.021128198131918907,\n", + " 0.007975269109010696,\n", + " 0.011009489186108112,\n", + " 0.015700004994869232,\n", + " 0.021865876391530037,\n", + " 0.004213809035718441,\n", + " -0.0014092425117269158,\n", + " -0.04289664700627327,\n", + " -0.009561971761286259,\n", + " 0.020376602187752724,\n", + " 0.05394789204001427,\n", + " 0.03760763630270958,\n", + " -0.016437683254480362,\n", + " -0.0005106329335831106,\n", + " -0.019318800419569016,\n", + " -0.0012961551547050476,\n", + " -0.0028567607514560223,\n", + " -0.03101029433310032,\n", + " -0.004370391368865967,\n", + " 0.013222522102296352,\n", + " -0.014266405254602432,\n", + " -0.02790648117661476,\n", + " 0.012373496778309345,\n", + " 0.006200667005032301,\n", + " 0.03757980093359947,\n", + " 0.007237591315060854,\n", + " 0.0086015984416008,\n", + " -0.025985736399888992,\n", + " -0.006917466875165701,\n", + " 0.009735952131450176,\n", + " 0.006604301743209362,\n", + " -0.002955929609015584,\n", + " 0.019110023975372314,\n", + " 0.03089894726872444,\n", + " 0.02306286245584488,\n", + " -0.002809786004945636,\n", + " 0.034350719302892685,\n", + " 0.005014119669795036,\n", + " -0.027280151844024658,\n", + " -0.02925657108426094,\n", + " -0.016896991059184074,\n", + " 0.001798958983272314,\n", + " 0.006058002822101116,\n", + " 0.018288835883140564,\n", + " -0.0012674483004957438,\n", + " 0.013827974908053875,\n", + " -0.0031577469781041145,\n", + " -0.007954390719532967,\n", + " 0.02290976047515869,\n", + " -0.005741358269006014,\n", + " 0.03376614674925804,\n", + " 0.03332075476646423,\n", + " -0.007474204525351524,\n", + " -0.005974492058157921,\n", + " 0.006948783528059721,\n", + " -0.039027318358421326,\n", + " -0.007850002497434616,\n", + " 0.026458963751792908,\n", + " -0.008267556317150593,\n", + " -0.02289584092795849,\n", + " 0.021420486271381378,\n", + " 0.008455455303192139,\n", + " -0.02032092958688736,\n", + " -0.02478875033557415,\n", + " 0.012547478079795837,\n", + " 0.011768044903874397,\n", + " -0.004474780056625605,\n", + " 0.009756829589605331,\n", + " -0.009269683621823788,\n", + " -0.026890434324741364,\n", + " -0.003542244201526046,\n", + " -0.04698866978287697,\n", + " 0.022339103743433952,\n", + " -0.012951112352311611,\n", + " -0.02217208221554756,\n", + " 0.015964455902576447,\n", + " -0.0254011619836092,\n", + " -0.0016667337622493505,\n", + " -0.029757633805274963,\n", + " 0.008399780839681625,\n", + " -0.02282624877989292,\n", + " -0.027753377333283424,\n", + " -0.057343989610672,\n", + " -0.012429171241819859,\n", + " 0.011587104760110378,\n", + " 0.016980502754449844,\n", + " 0.01631241664290428,\n", + " -0.003481350839138031,\n", + " 0.011747167445719242,\n", + " 0.007738654967397451,\n", + " -0.010508425533771515,\n", + " -0.00436343252658844,\n", + " 0.014057628810405731,\n", + " -0.03479611128568649,\n", + " -0.01124610286206007,\n", + " -0.010640650987625122,\n", + " 0.00042320770444348454,\n", + " -0.0186367966234684,\n", + " -0.020251337438821793,\n", + " 0.0009020891739055514,\n", + " -0.0043007992208004,\n", + " -0.002157358918339014,\n", + " -0.03465692698955536,\n", + " -0.004245125688612461,\n", + " 0.022478288039565086,\n", + " 0.015240696258842945,\n", + " 0.015240696258842945,\n", + " 0.01696658320724964,\n", + " 0.013201644644141197,\n", + " -0.02290976047515869,\n", + " 0.0034778714179992676,\n", + " -0.03897164389491081,\n", + " -0.02700178138911724,\n", + " -0.02801782824099064,\n", + " -0.0040537468157708645,\n", + " 0.015352044254541397,\n", + " 0.015073675662279129,\n", + " 0.008295392617583275,\n", + " 0.00011700192408170551,\n", + " -0.016618622466921806,\n", + " 0.005835307762026787,\n", + " 0.0013335609110072255,\n", + " 0.003126430558040738,\n", + " -0.006510352250188589,\n", + " -0.0006089319358579814,\n", + " 0.011322654783725739,\n", + " 0.022645309567451477,\n", + " 0.017551157623529434,\n", + " 0.014168976806104183,\n", + " -0.03752412647008896,\n", + " 0.0023104618303477764,\n", + " -0.04108724743127823,\n", + " 0.038776785135269165,\n", + " 0.0002922873245552182,\n", + " -0.008942600339651108,\n", + " 0.024566054344177246,\n", + " -0.007087967824190855,\n", + " 0.0021069045178592205,\n", + " -0.02466348372399807,\n", + " 0.00964548159390688,\n", + " 0.0031977626495063305,\n", + " 0.037301432341337204,\n", + " -0.0014318600296974182,\n", + " -0.008657272905111313,\n", + " -0.024552136659622192,\n", + " -0.002320900559425354,\n", + " -0.033209409564733505,\n", + " 0.0016058405162766576,\n", + " -0.019318800419569016,\n", + " 0.00449565751478076,\n", + " 0.0049967216327786446,\n", + " 0.017885200679302216,\n", + " -0.0005737008759751916,\n", + " -0.004916690289974213,\n", + " 0.021531833335757256,\n", + " -0.027224477380514145,\n", + " -0.022547880187630653,\n", + " 0.03362696245312691,\n", + " 0.03265267238020897,\n", + " 0.008998273871839046,\n", + " -0.010550180450081825,\n", + " -0.00029315723804757,\n", + " -0.0413934551179409,\n", + " -0.027669867500662804,\n", + " -0.016702134162187576,\n", + " -0.012582274153828621,\n", + " 0.002251308411359787,\n", + " 0.002063409425318241,\n", + " 0.00664605712518096,\n", + " -0.0036744694225490093,\n", + " 0.06096278503537178,\n", + " -0.011190429329872131,\n", + " 0.001123044523410499,\n", + " 0.033988840878009796,\n", + " -0.01278409082442522,\n", + " -0.003587479004636407,\n", + " 0.0053759990260005,\n", + " -0.0063363718800246716,\n", + " -0.0241763386875391,\n", + " -0.013577442616224289,\n", + " 0.02110036090016365,\n", + " 0.01245700754225254,\n", + " 0.009186173789203167,\n", + " -0.013605279847979546,\n", + " -0.009241847321391106,\n", + " 0.022812331095337868,\n", + " -0.014447345398366451,\n", + " 0.01606188528239727,\n", + " -0.007717777509242296,\n", + " -0.02835187129676342,\n", + " -0.01300678588449955,\n", + " 0.015574739314615726,\n", + " -0.016855236142873764,\n", + " -0.010870304889976978,\n", + " -0.02413458190858364,\n", + " -0.006492954213172197,\n", + " 0.020348764955997467,\n", + " -0.0074115716852247715,\n", + " 0.010063035413622856,\n", + " 0.010807672515511513,\n", + " 0.007613389287143946,\n", + " -0.019068269059062004,\n", + " -0.006099758204072714,\n", + " -0.0014170716749504209,\n", + " 0.006621699780225754,\n", + " -0.016479438170790672,\n", + " 0.002092986134812236,\n", + " -0.04807430878281593,\n", + " -0.005504744593054056,\n", + " 0.024844422936439514,\n", + " -0.0001052582374541089,\n", + " 0.009040029719471931,\n", + " 0.022213837131857872,\n", + " -0.017064012587070465,\n", + " 0.009986483491957188,\n", + " 0.0011830677976831794,\n", + " -0.0021956346463412046,\n", + " -0.00579703226685524,\n", + " -0.0256099384278059,\n", + " -0.01840018294751644,\n", + " 0.006339851301163435,\n", + " -0.040001608431339264,\n", + " -0.014203772880136967,\n", + " -0.015185022726655006,\n", + " -0.0026897394564002752,\n", + " 0.011127796024084091,\n", + " 0.003317809198051691,\n", + " 0.025860469788312912,\n", + " -0.02721055969595909,\n", + " -0.02076631970703602,\n", + " 0.04036349058151245,\n", + " 0.018817737698554993,\n", + " 0.04579168185591698,\n", + " -0.00551170390099287,\n", + " 0.019221371039748192,\n", + " 0.02080807462334633,\n", + " 0.0037440615706145763,\n", + " -0.021559670567512512,\n", + " 0.006343331187963486,\n", + " 0.009715074673295021,\n", + " 0.00015701744996476918,\n", + " 0.020056478679180145,\n", + " 0.0129023976624012,\n", + " -0.0039006441365927458,\n", + " -0.006256341002881527,\n", + " 0.021517915651202202,\n", + " 0.0004597436054609716,\n", + " -0.019972966983914375,\n", + " -0.03290320187807083,\n", + " 0.03579824045300484,\n", + " 0.020752400159835815,\n", + " 0.00993776973336935,\n", + " -0.032346464693546295,\n", + " -0.0074811638332903385,\n", + " -0.010257893241941929,\n", + " 0.0007637746166437864,\n", + " -0.021197790279984474,\n", + " 0.014990164898335934,\n", + " 0.01274233590811491,\n", + " -0.0037127451505512,\n", + " 0.025498589500784874,\n", + " 0.042172886431217194,\n", + " 0.03176188841462135,\n", + " -0.0022930637933313847,\n", + " -0.004081584047526121,\n", + " 0.0010151765309274197,\n", + " 0.023299476131796837,\n", + " -0.022854086011648178,\n", + " -0.02068280801177025,\n", + " 0.02015390805900097,\n", + " 0.0031890636309981346,\n", + " 0.05233335122466087,\n", + " -0.011844595894217491,\n", + " 0.007968309335410595,\n", + " -0.007919594645500183,\n", + " -0.004986282903701067,\n", + " 0.0010308347409591079,\n", + " -0.004561770241707563,\n", + " 0.002446166705340147,\n", + " 0.030453557148575783,\n", + " -0.02453821711242199,\n", + " 0.023508252575993538,\n", + " 0.006698251236230135,\n", + " -0.009902973659336567,\n", + " 0.00315948692150414,\n", + " -0.023633519187569618,\n", + " -0.0038693274836987257,\n", + " -0.000989079475402832,\n", + " -0.011002530343830585,\n", + " 0.013932363130152225,\n", + " 0.024524299427866936,\n", + " 0.008552883751690388,\n", + " -0.029813308268785477,\n", + " 0.014795306138694286,\n", + " -0.027558520436286926,\n", + " -0.010661528445780277,\n", + " 0.0010978173231706023,\n", + " -0.011601023375988007,\n", + " 0.014823143370449543,\n", + " -0.049187783151865005,\n", + " 0.002573172328993678,\n", + " 0.016576867550611496,\n", + " 0.01867855153977871,\n", + " 0.024078909307718277,\n", + " -0.006900068838149309,\n", + " -0.015379881486296654,\n", + " -0.003004644298925996,\n", + " 0.014795306138694286,\n", + " -0.025456834584474564,\n", + " 0.015185022726655006,\n", + " 0.009617645293474197,\n", + " -0.009882095269858837,\n", + " -0.0017050094902515411,\n", + " 0.004266003146767616,\n", + " -0.018622878938913345,\n", + " -0.02224167436361313,\n", + " 0.02318812906742096,\n", + " -0.019110023975372314,\n", + " -0.01757899485528469,\n", + " -8.628347859485075e-05,\n", + " -0.006934864912182093,\n", + " -0.010404037311673164,\n", + " 0.010445792227983475,\n", + " -0.003918041940778494,\n", + " 0.013633116148412228,\n", + " -0.0004345164343249053,\n", + " -0.008845171891152859,\n", + " -0.013674871996045113,\n", + " 0.01867855153977871,\n", + " 0.012505722232162952,\n", + " -0.01913786120712757,\n", + " 0.005007160361856222,\n", + " 0.004589607007801533,\n", + " -0.003333467524498701,\n", + " 0.02032092958688736,\n", + " 0.0017406754195690155,\n", + " -0.008267556317150593,\n", + " -0.028463218361139297,\n", + " -0.041282106190919876,\n", + " 0.005497785750776529,\n", + " 0.004008512012660503,\n", + " 0.019638925790786743,\n", + " -0.018219243735074997,\n", + " -0.0004571339231915772,\n", + " -0.02773945964872837,\n", + " -0.013041582889854908,\n", + " -0.0009960386669263244,\n", + " 0.006882670801132917,\n", + " -0.020014723762869835,\n", + " 0.017425892874598503,\n", + " 0.0157695971429348,\n", + " -0.011454880237579346,\n", + " 0.019235290586948395,\n", + " 0.011454880237579346,\n", + " -0.03454557806253433,\n", + " -0.018817737698554993,\n", + " 0.01174020767211914,\n", + " 0.003851929446682334,\n", + " -0.029562776908278465,\n", + " -0.016479438170790672,\n", + " -0.010181342251598835,\n", + " 0.04515143483877182,\n", + " -0.004725311882793903,\n", + " -0.00805182009935379,\n", + " -0.022213837131857872,\n", + " -0.025415079668164253,\n", + " -0.05600782111287117,\n", + " -0.021768447011709213,\n", + " -0.00012896308908239007,\n", + " 0.028699832037091255,\n", + " 0.006753925234079361,\n", + " 0.024273766204714775,\n", + " 0.0037927760276943445,\n", + " 0.017968712374567986,\n", + " -0.010515384376049042,\n", + " -0.00023596112441737205,\n", + " -0.02048795111477375,\n", + " 0.0010856386506929994,\n", + " -0.006176309660077095,\n", + " -0.012387415394186974,\n", + " 0.014976246282458305,\n", + " 0.02282624877989292,\n", + " -0.03240213915705681,\n", + " -0.005560418590903282,\n", + " 0.013869729824364185,\n", + " -0.016688214614987373,\n", + " -0.001046493067406118,\n", + " 0.02716880291700363,\n", + " 0.00014114173245616257,\n", + " -0.0033665236551314592,\n", + " 0.011322654783725739,\n", + " -0.006736527197062969,\n", + " 0.008712946437299252,\n", + " -0.0054629892110824585,\n", + " 0.010988611727952957,\n", + " -0.029228733852505684,\n", + " -0.008246677927672863,\n", + " 0.021573588252067566,\n", + " -0.00964548159390688,\n", + " -0.010285730473697186,\n", + " -0.01970851793885231,\n", + " 0.01810789667069912,\n", + " -0.002505319891497493,\n", + " -0.009401909075677395,\n", + " 0.00938103161752224,\n", + " -0.0040154713205993176,\n", + " 0.02548467181622982,\n", + " -0.016075802966952324,\n", + " 0.034183699637651443,\n", + " 0.011914188042283058,\n", + " 0.021378731355071068,\n", + " 0.01467004045844078,\n", + " 0.01020221970975399,\n", + " -0.003196022706106305,\n", + " -0.01802438497543335,\n", + " 0.01042491476982832,\n", + " 0.0015814832877367735,\n", + " 0.0004388659435790032,\n", + " 0.026932189241051674,\n", + " -0.01141312438994646,\n", + " -0.02925657108426094,\n", + " -0.01639592833817005,\n", + " -0.0022913238499313593,\n", + " -0.003418717999011278,\n", + " -0.026152757927775383,\n", + " -0.023160291835665703,\n", + " -0.00518462061882019,\n", + " -0.009534134529531002,\n", + " 0.013695749454200268,\n", + " 0.04147696495056152,\n", + " -0.03393316641449928,\n", + " 0.011044285260140896,\n", + " -0.003086415119469166,\n", + " 0.010480588302016258,\n", + " -0.00991689134389162,\n", + " -0.006151952315121889,\n", + " -0.002573172328993678,\n", + " -0.023160291835665703,\n", + " 0.016089722514152527,\n", + " 0.004151176195591688,\n", + " -0.01016046479344368,\n", + " -0.0054490710608661175,\n", + " -0.001388364820741117,\n", + " 0.014148098416626453,\n", + " -0.01065456960350275,\n", + " -0.003938919864594936,\n", + " 0.20354333519935608,\n", + " -0.02531765028834343,\n", + " -0.006614740937948227,\n", + " 0.03307022526860237,\n", + " 0.009582849219441414,\n", + " -0.018288835883140564,\n", + " 0.014294242486357689,\n", + " 0.009436705149710178,\n", + " 0.00016647765005473047,\n", + " -0.007098406553268433,\n", + " -0.003469172166660428,\n", + " 0.0052994475699961185,\n", + " -0.009861217811703682,\n", + " 0.008100534789264202,\n", + " 0.025512509047985077,\n", + " -0.012408292852342129,\n", + " -0.041811008006334305,\n", + " -0.04782377555966377,\n", + " -0.015491228550672531,\n", + " 0.02044619433581829,\n", + " -0.007300224155187607,\n", + " -0.010905100964009762,\n", + " -0.008685109205543995,\n", + " -0.03429504856467247,\n", + " 0.001087378477677703,\n", + " 5.6489312555640936e-05,\n", + " -0.01732846349477768,\n", + " -0.0006467727362178266,\n", + " 0.009033070877194405,\n", + " 0.004791424609720707,\n", + " -0.010452752001583576,\n", + " -0.0016049706609919667,\n", + " 0.007237591315060854,\n", + " 0.01421769056469202,\n", + " 0.00166151428129524,\n", + " 0.006179789546877146,\n", + " 0.008295392617583275,\n", + " -0.0020164346788078547,\n", + " 0.006468596868216991,\n", + " 0.00733502022922039,\n", + " 0.015880944207310677,\n", + " -0.0045930868946015835,\n", + " 0.009450623765587807,\n", + " -0.03421153500676155,\n", + " 0.007087967824190855,\n", + " 0.01642376370728016,\n", + " ...],\n", + " [-0.015102829784154892,\n", + " -0.009500386193394661,\n", + " 0.008536086417734623,\n", + " -0.01692277565598488,\n", + " -0.03112921305000782,\n", + " 0.012597009539604187,\n", + " -0.015333718620240688,\n", + " -0.026266971603035927,\n", + " -0.006091384217143059,\n", + " -0.014124948531389236,\n", + " 0.009344196878373623,\n", + " 0.024487771093845367,\n", + " 0.011972252279520035,\n", + " -0.003965850919485092,\n", + " -0.014124948531389236,\n", + " 0.010159097611904144,\n", + " 0.04498253017663956,\n", + " 0.0030592738185077906,\n", + " 0.006138919852674007,\n", + " -0.026878148317337036,\n", + " -0.0051848068833351135,\n", + " 0.010654829442501068,\n", + " -0.005500581115484238,\n", + " -0.0042748344130814075,\n", + " -0.00960903987288475,\n", + " -0.0021594874560832977,\n", + " 0.021010860800743103,\n", + " -0.03748543933033943,\n", + " 0.012006206437945366,\n", + " -0.017017846927046776,\n", + " 0.014491654001176357,\n", + " -0.01235933043062687,\n", + " -0.023930922150611877,\n", + " -0.03705082833766937,\n", + " -0.03702366352081299,\n", + " -0.02628055401146412,\n", + " -0.01094683539122343,\n", + " -0.0036161227617412806,\n", + " 0.0032799760811030865,\n", + " 0.007483506575226784,\n", + " 0.010600502602756023,\n", + " 0.02144547551870346,\n", + " -0.0064241355285048485,\n", + " 0.007225454319268465,\n", + " -0.018117962405085564,\n", + " -0.024881640449166298,\n", + " 0.012101277709007263,\n", + " -0.011490102857351303,\n", + " -0.01540162693709135,\n", + " -0.0031933928839862347,\n", + " 0.005503976251929998,\n", + " 0.016569651663303375,\n", + " -0.02522118203341961,\n", + " -0.004037154838442802,\n", + " -0.013581681065261364,\n", + " 0.013452655635774136,\n", + " -0.014016294851899147,\n", + " 0.01954403892159462,\n", + " 0.0012766780564561486,\n", + " -0.017629021778702736,\n", + " 0.0028996889013797045,\n", + " 0.001703652204014361,\n", + " -0.014668215997517109,\n", + " 0.004033759236335754,\n", + " -0.004057527519762516,\n", + " 0.001213862793520093,\n", + " -0.006159292533993721,\n", + " 0.008902791887521744,\n", + " 0.016719050705432892,\n", + " -0.01799572817981243,\n", + " 0.022844389081001282,\n", + " 0.039631348103284836,\n", + " 0.0077687217853963375,\n", + " 0.005643188487738371,\n", + " 0.013235348276793957,\n", + " -0.01492626778781414,\n", + " -0.00801998283714056,\n", + " -0.009812764823436737,\n", + " -0.010586921125650406,\n", + " 0.00220702332444489,\n", + " 0.0380830354988575,\n", + " -0.02539774402976036,\n", + " -0.008264453150331974,\n", + " 0.009561503306031227,\n", + " 0.015537443570792675,\n", + " 0.01659681461751461,\n", + " 0.01420643925666809,\n", + " 0.008773766458034515,\n", + " -0.010783854871988297,\n", + " 0.023251838982105255,\n", + " 0.015632515773177147,\n", + " 0.02450135350227356,\n", + " -0.0038605928421020508,\n", + " 0.032107096165418625,\n", + " -0.019734183326363564,\n", + " 0.013167439959943295,\n", + " -0.016691885888576508,\n", + " 0.020236704498529434,\n", + " 0.005969149060547352,\n", + " -0.024528516456484795,\n", + " 0.014342255890369415,\n", + " -0.0033512800000607967,\n", + " -0.011062279343605042,\n", + " 0.0010839879978448153,\n", + " -0.019557621330022812,\n", + " -0.011911134235560894,\n", + " 0.020616993308067322,\n", + " -0.01726231724023819,\n", + " 0.024338373914361,\n", + " -0.016949938610196114,\n", + " -0.01859332248568535,\n", + " 0.02895614504814148,\n", + " 0.0018793651834130287,\n", + " -0.040908023715019226,\n", + " 0.0003889878571499139,\n", + " 0.008671903982758522,\n", + " 0.0002548687334638089,\n", + " -0.018117962405085564,\n", + " -0.009337405674159527,\n", + " -0.008311988785862923,\n", + " 0.021676363423466682,\n", + " -0.005908031482249498,\n", + " 0.025248344987630844,\n", + " -0.002864037174731493,\n", + " 0.017506787553429604,\n", + " 0.008169380947947502,\n", + " 0.0010440917685627937,\n", + " -0.015197901986539364,\n", + " -0.010233797132968903,\n", + " 0.0006052336539141834,\n", + " 0.030721763148903847,\n", + " 0.033383771777153015,\n", + " 0.020454011857509613,\n", + " 0.006386785767972469,\n", + " -0.03501357510685921,\n", + " 0.024827314540743828,\n", + " -0.023863013833761215,\n", + " 0.02126891352236271,\n", + " -0.040962349623441696,\n", + " -0.03457896038889885,\n", + " -0.0017452461179345846,\n", + " 0.004264648072421551,\n", + " -0.017778420820832253,\n", + " -0.020915789529681206,\n", + " 0.008542877621948719,\n", + " 0.014233602210879326,\n", + " 0.027434997260570526,\n", + " 0.022627081722021103,\n", + " 0.0011221864260733128,\n", + " -0.016393089666962624,\n", + " 0.015102829784154892,\n", + " -0.011476520448923111,\n", + " 0.02952657639980316,\n", + " 0.0034938876051455736,\n", + " 0.003497282974421978,\n", + " 0.0062951091676950455,\n", + " -0.015727587044239044,\n", + " -0.00835273414850235,\n", + " -0.01492626778781414,\n", + " 0.0036466815508902073,\n", + " 0.01455956231802702,\n", + " 0.0024565865751355886,\n", + " -0.0021357194054871798,\n", + " -0.011782108806073666,\n", + " 0.009812764823436737,\n", + " 0.04443925991654396,\n", + " 0.009507177397608757,\n", + " 0.008570040576159954,\n", + " 0.009819556027650833,\n", + " -0.016854867339134216,\n", + " -0.028032589703798294,\n", + " 0.027027545496821404,\n", + " -0.0035923547111451626,\n", + " 0.003741753287613392,\n", + " 0.006536184344440699,\n", + " 0.030259985476732254,\n", + " 0.002327560679987073,\n", + " 0.002383585087954998,\n", + " -0.03637174144387245,\n", + " -0.006200037430971861,\n", + " -0.014192856848239899,\n", + " 0.029445085674524307,\n", + " 0.026199063286185265,\n", + " 0.03919673338532448,\n", + " -0.025968175381422043,\n", + " -0.0009125192300416529,\n", + " 0.027136199176311493,\n", + " -0.0025312858633697033,\n", + " 0.010464685969054699,\n", + " -0.033329445868730545,\n", + " 0.005717888008803129,\n", + " 0.014328673481941223,\n", + " 0.01255626417696476,\n", + " -0.017669767141342163,\n", + " -0.6897321343421936,\n", + " -0.013744661584496498,\n", + " 0.012087696231901646,\n", + " -0.008278034627437592,\n", + " 0.00846817810088396,\n", + " 0.021513383835554123,\n", + " -0.004420837387442589,\n", + " 0.01024737861007452,\n", + " -0.02712261863052845,\n", + " -0.0006200886564329267,\n", + " -0.0034140951465815306,\n", + " 0.02026386931538582,\n", + " -0.007986028678715229,\n", + " -0.020372522994875908,\n", + " -0.01235933043062687,\n", + " 0.005361368879675865,\n", + " 0.015605351887643337,\n", + " -0.01642025262117386,\n", + " 0.000735532958060503,\n", + " 0.011327122338116169,\n", + " -0.028331387788057327,\n", + " -0.00014281987387221307,\n", + " -0.008413851261138916,\n", + " 0.014423745684325695,\n", + " 0.007395225577056408,\n", + " -0.01333721075206995,\n", + " -0.004400464706122875,\n", + " -0.010838181711733341,\n", + " -0.006515811663120985,\n", + " -0.01709933765232563,\n", + " -0.030667437240481377,\n", + " 0.02099728025496006,\n", + " 0.0057891919277608395,\n", + " -0.019679855555295944,\n", + " 0.04514550790190697,\n", + " -0.018905701115727425,\n", + " -0.009452850557863712,\n", + " 0.02211097814142704,\n", + " 5.549390334635973e-05,\n", + " 0.022912297397851944,\n", + " -0.008739812299609184,\n", + " -0.011198095977306366,\n", + " 0.023808687925338745,\n", + " 0.006549765821546316,\n", + " 0.0024990292731672525,\n", + " -0.005018431227654219,\n", + " 0.007918120361864567,\n", + " -0.011150560341775417,\n", + " 0.016746213659644127,\n", + " -0.01150368433445692,\n", + " -0.005147457122802734,\n", + " -0.0042714388109743595,\n", + " -0.014084204100072384,\n", + " -0.0018742720130831003,\n", + " 0.004169576335698366,\n", + " -0.010532594285905361,\n", + " 0.02511252835392952,\n", + " -0.034171510487794876,\n", + " 0.008339152671396732,\n", + " -0.0005224703345447779,\n", + " -0.002718033967539668,\n", + " -0.0004375847929622978,\n", + " -0.008067518472671509,\n", + " -0.007177918683737516,\n", + " -0.025098947808146477,\n", + " 0.027978263795375824,\n", + " -0.007272990420460701,\n", + " 0.004339347127825022,\n", + " 0.00983313750475645,\n", + " -0.003076250897720456,\n", + " -0.0030372035689651966,\n", + " -0.0006323970155790448,\n", + " -0.03384555131196976,\n", + " -0.01255626417696476,\n", + " 0.0022986996918916702,\n", + " 0.01350698247551918,\n", + " 0.020250286906957626,\n", + " -0.021785017102956772,\n", + " 0.0033020463306456804,\n", + " 0.015523862093687057,\n", + " 0.013106322847306728,\n", + " 0.006240782793611288,\n", + " -0.014790451154112816,\n", + " 0.0043461378663778305,\n", + " 0.03732246160507202,\n", + " -0.016216527670621872,\n", + " -0.01688203029334545,\n", + " 0.007680440787225962,\n", + " 0.024827314540743828,\n", + " -0.009418896399438381,\n", + " 0.004573631100356579,\n", + " 0.03224291279911995,\n", + " 0.022369029000401497,\n", + " -0.023876596242189407,\n", + " -0.020413266494870186,\n", + " 0.006919866893440485,\n", + " -0.006047243718057871,\n", + " -0.0028148035053163767,\n", + " -0.0068553537130355835,\n", + " 4.679313860833645e-05,\n", + " -0.024813732132315636,\n", + " -0.01225067675113678,\n", + " 0.01180248148739338,\n", + " -0.003931896761059761,\n", + " 0.014967013150453568,\n", + " 0.012651336379349232,\n", + " -0.0024124460760504007,\n", + " 0.013344001956284046,\n", + " 0.02890181727707386,\n", + " -0.035719823092222214,\n", + " 0.015211483463644981,\n", + " -0.0247865691781044,\n", + " 0.0022375821135938168,\n", + " -0.009765229187905788,\n", + " 0.010641247034072876,\n", + " -0.02968955598771572,\n", + " 0.028603021055459976,\n", + " 0.02789677307009697,\n", + " 0.028195571154356003,\n", + " -0.003395420266315341,\n", + " 0.012488355860114098,\n", + " 0.0006892703240737319,\n", + " 0.01636592671275139,\n", + " -0.0034242814872413874,\n", + " 0.005768819246441126,\n", + " 0.019584784284234047,\n", + " -0.03218858689069748,\n", + " -0.016854867339134216,\n", + " -0.02082071825861931,\n", + " -0.0032884646207094193,\n", + " -0.005144061986356974,\n", + " 0.023849433287978172,\n", + " 0.015048502944409847,\n", + " -0.006784049794077873,\n", + " 0.023700034245848656,\n", + " 0.006335854530334473,\n", + " 0.025153273716568947,\n", + " -0.013934805057942867,\n", + " 0.007435970474034548,\n", + " -0.013323629274964333,\n", + " -0.015972057357430458,\n", + " -0.01642025262117386,\n", + " 0.002370003378018737,\n", + " -0.017968565225601196,\n", + " 0.007782303262501955,\n", + " -0.03281334415078163,\n", + " -0.01688203029334545,\n", + " 0.004278229549527168,\n", + " -0.01893286406993866,\n", + " 0.002507518045604229,\n", + " 0.00489959167316556,\n", + " 0.006254364270716906,\n", + " -0.012637754902243614,\n", + " 0.009663366712629795,\n", + " 0.009629412554204464,\n", + " -0.014858359470963478,\n", + " -0.026266971603035927,\n", + " -0.004665307700634003,\n", + " -0.007171127945184708,\n", + " -0.01235933043062687,\n", + " 0.010410359129309654,\n", + " 0.025642214342951775,\n", + " -0.004176367074251175,\n", + " 0.01183643564581871,\n", + " -0.01576833240687847,\n", + " -0.006539579480886459,\n", + " -0.022124558687210083,\n", + " 0.002349630929529667,\n", + " 0.005857100244611502,\n", + " -0.025587888434529305,\n", + " 0.012902596965432167,\n", + " -0.04264647886157036,\n", + " 0.006678791716694832,\n", + " -0.002738406416028738,\n", + " -0.004227298311889172,\n", + " 0.004431023728102446,\n", + " -0.013934805057942867,\n", + " 0.013792197220027447,\n", + " 0.017384551465511322,\n", + " -0.013676753267645836,\n", + " 0.01121846865862608,\n", + " 0.012563055381178856,\n", + " 0.0006311237812042236,\n", + " -0.013466237112879753,\n", + " 0.014410164207220078,\n", + " -0.0030813440680503845,\n", + " 0.013534145429730415,\n", + " 0.0299068633466959,\n", + " -0.018280943855643272,\n", + " 0.010179470293223858,\n", + " 0.00096939253853634,\n", + " 0.005079548805952072,\n", + " 0.0016832796391099691,\n", + " 0.008950328454375267,\n", + " 0.008373106829822063,\n", + " -0.005697515327483416,\n", + " 0.008318779990077019,\n", + " 0.010607292875647545,\n", + " 0.016298018395900726,\n", + " 0.013989131897687912,\n", + " 0.004410651046782732,\n", + " -0.01366996206343174,\n", + " 0.013574890792369843,\n", + " -0.005877472460269928,\n", + " 0.017411716282367706,\n", + " -0.019177334383130074,\n", + " 0.008108263835310936,\n", + " -0.023374073207378387,\n", + " 0.016121456399559975,\n", + " 0.006159292533993721,\n", + " 0.012040160596370697,\n", + " -0.01954403892159462,\n", + " -0.0105529660359025,\n", + " -0.004105063155293465,\n", + " 0.006118547637015581,\n", + " 0.023795105516910553,\n", + " -0.009805973619222641,\n", + " 0.024691496044397354,\n", + " -0.01815870776772499,\n", + " 0.0015517071587964892,\n", + " 0.020535502582788467,\n", + " -0.021975161507725716,\n", + " -0.004251066129654646,\n", + " -0.004288415890187025,\n", + " -0.009955372661352158,\n", + " 0.002918363781645894,\n", + " 0.023917341604828835,\n", + " 0.012712453491985798,\n", + " -0.003195090452209115,\n", + " -0.0007881619385443628,\n", + " -0.006155896931886673,\n", + " 0.008142217993736267,\n", + " -0.008264453150331974,\n", + " 0.013602053746581078,\n", + " 0.0005746749229729176,\n", + " -0.0019319942221045494,\n", + " 0.002904782071709633,\n", + " 0.004359719809144735,\n", + " 0.015537443570792675,\n", + " 0.01002328097820282,\n", + " -0.008060728199779987,\n", + " 0.03732246160507202,\n", + " 0.02211097814142704,\n", + " -0.00899107288569212,\n", + " 0.03270468860864639,\n", + " 0.017303062602877617,\n", + " 0.03680635616183281,\n", + " -0.0004545619012787938,\n", + " 0.009011445567011833,\n", + " 0.001637441455386579,\n", + " 0.0054326727986335754,\n", + " 0.001069557387381792,\n", + " -0.019802091643214226,\n", + " -0.0028453622944653034,\n", + " 0.009921418502926826,\n", + " -0.005364764016121626,\n", + " 0.0036127271596342325,\n", + " 0.01436941884458065,\n", + " 0.026552187278866768,\n", + " 0.01311311312019825,\n", + " 0.016121456399559975,\n", + " 0.005368159618228674,\n", + " 0.010315286926925182,\n", + " 0.0037791028153151274,\n", + " 0.002015182049944997,\n", + " 0.010457894764840603,\n", + " -0.022898714989423752,\n", + " -0.020684901624917984,\n", + " 0.011007952503859997,\n", + " 0.008216917514801025,\n", + " -0.003867383813485503,\n", + " -0.005649979691952467,\n", + " 0.01155121996998787,\n", + " -0.010824600234627724,\n", + " 0.012243885546922684,\n", + " 0.00672293221578002,\n", + " 0.009092935360968113,\n", + " 0.014980594627559185,\n", + " -0.0004715390095952898,\n", + " 0.007082846947014332,\n", + " 0.00412204023450613,\n", + " -0.043352726846933365,\n", + " 0.01280752569437027,\n", + " 0.02338765561580658,\n", + " -0.01381256990134716,\n", + " -0.009147262200713158,\n", + " -0.004709448199719191,\n", + " -0.016135036945343018,\n", + " 0.0007996215135790408,\n", + " 0.022599918767809868,\n", + " 0.0033444890286773443,\n", + " 0.0011994322994723916,\n", + " 0.009989326819777489,\n", + " 0.002549960743635893,\n", + " 0.016623977571725845,\n", + " 0.0028012217953801155,\n", + " 0.007150755263864994,\n", + " -0.013574890792369843,\n", + " 0.01439658273011446,\n", + " -0.015265810303390026,\n", + " -0.0019184125121682882,\n", + " -0.007469924632459879,\n", + " 0.005918217822909355,\n", + " -0.012040160596370697,\n", + " 0.010668410919606686,\n", + " 0.01821303553879261,\n", + " 0.0010670108022168279,\n", + " -0.0020440430380403996,\n", + " -0.018688393756747246,\n", + " 0.00309832114726305,\n", + " 0.012692081741988659,\n", + " 0.004105063155293465,\n", + " -0.009520758874714375,\n", + " 0.008678694255650043,\n", + " -0.004254461731761694,\n", + " -0.010036862455308437,\n", + " 0.010383195243775845,\n", + " 0.005799377802759409,\n", + " 0.012189558707177639,\n", + " -0.01582265831530094,\n", + " -0.02633487991988659,\n", + " -0.014233602210879326,\n", + " -0.015551025047898293,\n", + " -0.0037451486568897963,\n", + " 0.05970507115125656,\n", + " 0.03824601322412491,\n", + " -0.0012155604781582952,\n", + " 0.0021594874560832977,\n", + " 0.02049475722014904,\n", + " 0.010838181711733341,\n", + " -0.014858359470963478,\n", + " -0.013323629274964333,\n", + " -0.00977201946079731,\n", + " -0.010199842974543571,\n", + " -0.0004259130510035902,\n", + " 0.004539676941931248,\n", + " 0.007042102050036192,\n", + " -0.0056601655669510365,\n", + " -0.012074114754796028,\n", + " 0.009812764823436737,\n", + " -0.0011960368137806654,\n", + " -0.025139693170785904,\n", + " -0.0007189802709035575,\n", + " -0.03938687592744827,\n", + " -0.013785406947135925,\n", + " -0.001056824577972293,\n", + " 0.011238841339945793,\n", + " 0.00946643203496933,\n", + " -0.006593906320631504,\n", + " -0.012271049432456493,\n", + " 0.030776090919971466,\n", + " 0.02133682183921337,\n", + " 0.009962162934243679,\n", + " -0.04047340899705887,\n", + " -0.02211097814142704,\n", + " 0.026049664244055748,\n", + " 0.009120099246501923,\n", + " -0.011395030654966831,\n", + " -0.0176018588244915,\n", + " 0.011272795498371124,\n", + " 0.013018041849136353,\n", + " 0.003908128943294287,\n", + " 0.015048502944409847,\n", + " -0.0038605928421020508,\n", + " 0.028331387788057327,\n", + " 0.022396191954612732,\n", + " 0.0036466815508902073,\n", + " -0.006227200850844383,\n", + " 0.008896001614630222,\n", + " -0.028521530330181122,\n", + " -0.003711194498464465,\n", + " -0.001570381922647357,\n", + " -0.0016442323103547096,\n", + " -0.02505820244550705,\n", + " 0.03140084818005562,\n", + " 0.012515519745647907,\n", + " -0.02595459297299385,\n", + " -0.020807135850191116,\n", + " -0.010084398090839386,\n", + " 0.017629021778702736,\n", + " -0.0018640857888385653,\n", + " -0.018199453130364418,\n", + " -0.008230498991906643,\n", + " 0.003025319427251816,\n", + " -0.008278034627437592,\n", + " -0.020630573853850365,\n", + " 0.0035685868933796883,\n", + " -0.0037723120767623186,\n", + " 0.005225551780313253,\n", + " -0.02985253557562828,\n", + " -0.019462550058960915,\n", + " -0.0034293746575713158,\n", + " -0.005340996198356152,\n", + " -0.010457894764840603,\n", + " -0.0016739421989768744,\n", + " -0.024637170135974884,\n", + " -0.016406672075390816,\n", + " -0.005473417695611715,\n", + " 0.02617190033197403,\n", + " 0.008291616104543209,\n", + " -0.001848806394264102,\n", + " -0.008135426789522171,\n", + " 0.00876697525382042,\n", + " 0.023876596242189407,\n", + " -0.0065803248435258865,\n", + " -0.02417539246380329,\n", + " -0.02188008837401867,\n", + " -0.007150755263864994,\n", + " 0.0051033166237175465,\n", + " 0.00816259067505598,\n", + " -0.00824408046901226,\n", + " -0.016623977571725845,\n", + " -0.002952317940071225,\n", + " 0.001025417004711926,\n", + " -0.012128441594541073,\n", + " 0.011870389804244041,\n", + " 0.019924325868487358,\n", + " -0.008794139139354229,\n", + " 0.007707604207098484,\n", + " 0.0010194749338552356,\n", + " 0.02522118203341961,\n", + " 0.006264550611376762,\n", + " -0.005405509378761053,\n", + " -0.02283080667257309,\n", + " 0.00616608327254653,\n", + " -0.013880478218197823,\n", + " 0.004733216017484665,\n", + " -0.011816062964498997,\n", + " 0.004217111971229315,\n", + " 0.015279391780495644,\n", + " -0.00423408905044198,\n", + " 0.019000772386789322,\n", + " -0.033166464418172836,\n", + " -0.012746407650411129,\n", + " 0.018864955753087997,\n", + " 0.0036059364210814238,\n", + " -0.00849534198641777,\n", + " -0.0026721959002316,\n", + " 0.007863793522119522,\n", + " 0.012895806692540646,\n", + " -0.00943926814943552,\n", + " 0.00932382419705391,\n", + " 0.014505235478281975,\n", + " -0.007531042210757732,\n", + " -0.021744271740317345,\n", + " -0.018348852172493935,\n", + " 0.021920833736658096,\n", + " -0.008026774041354656,\n", + " -0.006305295508354902,\n", + " -0.02033177763223648,\n", + " 0.009391732513904572,\n", + " -0.021785017102956772,\n", + " 0.005806169006973505,\n", + " 0.01336437463760376,\n", + " -0.008712648414075375,\n", + " 0.02645711600780487,\n", + " -0.004729820415377617,\n", + " -0.018348852172493935,\n", + " -0.015225064940750599,\n", + " -0.00690628495067358,\n", + " -0.01183643564581871,\n", + " 0.021105932071805,\n", + " -0.010919671505689621,\n", + " -0.009975745342671871,\n", + " -0.011395030654966831,\n", + " 0.01643383502960205,\n", + " -2.394036710029468e-05,\n", + " -0.019869999960064888,\n", + " -0.009602248668670654,\n", + " -0.045580122619867325,\n", + " -0.011734573170542717,\n", + " 0.003999805077910423,\n", + " 0.024025995284318924,\n", + " 0.022233212366700172,\n", + " 0.011089443229138851,\n", + " -0.0013089345302432775,\n", + " -0.029417922720313072,\n", + " -0.0299068633466959,\n", + " -0.019611947238445282,\n", + " -0.03925105929374695,\n", + " -0.010525803081691265,\n", + " -0.03096623346209526,\n", + " 0.016012802720069885,\n", + " 0.008345942944288254,\n", + " 0.024935966357588768,\n", + " 0.024990294128656387,\n", + " -0.008474969305098057,\n", + " -0.00023322293418459594,\n", + " -0.008427433669567108,\n", + " 0.005191597621887922,\n", + " -0.012630963698029518,\n", + " 0.006152501795440912,\n", + " -0.0197613462805748,\n", + " 0.015428789891302586,\n", + " 0.02868451178073883,\n", + " -0.009778810665011406,\n", + " 0.011089443229138851,\n", + " -0.00016966491239145398,\n", + " 0.007918120361864567,\n", + " 0.024908803403377533,\n", + " 0.0012647940311580896,\n", + " -0.015904149040579796,\n", + " -0.0051542483270168304,\n", + " -0.03140084818005562,\n", + " -0.01058012992143631,\n", + " -0.013051996007561684,\n", + " -0.015238646417856216,\n", + " 0.01776483841240406,\n", + " -0.027638722211122513,\n", + " -0.0014150413917377591,\n", + " 0.020752809941768646,\n", + " 0.017058592289686203,\n", + " 0.01993790827691555,\n", + " -0.0034022112376987934,\n", + " 0.016800539568066597,\n", + " -0.0029217591509222984,\n", + " 0.007123591843992472,\n", + " -0.005571885034441948,\n", + " -0.003497282974421978,\n", + " -0.004403860308229923,\n", + " -0.011150560341775417,\n", + " -0.005748446565121412,\n", + " -0.02857585810124874,\n", + " 0.015537443570792675,\n", + " -0.00821012631058693,\n", + " -0.01069557387381792,\n", + " -0.008169380947947502,\n", + " -0.0052323429845273495,\n", + " -0.01094683539122343,\n", + " 0.00843422394245863,\n", + " -0.02689172886312008,\n", + " -0.019353896379470825,\n", + " -0.02288513258099556,\n", + " 0.002291908720508218,\n", + " -0.005493790376931429,\n", + " -0.01697710156440735,\n", + " -0.01659681461751461,\n", + " -0.034443143755197525,\n", + " 0.02076639048755169,\n", + " 0.01909584365785122,\n", + " -0.019503295421600342,\n", + " 0.024012412875890732,\n", + " -0.00821012631058693,\n", + " -0.026049664244055748,\n", + " 0.01688203029334545,\n", + " 0.0022664431016892195,\n", + " 0.022015905007719994,\n", + " 0.015157156623899937,\n", + " 0.016189364716410637,\n", + " 0.023971667513251305,\n", + " -0.011856808327138424,\n", + " -0.015197901986539364,\n", + " -0.0013233651407063007,\n", + " 0.007123591843992472,\n", + " -0.004665307700634003,\n", + " 0.025927430018782616,\n", + " -0.002427725587040186,\n", + " -0.010362822562456131,\n", + " -0.01754753291606903,\n", + " 0.032541707158088684,\n", + " -0.00701493863016367,\n", + " -0.02194799669086933,\n", + " -0.009656575508415699,\n", + " 0.011089443229138851,\n", + " 0.011374657973647118,\n", + " -0.0037485440261662006,\n", + " 0.00738164409995079,\n", + " -0.018634067848324776,\n", + " -0.0192180797457695,\n", + " 0.015265810303390026,\n", + " -0.0032222538720816374,\n", + " -0.0011977344984188676,\n", + " -0.013235348276793957,\n", + " -0.03218858689069748,\n", + " -0.007069265004247427,\n", + " 0.013038414530456066,\n", + " -0.011965461075305939,\n", + " 0.01392122358083725,\n", + " -0.01280752569437027,\n", + " -0.009541131556034088,\n", + " -0.02266782708466053,\n", + " -0.018566157668828964,\n", + " -0.013045204803347588,\n", + " 0.008841674774885178,\n", + " -0.002704452257603407,\n", + " 0.025587888434529305,\n", + " 0.0004163634148426354,\n", + " 0.011123397387564182,\n", + " 0.029363594949245453,\n", + " -0.007062474265694618,\n", + " -0.030395803973078728,\n", + " 0.009907837025821209,\n", + " 0.000835273414850235,\n", + " 0.030422966927289963,\n", + " -0.019978653639554977,\n", + " 0.010824600234627724,\n", + " 0.010892508551478386,\n", + " 0.00014207711501512676,\n", + " -0.0027655698359012604,\n", + " 0.0001869603293016553,\n", + " -0.016121456399559975,\n", + " -0.00888241920620203,\n", + " -0.034551799297332764,\n", + " -0.0025941012427210808,\n", + " 0.0077687217853963375,\n", + " 0.0033869317267090082,\n", + " -0.03832750394940376,\n", + " -0.02099728025496006,\n", + " -0.008834883570671082,\n", + " -0.041071005165576935,\n", + " -0.005629607010632753,\n", + " -0.011395030654966831,\n", + " -0.014545980840921402,\n", + " 0.006335854530334473,\n", + " -0.027041127905249596,\n", + " -0.017629021778702736,\n", + " 0.002047438407316804,\n", + " 0.01233216654509306,\n", + " 0.0021577896550297737,\n", + " -0.006617674138396978,\n", + " 0.0113610764965415,\n", + " 0.016800539568066597,\n", + " -0.01798214577138424,\n", + " 0.031156377866864204,\n", + " -0.006739909294992685,\n", + " 0.023509889841079712,\n", + " -0.012080905959010124,\n", + " 0.004064318258315325,\n", + " -0.028277060016989708,\n", + " -0.007157546002417803,\n", + " 0.005836727563291788,\n", + " -0.011211678385734558,\n", + " -0.028277060016989708,\n", + " -0.024582844227552414,\n", + " 0.0037213806062936783,\n", + " -0.001502473489381373,\n", + " 0.0009906139457598329,\n", + " -0.016216527670621872,\n", + " 0.00583333196118474,\n", + " 0.0136495903134346,\n", + " -0.0043970695696771145,\n", + " -0.006804422475397587,\n", + " -0.024460608139634132,\n", + " 0.0054598357528448105,\n", + " -0.006033661775290966,\n", + " -0.009194798767566681,\n", + " 0.01049864012748003,\n", + " -0.016719050705432892,\n", + " -0.004858846310526133,\n", + " 0.014790451154112816,\n", + " 0.000968543638009578,\n", + " 0.0036466815508902073,\n", + " -0.01381256990134716,\n", + " -0.009541131556034088,\n", + " -0.022314703091979027,\n", + " 0.018783465027809143,\n", + " -0.01938105933368206,\n", + " 0.004835078492760658,\n", + " -0.01803647354245186,\n", + " 0.004665307700634003,\n", + " 0.0052595059387385845,\n", + " 0.010172679089009762,\n", + " -0.01484477799385786,\n", + " -0.011170933023095131,\n", + " 0.004916568752378225,\n", + " 0.0111369788646698,\n", + " -0.012067323550581932,\n", + " 0.013181021437048912,\n", + " -0.005150852724909782,\n", + " -0.014233602210879326,\n", + " 0.0057925870642066,\n", + " -0.001993111800402403,\n", + " -0.014613889157772064,\n", + " -0.02177143469452858,\n", + " 0.004590608179569244,\n", + " 0.02634846232831478,\n", + " 0.009595458395779133,\n", + " -0.03876211866736412,\n", + " -0.033112138509750366,\n", + " 0.012277839705348015,\n", + " -0.04395032301545143,\n", + " -0.008671903982758522,\n", + " 0.009181216359138489,\n", + " -0.008074309676885605,\n", + " 0.005286669358611107,\n", + " -0.004699261859059334,\n", + " -0.0065022301860153675,\n", + " 0.014912686310708523,\n", + " -0.004773960914462805,\n", + " 0.03903375193476677,\n", + " -0.006149106193333864,\n", + " 0.009167634882032871,\n", + " -0.01381256990134716,\n", + " -0.016053548082709312,\n", + " 0.003140763845294714,\n", + " -0.010193051770329475,\n", + " -0.04063639044761658,\n", + " -0.00616608327254653,\n", + " 0.01916375197470188,\n", + " 0.010464685969054699,\n", + " 0.020073724910616875,\n", + " 0.017941400408744812,\n", + " -0.01798214577138424,\n", + " -0.00040511609404347837,\n", + " -0.02500387467443943,\n", + " -0.0015542536275461316,\n", + " -0.0031662294641137123,\n", + " -0.005514162592589855,\n", + " -0.0026144736912101507,\n", + " 0.0027299178764224052,\n", + " -0.003979432862251997,\n", + " 0.0023869804572314024,\n", + " -0.00835273414850235,\n", + " -0.03330228477716446,\n", + " -0.015428789891302586,\n", + " 0.004777356516569853,\n", + " 0.011829644441604614,\n", + " 0.002982876729220152,\n", + " -0.02778811939060688,\n", + " -0.03164531663060188,\n", + " 0.00646148482337594,\n", + " -0.015618933364748955,\n", + " 0.004651725757867098,\n", + " 0.028277060016989708,\n", + " 0.0008751695859245956,\n", + " 0.019014354795217514,\n", + " 0.029363594949245453,\n", + " -0.01214202307164669,\n", + " -0.014804032631218433,\n", + " 0.0009651482105255127,\n", + " -0.011069070547819138,\n", + " -0.012216722592711449,\n", + " 0.0010008001700043678,\n", + " -0.030368639156222343,\n", + " -0.021092351526021957,\n", + " 0.012488355860114098,\n", + " 0.025533560663461685,\n", + " -0.006369808688759804,\n", + " -0.004892800934612751,\n", + " -0.008760184980928898,\n", + " -0.017031429335474968,\n", + " 0.0039964099414646626,\n", + " 0.013975550420582294,\n", + " 0.017085755243897438,\n", + " -0.006899494212120771,\n", + " -0.0006026871269568801,\n", + " 0.0030881348066031933,\n", + " -0.02451493591070175,\n", + " -0.007483506575226784,\n", + " 0.004807915072888136,\n", + " 0.00738164409995079,\n", + " 0.0222739577293396,\n", + " -0.014070621691644192,\n", + " 0.014817614108324051,\n", + " 0.0008946932503022254,\n", + " -0.009527549147605896,\n", + " -0.027163362130522728,\n", + " 0.029608065262436867,\n", + " -0.0009829741902649403,\n", + " 0.0046279579401016235,\n", + " 0.1850368231534958,\n", + " 0.009364569559693336,\n", + " -0.006519207265228033,\n", + " 0.05535893514752388,\n", + " 0.009676948189735413,\n", + " 0.001647627679631114,\n", + " 0.027407832443714142,\n", + " 0.019625529646873474,\n", + " -0.01576833240687847,\n", + " 0.022803643718361855,\n", + " -0.006648233160376549,\n", + " 0.004740006756037474,\n", + " -0.011232050135731697,\n", + " 0.0006748397718183696,\n", + " 0.019082263112068176,\n", + " -0.008081100881099701,\n", + " -0.03949553146958351,\n", + " -0.010288123972713947,\n", + " -0.030042679980397224,\n", + " -0.01910942606627941,\n", + " -0.00011809696297859773,\n", + " 0.013377956114709377,\n", + " -0.01904151774942875,\n", + " -0.004417441785335541,\n", + " 0.025642214342951775,\n", + " 0.007429179735481739,\n", + " -0.020929371938109398,\n", + " -0.018511831760406494,\n", + " 0.027258435264229774,\n", + " -0.011714200489223003,\n", + " -0.013540936633944511,\n", + " 0.004441209603101015,\n", + " -0.013350793160498142,\n", + " -0.0028131057042628527,\n", + " -0.007164336740970612,\n", + " -0.0029692950192838907,\n", + " -0.014749705791473389,\n", + " -0.009738065302371979,\n", + " 0.007761931046843529,\n", + " 0.011476520448923111,\n", + " 0.0008726230589672923,\n", + " 0.01737097091972828,\n", + " -0.0008221161551773548,\n", + " -0.022409774363040924,\n", + " 0.014247183687984943,\n", + " 0.01278036180883646,\n", + " ...]]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "encoder(docs=docs, truncate=True)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "semantic-router", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/docs/examples/function_calling.ipynb b/docs/examples/function_calling.ipynb index a0ea95400585a7a8fe942d3e0db7946a011869f5..cc439b6d2ca1b72ed4a854c64781bdebbf548517 100644 --- a/docs/examples/function_calling.ipynb +++ b/docs/examples/function_calling.ipynb @@ -89,6 +89,7 @@ ], "source": [ "from semantic_router.llms import OpenAILLM\n", + "\n", "llm = OpenAILLM()" ] }, @@ -143,7 +144,7 @@ "routes = []\n", "\n", "for function in functions:\n", - " route = Route.from_dynamic_route(llm=llm, entity=function)\n", + " route = Route.from_dynamic_route(llm=llm, entities=function)\n", " routes.append(route)" ] }, @@ -524,6 +525,7 @@ "\n", "llm = OpenAILLM()\n", "\n", + "\n", "def route_and_execute(query, functions, layer):\n", " route_choice: RouteChoice = layer(query)\n", "\n", diff --git a/docs/examples/unstructured-element-splitter.ipynb b/docs/examples/unstructured-element-splitter.ipynb index 4eeb6fe93cdb7f2867b9376ae64f519f94c3a309..4126338eb81fd3d7a2c78b0f9ea7061153f7dd5b 100644 --- a/docs/examples/unstructured-element-splitter.ipynb +++ b/docs/examples/unstructured-element-splitter.ipynb @@ -145,6 +145,7 @@ "from semantic_router.splitters import RollingWindowSplitter\n", "from typing import Dict\n", "\n", + "\n", "def create_title_chunks(\n", " grouped_elements: Dict, splitter: RollingWindowSplitter\n", ") -> list:\n",