Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ollama/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
Expand Down
14 changes: 14 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down