From 0bb4f975d961cda1387e8a255d42a8bdaca8e5ae Mon Sep 17 00:00:00 2001 From: Siraj R Aizlewood <siraj@aurelio.ai> Date: Mon, 29 Apr 2024 13:51:06 +0400 Subject: [PATCH] Corrected and elabborated on Notebook 02 introduction. It was previously (incorrectly) stating that the dynamic route generates functions. --- docs/02-dynamic-routes.ipynb | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/02-dynamic-routes.ipynb b/docs/02-dynamic-routes.ipynb index b80cc81f..947b0200 100644 --- a/docs/02-dynamic-routes.ipynb +++ b/docs/02-dynamic-routes.ipynb @@ -26,7 +26,35 @@ "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 can generate additional values, so it may decide a query is talking about maths, but it can also generate Python code that we can later execute to answer the user's query, this output may look like `\"math\", \"import math; output = math.sqrt(64)`.\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)!***" ] -- GitLab