diff --git a/ollama/_utils.py b/ollama/_utils.py index 15f1cc0c..3fd3329b 100644 --- a/ollama/_utils.py +++ b/ollama/_utils.py @@ -73,9 +73,10 @@ def convert_function_to_tool(func: Callable) -> Tool: schema['required'].remove(k) types.discard('null') + sorted_types = sorted(types) schema['properties'][k] = { 'description': parsed_docstring[k], - 'type': ', '.join(types), + 'type': sorted_types if len(sorted_types) > 1 else ''.join(sorted_types), } tool = Tool( diff --git a/tests/test_utils.py b/tests/test_utils.py index cb9e0d4f..a3393759 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -98,8 +98,8 @@ def all_types( if sys.version_info >= (3, 10): assert tool['function']['parameters']['properties']['z']['type'] == 'array' assert tool['function']['parameters']['properties']['w']['type'] == 'object' - assert {x.strip().strip("'") for x in tool['function']['parameters']['properties']['v']['type'].removeprefix('[').removesuffix(']').split(',')} == {'string', 'integer'} - assert tool['function']['parameters']['properties']['v']['type'] != 'null' + assert isinstance(tool['function']['parameters']['properties']['v']['type'], list) + assert tool['function']['parameters']['properties']['v']['type'] == ['integer', 'string'] assert tool['function']['parameters']['required'] == ['x', 'y', 'z', 'w'] else: assert tool['function']['parameters']['properties']['z']['type'] == 'array'