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 src/anthropic/lib/tools/_beta_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __init__(
self._cache_control = cache_control
self._allowed_callers = allowed_callers
self._eager_input_streaming = eager_input_streaming
self._input_examples = input_examples
self._input_examples = list(input_examples) if input_examples is not None else None
self._strict = strict

self.description = description or self._get_description_from_docstring()
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/tools/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ def get_weather(location: str, unit: str = "celsius") -> str: # noqa: ARG001
"required": ["location"],
}

def test_input_examples_materialized_from_iterable(self) -> None:
def lookup(city: str) -> str:
return city

generator_examples = ({"city": c} for c in ["Kraków", "London"])
tool = beta_tool(lookup, input_examples=generator_examples)

# First call to to_dict
first_dict = tool.to_dict()
assert first_dict["input_examples"] == [{"city": "Kraków"}, {"city": "London"}]

# Second call to to_dict must still have the examples
second_dict = tool.to_dict()
assert second_dict["input_examples"] == [{"city": "Kraków"}, {"city": "London"}]

def test_to_dict_method(self) -> None:
def simple_func(message: str) -> str:
"""A simple function."""
Expand Down