diff --git a/ollama/_utils.py b/ollama/_utils.py index 15f1cc0c..d0449dc7 100644 --- a/ollama/_utils.py +++ b/ollama/_utils.py @@ -60,7 +60,7 @@ def convert_function_to_tool(func: Callable) -> Tool: func.__name__, (pydantic.BaseModel,), { - '__annotations__': {k: v.annotation if v.annotation != inspect._empty else str for k, v in inspect.signature(func).parameters.items()}, + '__annotations__': {k: v.annotation if v.annotation != inspect._empty else str for k, v in inspect.signature(func).parameters.items() if v.kind not in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD)}, '__signature__': inspect.signature(func), '__doc__': parsed_docstring[doc_string_hash], }, diff --git a/tests/test_utils.py b/tests/test_utils.py index cb9e0d4f..295fb08c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -230,6 +230,20 @@ def no_types(a, b): assert tool['function']['parameters']['properties']['b']['type'] == 'string' +def test_function_with_varargs(): + def func_with_varargs(x: int, *args, **kwargs) -> int: + """ + A function with varargs. + Args: + x: The first number + """ + return x + + tool = convert_function_to_tool(func_with_varargs).model_dump() + assert set(tool['function']['parameters']['properties']) == {'x'} + assert tool['function']['parameters']['required'] == ['x'] + + def test_function_with_parentheses(): def func_with_parentheses(a: int, b: int) -> int: """