diff --git a/coverage.xml b/coverage.xml index 52f00b34c6122ea9b73d3f3cf386ee7b09a1c64a..9bdbfa3735a680c28c2ffcced9bfe29ca71f5977 100644 --- a/coverage.xml +++ b/coverage.xml @@ -1,5 +1,5 @@ <?xml version="1.0" ?> -<coverage version="7.3.2" timestamp="1702538160019" lines-valid="344" lines-covered="344" line-rate="1" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0"> +<coverage version="7.3.2" timestamp="1702633916069" lines-valid="344" lines-covered="344" line-rate="1" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0"> <!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.3.2 --> <!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd --> <sources> diff --git a/docs/examples/function_calling.ipynb b/docs/examples/function_calling.ipynb index e05686b383417c09237c13a1deb9867ba6ea2f73..650b5b9426fd9af7733cae3584540cb52a6d64b3 100644 --- a/docs/examples/function_calling.ipynb +++ b/docs/examples/function_calling.ipynb @@ -17,6 +17,7 @@ "import openai\n", "from semantic_router.utils.logger import logger\n", "\n", + "\n", "# Docs # https://platform.openai.com/docs/guides/function-calling\n", "def llm_openai(prompt: str, model: str = \"gpt-4\") -> str:\n", " try:\n", @@ -49,6 +50,7 @@ "# Docs https://huggingface.co/docs/transformers/main_classes/text_generation\n", "HF_API_TOKEN = os.environ[\"HF_API_TOKEN\"]\n", "\n", + "\n", "def llm_mistral(prompt: str) -> str:\n", " api_url = \"https://z5t4cuhg21uxfmc3.us-east-1.aws.endpoints.huggingface.cloud/\"\n", " headers = {\n", @@ -71,9 +73,9 @@ " if response.status_code != 200:\n", " raise Exception(\"Failed to call HuggingFace API\", response.text)\n", "\n", - " ai_message = response.json()[0]['generated_text']\n", + " ai_message = response.json()[0][\"generated_text\"]\n", " if not ai_message:\n", - " raise Exception(\"AI message is empty\", ai_message)\n", + " raise Exception(\"AI message is empty\", ai_message)\n", " logger.info(f\"AI message: {ai_message}\")\n", " return ai_message" ] @@ -94,6 +96,7 @@ "import inspect\n", "from typing import Any\n", "\n", + "\n", "def get_function_schema(function) -> dict[str, Any]:\n", " schema = {\n", " \"name\": function.__name__,\n", @@ -116,6 +119,7 @@ "\n", "from semantic_router.utils.logger import logger\n", "\n", + "\n", "def generate_route(function) -> dict:\n", " logger.info(\"Generating config...\")\n", " example_schema = {\n", @@ -249,6 +253,7 @@ "from semantic_router.layer import RouteLayer\n", "from semantic_router.utils.logger import logger\n", "\n", + "\n", "def create_router(routes: list[dict]) -> RouteLayer:\n", " logger.info(\"Creating route layer...\")\n", " encoder = CohereEncoder()\n", @@ -279,6 +284,7 @@ "source": [ "from typing import Callable\n", "\n", + "\n", "def call_function(function: Callable, parameters: dict[str, str]):\n", " try:\n", " return function(**parameters)\n", @@ -410,17 +416,9 @@ } ], "source": [ - "call(query=\"What is the time in Stockholm?\",\n", - " functions=tools,\n", - " router=router)\n", - "call(\n", - " query=\"What is the tech news in the Lithuania?\",\n", - " functions=tools,\n", - " router=router)\n", - "call(\n", - " query=\"Hi!\",\n", - " functions=tools,\n", - " router=router)\n" + "call(query=\"What is the time in Stockholm?\", functions=tools, router=router)\n", + "call(query=\"What is the tech news in the Lithuania?\", functions=tools, router=router)\n", + "call(query=\"Hi!\", functions=tools, router=router)" ] } ],