mirror of
https://github.com/hwchase17/langchain.git
synced 2025-10-14 21:40:51 +00:00
Signed-off-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Dan O'Donovan <dan.odonovan@gmail.com> Co-authored-by: Tom Daniel Grande <tomdgrande@gmail.com> Co-authored-by: Grande <Tom.Daniel.Grande@statsbygg.no> Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: ccurme <chester.curme@gmail.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com> Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com> Co-authored-by: ZhangShenao <15201440436@163.com> Co-authored-by: Friso H. Kingma <fhkingma@gmail.com> Co-authored-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Nuno Campos <nuno@langchain.dev> Co-authored-by: Morgante Pell <morgantep@google.com>
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
from typing import List, Type
|
|
|
|
from langchain_core.tools import BaseTool, StructuredTool
|
|
from langchain_core.utils.pydantic import get_fields
|
|
|
|
import langchain_community.tools
|
|
from langchain_community.tools import _DEPRECATED_TOOLS
|
|
from langchain_community.tools import __all__ as tools_all
|
|
|
|
_EXCLUDE = {
|
|
BaseTool,
|
|
StructuredTool,
|
|
}
|
|
|
|
|
|
def _get_tool_classes(skip_tools_without_default_names: bool) -> List[Type[BaseTool]]:
|
|
results = []
|
|
for tool_class_name in tools_all:
|
|
if tool_class_name in _DEPRECATED_TOOLS:
|
|
continue
|
|
# Resolve the str to the class
|
|
tool_class = getattr(langchain_community.tools, tool_class_name)
|
|
if isinstance(tool_class, type) and issubclass(tool_class, BaseTool):
|
|
if tool_class in _EXCLUDE:
|
|
continue
|
|
default_name = get_fields(tool_class)["name"].default
|
|
if skip_tools_without_default_names and default_name in [ # type: ignore
|
|
None,
|
|
"",
|
|
]:
|
|
continue
|
|
if not isinstance(default_name, str):
|
|
continue
|
|
|
|
results.append(tool_class)
|
|
return results
|
|
|
|
|
|
def test_tool_names_unique() -> None:
|
|
"""Test that the default names for our core tools are unique."""
|
|
tool_classes = _get_tool_classes(skip_tools_without_default_names=True)
|
|
names = sorted([tool_cls.model_fields["name"].default for tool_cls in tool_classes])
|
|
duplicated_names = [name for name in names if names.count(name) > 1]
|
|
assert not duplicated_names
|