Add tests for models

This commit is contained in:
Aymeric 2024-12-26 11:56:06 +01:00
parent e5ca0f0cb8
commit ccdc75333b
1 changed files with 32 additions and 0 deletions

32
tests/test_models.py Normal file
View File

@ -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"]