refactor: update tools output type to Tool (#2766)

* refactor: update tools output type to Tool

* refactor: Update BingSearchAPI to return Tool type
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-07-17 16:32:52 -03:00 committed by GitHub
commit b23e17e54a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 20 additions and 20 deletions

View file

@ -1,11 +1,10 @@
from abc import abstractmethod
from typing import Union
from langflow.custom import Component
from langflow.field_typing import Tool
from langflow.io import Output
from langflow.schema import Data
from langchain_core.tools import BaseTool
class LCToolComponent(Component):
@ -32,7 +31,7 @@ class LCToolComponent(Component):
pass
@abstractmethod
def build_tool(self) -> BaseTool:
def build_tool(self) -> Tool:
"""
Build the tool.
"""

View file

@ -1,10 +1,10 @@
from typing import List
from typing import List, cast
from langchain_community.tools.bing_search import BingSearchResults
from langchain_community.utilities import BingSearchAPIWrapper
from langchain_core.tools import BaseTool
from langflow.base.langchain_utilities.model import LCToolComponent
from langflow.field_typing import Tool
from langflow.inputs import IntInput, MessageTextInput, MultilineInput, SecretStrInput
from langflow.schema import Data
@ -36,11 +36,11 @@ class BingSearchAPIComponent(LCToolComponent):
self.status = data
return data
def build_tool(self) -> BaseTool:
def build_tool(self) -> Tool:
if self.bing_search_url:
wrapper = BingSearchAPIWrapper(
bing_search_url=self.bing_search_url, bing_subscription_key=self.bing_subscription_key
)
else:
wrapper = BingSearchAPIWrapper(bing_subscription_key=self.bing_subscription_key) # type: ignore
return BingSearchResults(api_wrapper=wrapper, num_results=self.k)
return cast(Tool, BingSearchResults(api_wrapper=wrapper, num_results=self.k))

View file

@ -1,6 +1,6 @@
from typing import Union
from langchain_core.tools import BaseTool, Tool
from langchain_core.tools import Tool
from langflow.base.langchain_utilities.model import LCToolComponent
from langflow.inputs import SecretStrInput, MultilineInput, IntInput
@ -29,7 +29,7 @@ class GoogleSearchAPIComponent(LCToolComponent):
self.status = data
return data
def build_tool(self) -> BaseTool:
def build_tool(self) -> Tool:
wrapper = self._build_wrapper()
return Tool(
name="google_search",

View file

@ -2,10 +2,10 @@ from typing import Union
from langchain_community.utilities.google_serper import GoogleSerperAPIWrapper
from langchain_core.tools import BaseTool, Tool
from langflow.base.langchain_utilities.model import LCToolComponent
from langflow.inputs import SecretStrInput, MultilineInput, IntInput
from langflow.schema import Data
from langflow.field_typing import Tool
class GoogleSerperAPIComponent(LCToolComponent):
@ -30,7 +30,7 @@ class GoogleSerperAPIComponent(LCToolComponent):
self.status = data
return data
def build_tool(self) -> BaseTool:
def build_tool(self) -> Tool:
wrapper = self._build_wrapper()
return Tool(
name="google_search",

View file

@ -3,9 +3,9 @@ from typing import Union
from langchain_community.utilities.searchapi import SearchApiAPIWrapper
from langflow.base.langchain_utilities.model import LCToolComponent
from langchain_core.tools import BaseTool, Tool
from langflow.inputs import SecretStrInput, MultilineInput, DictInput, MessageTextInput
from langflow.schema import Data
from langflow.field_typing import Tool
class SearchAPIComponent(LCToolComponent):
@ -32,7 +32,7 @@ class SearchAPIComponent(LCToolComponent):
self.status = data
return data
def build_tool(self) -> BaseTool:
def build_tool(self) -> Tool:
wrapper = self._build_wrapper()
return Tool(
name="search_api",

View file

@ -1,9 +1,9 @@
from langchain_community.utilities.serpapi import SerpAPIWrapper
from langflow.base.langchain_utilities.model import LCToolComponent
from langchain_core.tools import BaseTool, Tool
from langflow.inputs import SecretStrInput, DictInput, MultilineInput
from langflow.schema import Data
from langflow.field_typing import Tool
class SerpAPIComponent(LCToolComponent):
@ -28,7 +28,7 @@ class SerpAPIComponent(LCToolComponent):
self.status = data
return data
def build_tool(self) -> BaseTool:
def build_tool(self) -> Tool:
wrapper = self._build_wrapper()
return Tool(name="search_api", description="Search for recent results.", func=wrapper.run)

View file

@ -1,8 +1,9 @@
from langchain.tools import WikipediaQueryRun
from langchain_community.utilities.wikipedia import WikipediaAPIWrapper
from langflow.base.langchain_utilities.model import LCToolComponent
from langchain.tools import WikipediaQueryRun, BaseTool
from langflow.inputs import IntInput, MessageTextInput, BoolInput, MultilineInput
from langflow.field_typing import Tool
from langflow.inputs import BoolInput, IntInput, MessageTextInput, MultilineInput
from langflow.schema import Data
@ -31,7 +32,7 @@ class WikipediaAPIComponent(LCToolComponent):
self.status = data
return data
def build_tool(self) -> BaseTool:
def build_tool(self) -> Tool:
wrapper = self._build_wrapper()
return WikipediaQueryRun(api_wrapper=wrapper)

View file

@ -1,7 +1,7 @@
from langchain_community.utilities.wolfram_alpha import WolframAlphaAPIWrapper
from langflow.base.langchain_utilities.model import LCToolComponent
from langchain.tools import BaseTool, Tool
from langflow.field_typing import Tool
from langflow.inputs import MultilineInput, SecretStrInput
from langflow.schema import Data
@ -26,7 +26,7 @@ class WolframAlphaAPIComponent(LCToolComponent):
self.status = data
return data
def build_tool(self) -> BaseTool:
def build_tool(self) -> Tool:
wrapper = self._build_wrapper()
return Tool(name="wolfram_alpha_api", description="Answers mathematical questions.", func=wrapper.run)