From 1df6da2583f07285495f8d07ca3fd320bd612780 Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Fri, 26 Apr 2024 18:29:14 -0700 Subject: [PATCH] Fix tests --- libs/core/langchain_core/tools.py | 8 ++++---- libs/core/tests/unit_tests/test_tools.py | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libs/core/langchain_core/tools.py b/libs/core/langchain_core/tools.py index eed3e084dd..7ad7da84f3 100644 --- a/libs/core/langchain_core/tools.py +++ b/libs/core/langchain_core/tools.py @@ -210,9 +210,9 @@ class ChildTool(BaseTool): You can use these to eg identify a specific instance of a tool with its use case. """ - handle_tool_error: Optional[Union[bool, str, Callable[[ToolException], str]]] = ( - False - ) + handle_tool_error: Optional[ + Union[bool, str, Callable[[ToolException], str]] + ] = False """Handle the content of the ToolException thrown.""" handle_validation_error: Optional[ @@ -838,7 +838,7 @@ class StructuredTool(BaseTool): # Description example: # search_api(query: str) - Searches the API for the query. sig = signature(source_function) - description = f"{name}{sig} - {description_.strip()}" + description_ = f"{name}{sig} - {description_.strip()}" _args_schema = args_schema if _args_schema is None and infer_schema: # schema name is appended within function diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.py index a424d6ecf6..f17e77fa01 100644 --- a/libs/core/tests/unit_tests/test_tools.py +++ b/libs/core/tests/unit_tests/test_tools.py @@ -3,6 +3,7 @@ import asyncio import json import sys +import textwrap from datetime import datetime from enum import Enum from functools import partial @@ -333,7 +334,7 @@ def test_structured_tool_from_function_docstring() -> None: prefix = "foo(bar: int, baz: str) -> str - " assert foo.__doc__ is not None - assert structured_tool.description == prefix + foo.__doc__.strip() + assert structured_tool.description == prefix + textwrap.dedent(foo.__doc__.strip()) def test_structured_tool_from_function_docstring_complex_args() -> None: @@ -366,7 +367,7 @@ def test_structured_tool_from_function_docstring_complex_args() -> None: prefix = "foo(bar: int, baz: List[str]) -> str - " assert foo.__doc__ is not None - assert structured_tool.description == prefix + foo.__doc__.strip() + assert structured_tool.description == prefix + textwrap.dedent(foo.__doc__).strip() def test_structured_tool_lambda_multi_args_schema() -> None: @@ -701,7 +702,7 @@ def test_structured_tool_from_function() -> None: prefix = "foo(bar: int, baz: str) -> str - " assert foo.__doc__ is not None - assert structured_tool.description == prefix + foo.__doc__.strip() + assert structured_tool.description == prefix + textwrap.dedent(foo.__doc__.strip()) def test_validation_error_handling_bool() -> None: