diff --git a/docs/05-local-execution.ipynb b/docs/05-local-execution.ipynb index 646f2176b70966f980343958f9882169dab129fd..25e4f012528a1471dd088bf1e4d79c83cef18ec1 100644 --- a/docs/05-local-execution.ipynb +++ b/docs/05-local-execution.ipynb @@ -136,6 +136,30 @@ "routes = [politics, chitchat, time]" ] }, + { + "cell_type": "code", + "execution_count": 9, + "id": "fac95b0c-c61f-4158-b7d9-0221f7d0b65e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'get_time',\n", + " 'description': 'Finds the current time in a specific timezone.\\n\\n:param timezone: The timezone to find the current time in, should\\n be a valid timezone from the IANA Time Zone Database like\\n \"America/New_York\" or \"Europe/London\". Do NOT put the place\\n name itself like \"rome\", or \"new york\", you must provide\\n the IANA format.\\n:type timezone: str\\n:return: The current time in the specified timezone.',\n", + " 'signature': '(timezone: str) -> str',\n", + " 'output': \"<class 'str'>\"}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "time_schema" + ] + }, { "cell_type": "markdown", "id": "ddd15620-92bd-4b77-99f4-c3fe68e9ab62", diff --git a/semantic_router/llms/llamacpp.py b/semantic_router/llms/llamacpp.py index 58e4dc3e096a362f304abc4a80c3ad1f2a4b5525..5554b73704ef6768c231ce4abaf6b784655595cd 100644 --- a/semantic_router/llms/llamacpp.py +++ b/semantic_router/llms/llamacpp.py @@ -1,4 +1,3 @@ -import json from pathlib import Path from typing import Any from contextlib import contextmanager diff --git a/tests/unit/llms/test_llm_base.py b/tests/unit/llms/test_llm_base.py index df78d8f54d881374a945eb32bbd692eb79a626a8..9fd97978b1be66d5181b33d49041674758da9636 100644 --- a/tests/unit/llms/test_llm_base.py +++ b/tests/unit/llms/test_llm_base.py @@ -14,3 +14,26 @@ class TestBaseLLM: def test_base_llm_call_method_not_implemented(self, base_llm): with pytest.raises(NotImplementedError): base_llm("test") + + def test_base_llm_is_valid_inputs_valid_input_pass(self, base_llm): + test_schema = { + "name": "get_time", + "description": 'Finds the current time in a specific timezone.\n\n:param timezone: The timezone to find the current time in, should\n be a valid timezone from the IANA Time Zone Database like\n "America/New_York" or "Europe/London". 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.', + "signature": "(timezone: str) -> str", + "output": "<class 'str'>", + } + test_inputs = {"timezone": "America/New_York"} + + assert base_llm._is_valid_inputs(test_inputs, test_schema) is True + + @pytest.mark.skip(reason="TODO: bug in is_valid_inputs") + def test_base_llm_is_valid_inputs_valid_input_fail(self, base_llm): + test_schema = { + "name": "get_time", + "description": 'Finds the current time in a specific timezone.\n\n:param timezone: The timezone to find the current time in, should\n be a valid timezone from the IANA Time Zone Database like\n "America/New_York" or "Europe/London". 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.', + "signature": "(timezone: str) -> str", + "output": "<class 'str'>", + } + test_inputs = {"timezone": None} + + assert base_llm._is_valid_inputs(test_inputs, test_schema) is False