From 7a47976c1f8631bf96ed26e18d4bb31dc2318663 Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:39:01 -0700 Subject: [PATCH] example --- libs/core/tests/unit_tests/test_tools.py | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.py index 9a2c37b42ec..ce929117e9f 100644 --- a/libs/core/tests/unit_tests/test_tools.py +++ b/libs/core/tests/unit_tests/test_tools.py @@ -938,7 +938,7 @@ def test_create_schema_from_function_with_descriptions() -> None: Args: bar: int """ - raise NotImplementedError() + raise bar schema = create_schema_from_function("foo_annotated", foo_annotated) assert schema.schema() == { @@ -953,6 +953,30 @@ def test_create_schema_from_function_with_descriptions() -> None: }, "required": ["bar"], } + + +def test_annotated_tool_typing() -> None: + @tool + def foo(bar: Annotated[int, "This is bar", {"gte": 5}, "it's useful"]) -> str: + """The foo.""" + return str(bar) + + assert foo.invoke({"bar": 5}) == "5" # type: ignore + with pytest.raises(ValidationError): + foo.invoke({"bar": 4}) # type: ignore + + +async def test_annotated_async_tool_typing() -> None: + @tool + async def foo(bar: Annotated[int, "This is bar", {"gte": 5}, "it's useful"]) -> str: + """The foo.""" + return str(bar) + + assert await foo.ainvoke({"bar": 5}) == "5" # type: ignore + with pytest.raises(ValidationError): + await foo.ainvoke({"bar": 4}) # type: ignore + + def test_tool_pass_context() -> None: @tool def foo(bar: str) -> str: