Skip to content

Commit

Permalink
add tests for optional tool args
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Dec 23, 2024
1 parent ccd6a9d commit 2552383
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/tools/test_tool_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ async def execute(extracted: list[Word]):
return execute


@tool
def sound_check():
async def execute(sound: str, extra: str = "stuff"):
"""
Accepts the extracted nouns and adjectives from a sentence
Args:
sound: The sound to check
extra: Optional extra stuff
Returns:
The sound that was passed to check.
"""
return f"{sound} ({extra})"

return execute


def check_point(model: str, tool: Tool, function_name: str) -> None:
task = Task(
dataset=MemoryDataset(
Expand Down Expand Up @@ -173,11 +192,31 @@ def check_list_of_objects(model: str) -> None:
verify_tool_call(log, "quick:")


def check_optional_args(model: str) -> None:
task = Task(
dataset=MemoryDataset(
[
Sample(
input="Please call the sound_check tool with single argument 'boo' and report its output."
)
]
),
solver=[
use_tools([sound_check()], tool_choice=ToolFunction("sound_check")),
generate(),
],
)

log = eval(task, model=model)[0]
verify_tool_call(log, "stuff")


def check_tool_types(model: str):
check_typed_dict(model)
check_dataclass(model)
check_list_of_numbers(model)
check_list_of_objects(model)
check_optional_args(model)


@skip_if_no_openai
Expand Down

0 comments on commit 2552383

Please sign in to comment.