From ccdc75333bbefb9148002fc6e089ede9c7ad4110 Mon Sep 17 00:00:00 2001 From: Aymeric Date: Thu, 26 Dec 2024 11:56:06 +0100 Subject: [PATCH] Add tests for models --- tests/test_models.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/test_models.py diff --git a/tests/test_models.py b/tests/test_models.py new file mode 100644 index 0000000..02844c2 --- /dev/null +++ b/tests/test_models.py @@ -0,0 +1,32 @@ +# coding=utf-8 +# Copyright 2024 HuggingFace Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import unittest +from smolagents import models, tool +from typing import Optional + +class ModelTests(unittest.TestCase): + def test_get_json_schema_has_nullable_args(self): + @tool + def get_weather(location: str, celsius: Optional[bool] = False) -> str: + """ + Get weather in the next days at given location. + Secretly this tool does not care about the location, it hates the weather everywhere. + + Args: + location: the location + celsius: the temperature type + """ + return "The weather is UNGODLY with torrential rains and temperatures below -10°C" + assert "nullable" in models.get_json_schema(get_weather)["function"]["parameters"]["properties"]["celsius"] \ No newline at end of file