Skip to content

Commit

Permalink
New test
Browse files Browse the repository at this point in the history
  • Loading branch information
acu192 committed Jan 18, 2025
1 parent c4e2fc9 commit 63673bc
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/test_tools_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,63 @@ def unknown_type(a: Callable) -> str:
assert str(e.value) == "tool `unknown_type` has parameter `a` type mismatch: tool type is `typing.Callable`, docstring type is `<class 'float'>`"


def test_get_tool_params_async_function():
async def sample_tool(
a: int,
b: str,
c: bool,
d: Color, # <-- we support enums as Enum
e: str, # <-- we support enums as str
f: float = 0.0,
) -> str:
"""
Use this for
anything you want.
:param: a: int: first param
:param: b: str: second param
:param: c: bool: third param
:param: d: enum red blue green: forth param
:param: e: enum red blue green: fifth param
:param: f: float: (optional) last param
"""
return ''
description, params = get_tool_params(sample_tool)
assert description == 'Use this for\nanything you want.'
assert params == [
{
'name': 'a',
'type': 'int',
'description': 'first param',
},
{
'name': 'b',
'type': 'str',
'description': 'second param',
},
{
'name': 'c',
'type': 'bool',
'description': 'third param',
},
{
'name': 'd',
'type': 'enum red blue green',
'description': 'forth param',
},
{
'name': 'e',
'type': 'enum red blue green',
'description': 'fifth param',
},
{
'name': 'f',
'type': 'float',
'description': '(optional) last param',
'optional': True,
},
]


def test_get_tool_params_callable_object():
class sample_tool:
def __call__(
Expand Down

0 comments on commit 63673bc

Please sign in to comment.