EVAL/tools/factory.py

21 lines
561 B
Python
Raw Normal View History

2023-03-18 12:26:19 +00:00
from typing import Optional
from langchain.llms.base import BaseLLM
from langchain.agents import load_tools
from langchain.agents.tools import BaseTool
from .base import BaseToolSet
class ToolsFactory:
@staticmethod
def from_toolsets(toolsets: list[BaseToolSet]) -> list[BaseTool]:
tools = []
for toolset in toolsets:
tools.extend(toolset.to_tools())
return tools
@staticmethod
def from_names(toolnames: list[str], llm: Optional[BaseLLM]) -> list[BaseTool]:
return load_tools(toolnames, llm=llm)