docstrings `tools` (#7848)

Added docstrings in `tools`.

 @baskaryan
pull/7859/head
Leonid Ganeline 1 year ago committed by GitHub
parent 74b701f42b
commit f5ae8f1980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,7 +13,7 @@ from langchain.utilities.arxiv import ArxivAPIWrapper
class ArxivQueryRun(BaseTool): class ArxivQueryRun(BaseTool):
"""Tool that adds the capability to search using the Arxiv API.""" """Tool that searches the Arxiv API."""
name = "arxiv" name = "arxiv"
description = ( description = (

@ -11,7 +11,7 @@ from langchain.utilities.bing_search import BingSearchAPIWrapper
class BingSearchRun(BaseTool): class BingSearchRun(BaseTool):
"""Tool that adds the capability to query the Bing search API.""" """Tool that queries the Bing search API."""
name = "bing_search" name = "bing_search"
description = ( description = (
@ -39,7 +39,7 @@ class BingSearchRun(BaseTool):
class BingSearchResults(BaseTool): class BingSearchResults(BaseTool):
"""Tool that has capability to query the Bing Search API and get back json.""" """Tool that queries the Bing Search API and gets back json."""
name = "Bing Search Results JSON" name = "Bing Search Results JSON"
description = ( description = (

@ -11,6 +11,8 @@ from langchain.utilities.brave_search import BraveSearchWrapper
class BraveSearch(BaseTool): class BraveSearch(BaseTool):
"""Tool that queries the BraveSearch."""
name = "brave_search" name = "brave_search"
description = ( description = (
"a search engine. " "a search engine. "
@ -23,6 +25,16 @@ class BraveSearch(BaseTool):
def from_api_key( def from_api_key(
cls, api_key: str, search_kwargs: Optional[dict] = None, **kwargs: Any cls, api_key: str, search_kwargs: Optional[dict] = None, **kwargs: Any
) -> BraveSearch: ) -> BraveSearch:
"""Create a tool from an api key.
Args:
api_key: The api key to use.
search_kwargs: Any additional kwargs to pass to the search wrapper.
**kwargs: Any additional kwargs to pass to the tool.
Returns:
A tool.
"""
wrapper = BraveSearchWrapper(api_key=api_key, search_kwargs=search_kwargs or {}) wrapper = BraveSearchWrapper(api_key=api_key, search_kwargs=search_kwargs or {})
return cls(search_wrapper=wrapper, **kwargs) return cls(search_wrapper=wrapper, **kwargs)

@ -13,7 +13,7 @@ from langchain.utilities.dataforseo_api_search import DataForSeoAPIWrapper
class DataForSeoAPISearchRun(BaseTool): class DataForSeoAPISearchRun(BaseTool):
"""Tool that adds the capability to query the DataForSeo Google search API.""" """Tool that queries the DataForSeo Google search API."""
name = "dataforseo_api_search" name = "dataforseo_api_search"
description = ( description = (
@ -41,7 +41,7 @@ class DataForSeoAPISearchRun(BaseTool):
class DataForSeoAPISearchResults(BaseTool): class DataForSeoAPISearchResults(BaseTool):
"""Tool that has capability to query the DataForSeo Google Search API """Tool that queries the DataForSeo Google Search API
and get back json.""" and get back json."""
name = "DataForSeo Results JSON" name = "DataForSeo Results JSON"

@ -14,7 +14,7 @@ from langchain.utilities.duckduckgo_search import DuckDuckGoSearchAPIWrapper
class DuckDuckGoSearchRun(BaseTool): class DuckDuckGoSearchRun(BaseTool):
"""Tool that adds the capability to query the DuckDuckGo search API.""" """Tool that queries the DuckDuckGo search API."""
name = "duckduckgo_search" name = "duckduckgo_search"
description = ( description = (
@ -44,7 +44,7 @@ class DuckDuckGoSearchRun(BaseTool):
class DuckDuckGoSearchResults(BaseTool): class DuckDuckGoSearchResults(BaseTool):
"""Tool that queries the DuckDuckGo search API and get back json.""" """Tool that queries the DuckDuckGo search API and gets back json."""
name = "DuckDuckGo Results JSON" name = "DuckDuckGo Results JSON"
description = ( description = (

@ -23,6 +23,8 @@ class FileCopyInput(BaseModel):
class CopyFileTool(BaseFileToolMixin, BaseTool): class CopyFileTool(BaseFileToolMixin, BaseTool):
"""Tool that copies a file."""
name: str = "copy_file" name: str = "copy_file"
args_schema: Type[BaseModel] = FileCopyInput args_schema: Type[BaseModel] = FileCopyInput
description: str = "Create a copy of a file in a specified location" description: str = "Create a copy of a file in a specified location"

@ -22,6 +22,8 @@ class FileDeleteInput(BaseModel):
class DeleteFileTool(BaseFileToolMixin, BaseTool): class DeleteFileTool(BaseFileToolMixin, BaseTool):
"""Tool that deletes a file."""
name: str = "file_delete" name: str = "file_delete"
args_schema: Type[BaseModel] = FileDeleteInput args_schema: Type[BaseModel] = FileDeleteInput
description: str = "Delete a file" description: str = "Delete a file"

@ -30,6 +30,8 @@ class FileSearchInput(BaseModel):
class FileSearchTool(BaseFileToolMixin, BaseTool): class FileSearchTool(BaseFileToolMixin, BaseTool):
"""Tool that searches for files in a subdirectory that match a regex pattern."""
name: str = "file_search" name: str = "file_search"
args_schema: Type[BaseModel] = FileSearchInput args_schema: Type[BaseModel] = FileSearchInput
description: str = ( description: str = (

@ -22,6 +22,8 @@ class DirectoryListingInput(BaseModel):
class ListDirectoryTool(BaseFileToolMixin, BaseTool): class ListDirectoryTool(BaseFileToolMixin, BaseTool):
"""Tool that lists files and directories in a specified folder."""
name: str = "list_directory" name: str = "list_directory"
args_schema: Type[BaseModel] = DirectoryListingInput args_schema: Type[BaseModel] = DirectoryListingInput
description: str = "List files and directories in a specified folder" description: str = "List files and directories in a specified folder"

@ -23,6 +23,8 @@ class FileMoveInput(BaseModel):
class MoveFileTool(BaseFileToolMixin, BaseTool): class MoveFileTool(BaseFileToolMixin, BaseTool):
"""Tool that moves a file."""
name: str = "move_file" name: str = "move_file"
args_schema: Type[BaseModel] = FileMoveInput args_schema: Type[BaseModel] = FileMoveInput
description: str = "Move or rename a file from one location to another" description: str = "Move or rename a file from one location to another"

@ -21,6 +21,8 @@ class ReadFileInput(BaseModel):
class ReadFileTool(BaseFileToolMixin, BaseTool): class ReadFileTool(BaseFileToolMixin, BaseTool):
"""Tool that reads a file."""
name: str = "read_file" name: str = "read_file"
args_schema: Type[BaseModel] = ReadFileInput args_schema: Type[BaseModel] = ReadFileInput
description: str = "Read file from disk" description: str = "Read file from disk"

@ -25,6 +25,8 @@ class WriteFileInput(BaseModel):
class WriteFileTool(BaseFileToolMixin, BaseTool): class WriteFileTool(BaseFileToolMixin, BaseTool):
"""Tool that writes a file to disk."""
name: str = "write_file" name: str = "write_file"
args_schema: Type[BaseModel] = WriteFileInput args_schema: Type[BaseModel] = WriteFileInput
description: str = "Write file to disk" description: str = "Write file to disk"

@ -20,8 +20,18 @@ else:
class GmailBaseTool(BaseTool): class GmailBaseTool(BaseTool):
"""Base class for Gmail tools."""
api_resource: Resource = Field(default_factory=build_resource_service) api_resource: Resource = Field(default_factory=build_resource_service)
@classmethod @classmethod
def from_api_resource(cls, api_resource: Resource) -> "GmailBaseTool": def from_api_resource(cls, api_resource: Resource) -> "GmailBaseTool":
"""Create a tool from an api resource.
Args:
api_resource: The api resource to use.
Returns:
A tool.
"""
return cls(service=api_resource) return cls(service=api_resource)

@ -12,6 +12,8 @@ from langchain.tools.gmail.base import GmailBaseTool
class CreateDraftSchema(BaseModel): class CreateDraftSchema(BaseModel):
"""Input for CreateDraftTool."""
message: str = Field( message: str = Field(
..., ...,
description="The message to include in the draft.", description="The message to include in the draft.",
@ -35,6 +37,8 @@ class CreateDraftSchema(BaseModel):
class GmailCreateDraft(GmailBaseTool): class GmailCreateDraft(GmailBaseTool):
"""Tool that creates a draft email for Gmail."""
name: str = "create_gmail_draft" name: str = "create_gmail_draft"
description: str = ( description: str = (
"Use this tool to create a draft email with the provided message fields." "Use this tool to create a draft email with the provided message fields."

@ -13,6 +13,8 @@ from langchain.tools.gmail.utils import clean_email_body
class SearchArgsSchema(BaseModel): class SearchArgsSchema(BaseModel):
"""Input for GetMessageTool."""
message_id: str = Field( message_id: str = Field(
..., ...,
description="The unique ID of the email message, retrieved from a search.", description="The unique ID of the email message, retrieved from a search.",
@ -20,6 +22,8 @@ class SearchArgsSchema(BaseModel):
class GmailGetMessage(GmailBaseTool): class GmailGetMessage(GmailBaseTool):
"""Tool that gets a message by ID from Gmail."""
name: str = "get_gmail_message" name: str = "get_gmail_message"
description: str = ( description: str = (
"Use this tool to fetch an email by message ID." "Use this tool to fetch an email by message ID."

@ -10,6 +10,8 @@ from langchain.tools.gmail.base import GmailBaseTool
class GetThreadSchema(BaseModel): class GetThreadSchema(BaseModel):
"""Input for GetMessageTool."""
# From https://support.google.com/mail/answer/7190?hl=en # From https://support.google.com/mail/answer/7190?hl=en
thread_id: str = Field( thread_id: str = Field(
..., ...,
@ -18,6 +20,8 @@ class GetThreadSchema(BaseModel):
class GmailGetThread(GmailBaseTool): class GmailGetThread(GmailBaseTool):
"""Tool that gets a thread by ID from Gmail."""
name: str = "get_gmail_thread" name: str = "get_gmail_thread"
description: str = ( description: str = (
"Use this tool to search for email messages." "Use this tool to search for email messages."

@ -21,6 +21,8 @@ class Resource(str, Enum):
class SearchArgsSchema(BaseModel): class SearchArgsSchema(BaseModel):
"""Input for SearchGmailTool."""
# From https://support.google.com/mail/answer/7190?hl=en # From https://support.google.com/mail/answer/7190?hl=en
query: str = Field( query: str = Field(
..., ...,
@ -45,6 +47,8 @@ class SearchArgsSchema(BaseModel):
class GmailSearch(GmailBaseTool): class GmailSearch(GmailBaseTool):
"""Tool that searches for messages or threads in Gmail."""
name: str = "search_gmail" name: str = "search_gmail"
description: str = ( description: str = (
"Use this tool to search for email messages or threads." "Use this tool to search for email messages or threads."

@ -14,6 +14,8 @@ from langchain.tools.gmail.base import GmailBaseTool
class SendMessageSchema(BaseModel): class SendMessageSchema(BaseModel):
"""Input for SendMessageTool."""
message: str = Field( message: str = Field(
..., ...,
description="The message to send.", description="The message to send.",
@ -37,6 +39,8 @@ class SendMessageSchema(BaseModel):
class GmailSendMessage(GmailBaseTool): class GmailSendMessage(GmailBaseTool):
"""Tool that sends a message to Gmail."""
name: str = "send_gmail_message" name: str = "send_gmail_message"
description: str = ( description: str = (
"Use this tool to send email messages." " The input is the message, recipients" "Use this tool to send email messages." " The input is the message, recipients"

@ -13,11 +13,13 @@ from langchain.utilities.google_places_api import GooglePlacesAPIWrapper
class GooglePlacesSchema(BaseModel): class GooglePlacesSchema(BaseModel):
"""Input for GooglePlacesTool."""
query: str = Field(..., description="Query for google maps") query: str = Field(..., description="Query for google maps")
class GooglePlacesTool(BaseTool): class GooglePlacesTool(BaseTool):
"""Tool that adds the capability to query the Google places API.""" """Tool that queries the Google places API."""
name = "google_places" name = "google_places"
description = ( description = (

@ -11,7 +11,7 @@ from langchain.utilities.google_search import GoogleSearchAPIWrapper
class GoogleSearchRun(BaseTool): class GoogleSearchRun(BaseTool):
"""Tool that adds the capability to query the Google search API.""" """Tool that queries the Google search API."""
name = "google_search" name = "google_search"
description = ( description = (
@ -39,7 +39,7 @@ class GoogleSearchRun(BaseTool):
class GoogleSearchResults(BaseTool): class GoogleSearchResults(BaseTool):
"""Tool that has capability to query the Google Search API and get back json.""" """Tool that queries the Google Search API and gets back json."""
name = "Google Search Results JSON" name = "Google Search Results JSON"
description = ( description = (

@ -13,7 +13,7 @@ from langchain.utilities.google_serper import GoogleSerperAPIWrapper
class GoogleSerperRun(BaseTool): class GoogleSerperRun(BaseTool):
"""Tool that adds the capability to query the Serper.dev Google search API.""" """Tool that queries the Serper.dev Google search API."""
name = "google_serper" name = "google_serper"
description = ( description = (
@ -41,7 +41,7 @@ class GoogleSerperRun(BaseTool):
class GoogleSerperResults(BaseTool): class GoogleSerperResults(BaseTool):
"""Tool that has capability to query the Serper.dev Google Search API """Tool that queries the Serper.dev Google Search API
and get back json.""" and get back json."""
name = "google_serrper_results_json" name = "google_serrper_results_json"

@ -17,7 +17,7 @@ def _print_func(text: str) -> None:
class HumanInputRun(BaseTool): class HumanInputRun(BaseTool):
"""Tool that adds the capability to ask user for input.""" """Tool that asks user for input."""
name = "human" name = "human"
description = ( description = (

@ -41,6 +41,8 @@ from langchain.utilities.jira import JiraAPIWrapper
class JiraAction(BaseTool): class JiraAction(BaseTool):
"""Tool that queries the Atlassian Jira API."""
api_wrapper: JiraAPIWrapper = Field(default_factory=JiraAPIWrapper) api_wrapper: JiraAPIWrapper = Field(default_factory=JiraAPIWrapper)
mode: str mode: str
name = "" name = ""

@ -11,7 +11,7 @@ from langchain.utilities.metaphor_search import MetaphorSearchAPIWrapper
class MetaphorSearchResults(BaseTool): class MetaphorSearchResults(BaseTool):
"""Tool that has capability to query the Metaphor Search API and get back json.""" """Tool that queries the Metaphor Search API and gets back json."""
name = "metaphor_search_results_json" name = "metaphor_search_results_json"
description = ( description = (

@ -1,4 +1,4 @@
"""Base class for Gmail tools.""" """Base class for Office 365 tools."""
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
@ -13,4 +13,7 @@ if TYPE_CHECKING:
class O365BaseTool(BaseTool): class O365BaseTool(BaseTool):
"""Base class for the Office 365 tools."""
account: Account = Field(default_factory=authenticate) account: Account = Field(default_factory=authenticate)
"""The account object for the Office 365 account."""

@ -10,6 +10,8 @@ from langchain.tools.office365.base import O365BaseTool
class CreateDraftMessageSchema(BaseModel): class CreateDraftMessageSchema(BaseModel):
"""Input for SendMessageTool."""
body: str = Field( body: str = Field(
..., ...,
description="The message body to include in the draft.", description="The message body to include in the draft.",
@ -33,6 +35,8 @@ class CreateDraftMessageSchema(BaseModel):
class O365CreateDraftMessage(O365BaseTool): class O365CreateDraftMessage(O365BaseTool):
"""Tool for creating a draft email in Office 365."""
name: str = "create_email_draft" name: str = "create_email_draft"
description: str = ( description: str = (
"Use this tool to create a draft email with the provided message fields." "Use this tool to create a draft email with the provided message fields."

@ -50,6 +50,8 @@ class SendEventSchema(BaseModel):
class O365SendEvent(O365BaseTool): class O365SendEvent(O365BaseTool):
"""Tool for sending calendar events in Office 365."""
name: str = "send_event" name: str = "send_event"
description: str = ( description: str = (
"Use this tool to create and send an event with the provided event fields." "Use this tool to create and send an event with the provided event fields."

@ -10,6 +10,8 @@ from langchain.tools.office365.base import O365BaseTool
class SendMessageSchema(BaseModel): class SendMessageSchema(BaseModel):
"""Input for SendMessageTool."""
body: str = Field( body: str = Field(
..., ...,
description="The message body to be sent.", description="The message body to be sent.",
@ -33,6 +35,8 @@ class SendMessageSchema(BaseModel):
class O365SendMessage(O365BaseTool): class O365SendMessage(O365BaseTool):
"""Tool for sending an email in Office 365."""
name: str = "send_email" name: str = "send_email"
description: str = ( description: str = (
"Use this tool to send an email with the provided message fields." "Use this tool to send an email with the provided message fields."

@ -13,7 +13,7 @@ from langchain.utilities import OpenWeatherMapAPIWrapper
class OpenWeatherMapQueryRun(BaseTool): class OpenWeatherMapQueryRun(BaseTool):
"""Tool that adds the capability to query using the OpenWeatherMap API.""" """Tool that queries the OpenWeatherMap API."""
api_wrapper: OpenWeatherMapAPIWrapper = Field( api_wrapper: OpenWeatherMapAPIWrapper = Field(
default_factory=OpenWeatherMapAPIWrapper default_factory=OpenWeatherMapAPIWrapper

@ -22,6 +22,8 @@ class ClickToolInput(BaseModel):
class ClickTool(BaseBrowserTool): class ClickTool(BaseBrowserTool):
"""Tool for clicking on an element with the given CSS selector."""
name: str = "click_element" name: str = "click_element"
description: str = "Click on an element with the given CSS selector" description: str = "Click on an element with the given CSS selector"
args_schema: Type[BaseModel] = ClickToolInput args_schema: Type[BaseModel] = ClickToolInput

@ -13,6 +13,8 @@ from langchain.tools.playwright.utils import aget_current_page, get_current_page
class CurrentWebPageTool(BaseBrowserTool): class CurrentWebPageTool(BaseBrowserTool):
"""Tool for getting the URL of the current webpage."""
name: str = "current_webpage" name: str = "current_webpage"
description: str = "Returns the URL of the current page" description: str = "Returns the URL of the current page"
args_schema: Type[BaseModel] = BaseModel args_schema: Type[BaseModel] = BaseModel

@ -13,6 +13,8 @@ from langchain.tools.playwright.utils import aget_current_page, get_current_page
class ExtractTextTool(BaseBrowserTool): class ExtractTextTool(BaseBrowserTool):
"""Tool for extracting all the text on the current webpage."""
name: str = "extract_text" name: str = "extract_text"
description: str = "Extract all the text on the current webpage" description: str = "Extract all the text on the current webpage"
args_schema: Type[BaseModel] = BaseModel args_schema: Type[BaseModel] = BaseModel
@ -23,7 +25,7 @@ class ExtractTextTool(BaseBrowserTool):
try: try:
from bs4 import BeautifulSoup # noqa: F401 from bs4 import BeautifulSoup # noqa: F401
except ImportError: except ImportError:
raise ValueError( raise ImportError(
"The 'beautifulsoup4' package is required to use this tool." "The 'beautifulsoup4' package is required to use this tool."
" Please install it with 'pip install beautifulsoup4'." " Please install it with 'pip install beautifulsoup4'."
) )

@ -71,6 +71,8 @@ def _get_elements(
class GetElementsTool(BaseBrowserTool): class GetElementsTool(BaseBrowserTool):
"""Tool for getting elements in the current web page matching a CSS selector."""
name: str = "get_elements" name: str = "get_elements"
description: str = ( description: str = (
"Retrieve elements in the current web page matching the given CSS selector" "Retrieve elements in the current web page matching the given CSS selector"

@ -22,6 +22,8 @@ class NavigateToolInput(BaseModel):
class NavigateTool(BaseBrowserTool): class NavigateTool(BaseBrowserTool):
"""Tool for navigating a browser to a URL."""
name: str = "navigate_browser" name: str = "navigate_browser"
description: str = "Navigate a browser to the specified URL" description: str = "Navigate a browser to the specified URL"
args_schema: Type[BaseModel] = NavigateToolInput args_schema: Type[BaseModel] = NavigateToolInput

@ -15,6 +15,8 @@ from langchain.tools.base import BaseTool
class ApiConfig(BaseModel): class ApiConfig(BaseModel):
"""API Configuration."""
type: str type: str
url: str url: str
has_user_authentication: Optional[bool] = False has_user_authentication: Optional[bool] = False
@ -57,12 +59,14 @@ def marshal_spec(txt: str) -> dict:
class AIPluginToolSchema(BaseModel): class AIPluginToolSchema(BaseModel):
"""AIPLuginToolSchema.""" """Schema for AIPluginTool."""
tool_input: Optional[str] = "" tool_input: Optional[str] = ""
class AIPluginTool(BaseTool): class AIPluginTool(BaseTool):
"""Tool for getting the OpenAPI spec for an AI Plugin."""
plugin: AIPlugin plugin: AIPlugin
api_spec: str api_spec: str
args_schema: Type[AIPluginToolSchema] = AIPluginToolSchema args_schema: Type[AIPluginToolSchema] = AIPluginToolSchema

@ -13,7 +13,7 @@ from langchain.utilities.pupmed import PubMedAPIWrapper
class PubmedQueryRun(BaseTool): class PubmedQueryRun(BaseTool):
"""Tool that adds the capability to search using the PubMed API.""" """Tool that searches the PubMed API."""
name = "PubMed" name = "PubMed"
description = ( description = (

@ -18,7 +18,7 @@ class SceneXplainInput(BaseModel):
class SceneXplainTool(BaseTool): class SceneXplainTool(BaseTool):
"""Tool that adds the capability to explain images.""" """Tool that explains images."""
name = "image_explainer" name = "image_explainer"
description = ( description = (

@ -12,7 +12,7 @@ from langchain.utilities.searx_search import SearxSearchWrapper
class SearxSearchRun(BaseTool): class SearxSearchRun(BaseTool):
"""Tool that adds the capability to query a Searx instance.""" """Tool that queries a Searx instance."""
name = "searx_search" name = "searx_search"
description = ( description = (
@ -41,7 +41,7 @@ class SearxSearchRun(BaseTool):
class SearxSearchResults(BaseTool): class SearxSearchResults(BaseTool):
"""Tool that has the capability to query a Searx instance and get back json.""" """Tool that queries a Searx instance and gets back json."""
name = "Searx Search Results" name = "Searx Search Results"
description = ( description = (

@ -11,7 +11,7 @@ from langchain.utilities.wikipedia import WikipediaAPIWrapper
class WikipediaQueryRun(BaseTool): class WikipediaQueryRun(BaseTool):
"""Tool that adds the capability to search using the Wikipedia API.""" """Tool that searches the Wikipedia API."""
name = "Wikipedia" name = "Wikipedia"
description = ( description = (

@ -11,7 +11,7 @@ from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper
class WolframAlphaQueryRun(BaseTool): class WolframAlphaQueryRun(BaseTool):
"""Tool that adds the capability to query using the Wolfram Alpha SDK.""" """Tool that queries using the Wolfram Alpha SDK."""
name = "wolfram_alpha" name = "wolfram_alpha"
description = ( description = (

@ -19,6 +19,8 @@ from langchain.tools import BaseTool
class YouTubeSearchTool(BaseTool): class YouTubeSearchTool(BaseTool):
"""Tool that queries YouTube."""
name = "youtube_search" name = "youtube_search"
description = ( description = (
"search for youtube videos associated with a person. " "search for youtube videos associated with a person. "

Loading…
Cancel
Save