mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-25 04:49:17 +00:00
standard-tests: tool tests (#28244)
This commit is contained in:
63
libs/standard-tests/tests/unit_tests/test_basic_tool.py
Normal file
63
libs/standard-tests/tests/unit_tests/test_basic_tool.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from typing import Type
|
||||
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from langchain_tests.integration_tests import ToolsIntegrationTests
|
||||
from langchain_tests.unit_tests import ToolsUnitTests
|
||||
|
||||
|
||||
class ParrotMultiplyTool(BaseTool): # type: ignore
|
||||
name: str = "ParrotMultiplyTool"
|
||||
description: str = (
|
||||
"Multiply two numbers like a parrot. Parrots always add "
|
||||
"eighty for their matey."
|
||||
)
|
||||
|
||||
def _run(self, a: int, b: int) -> int:
|
||||
return a * b + 80
|
||||
|
||||
|
||||
class TestParrotMultiplyToolUnit(ToolsUnitTests):
|
||||
@property
|
||||
def tool_constructor(self) -> Type[ParrotMultiplyTool]:
|
||||
return ParrotMultiplyTool
|
||||
|
||||
@property
|
||||
def tool_constructor_params(self) -> dict:
|
||||
# if your tool constructor instead required initialization arguments like
|
||||
# `def __init__(self, some_arg: int):`, you would return those here
|
||||
# as a dictionary, e.g.: `return {'some_arg': 42}`
|
||||
return {}
|
||||
|
||||
@property
|
||||
def tool_invoke_params_example(self) -> dict:
|
||||
"""
|
||||
Returns a dictionary representing the "args" of an example tool call.
|
||||
|
||||
This should NOT be a ToolCall dict - i.e. it should not
|
||||
have {"name", "id", "args"} keys.
|
||||
"""
|
||||
return {"a": 2, "b": 3}
|
||||
|
||||
|
||||
class TestParrotMultiplyToolIntegration(ToolsIntegrationTests):
|
||||
@property
|
||||
def tool_constructor(self) -> Type[ParrotMultiplyTool]:
|
||||
return ParrotMultiplyTool
|
||||
|
||||
@property
|
||||
def tool_constructor_params(self) -> dict:
|
||||
# if your tool constructor instead required initialization arguments like
|
||||
# `def __init__(self, some_arg: int):`, you would return those here
|
||||
# as a dictionary, e.g.: `return {'some_arg': 42}`
|
||||
return {}
|
||||
|
||||
@property
|
||||
def tool_invoke_params_example(self) -> dict:
|
||||
"""
|
||||
Returns a dictionary representing the "args" of an example tool call.
|
||||
|
||||
This should NOT be a ToolCall dict - i.e. it should not
|
||||
have {"name", "id", "args"} keys.
|
||||
"""
|
||||
return {"a": 2, "b": 3}
|
Reference in New Issue
Block a user