From 987099cfcda6f20140228926e9d39eed5ccd35b4 Mon Sep 17 00:00:00 2001 From: Leonid Ganeline Date: Sat, 22 Jun 2024 07:37:52 -0700 Subject: [PATCH] community: `toolkits` docstrings (#23286) Added missed docstrings. Formatted docstrings to the consistent form. --------- Co-authored-by: ccurme --- .../agent_toolkits/ainetwork/toolkit.py | 9 +++++++ .../agent_toolkits/amadeus/toolkit.py | 8 +++++- .../agent_toolkits/base.py | 1 + .../cassandra_database/toolkit.py | 9 ++++++- .../agent_toolkits/clickup/toolkit.py | 11 ++++++++ .../agent_toolkits/cogniswitch/toolkit.py | 18 ++++++++----- .../agent_toolkits/connery/toolkit.py | 7 ++++- .../agent_toolkits/file_management/toolkit.py | 7 +++++ .../agent_toolkits/github/toolkit.py | 12 +++++++++ .../agent_toolkits/gitlab/toolkit.py | 4 +++ .../agent_toolkits/gmail/toolkit.py | 3 +++ .../agent_toolkits/jira/toolkit.py | 12 +++++++++ .../agent_toolkits/json/base.py | 19 ++++++++++++- .../agent_toolkits/json/toolkit.py | 6 ++++- .../agent_toolkits/load_tools.py | 1 + .../agent_toolkits/multion/toolkit.py | 1 + .../agent_toolkits/nasa/toolkit.py | 6 ++++- .../agent_toolkits/nla/tool.py | 27 +++++++++++++++++-- .../agent_toolkits/nla/toolkit.py | 27 +++++++++++++++++-- .../agent_toolkits/office365/toolkit.py | 3 +++ .../agent_toolkits/openapi/base.py | 23 ++++++++++++++++ .../agent_toolkits/openapi/planner.py | 18 +++++++++++++ .../agent_toolkits/openapi/spec.py | 9 ++++++- .../agent_toolkits/openapi/toolkit.py | 4 +++ .../agent_toolkits/playwright/__init__.py | 1 + .../agent_toolkits/playwright/toolkit.py | 15 ++++++++++- .../agent_toolkits/polygon/toolkit.py | 14 +++++++++- .../agent_toolkits/powerbi/base.py | 23 +++++++++++++++- .../agent_toolkits/powerbi/chat_base.py | 20 ++++++++++++++ .../agent_toolkits/powerbi/prompt.py | 1 - .../agent_toolkits/powerbi/toolkit.py | 10 +++++++ .../agent_toolkits/slack/toolkit.py | 6 ++++- .../agent_toolkits/spark_sql/base.py | 25 ++++++++++++++++- .../agent_toolkits/spark_sql/toolkit.py | 8 +++++- .../agent_toolkits/sql/base.py | 1 + .../agent_toolkits/sql/toolkit.py | 8 +++++- .../agent_toolkits/steam/toolkit.py | 15 ++++++++++- .../agent_toolkits/zapier/toolkit.py | 25 ++++++++++++++--- 38 files changed, 387 insertions(+), 30 deletions(-) diff --git a/libs/community/langchain_community/agent_toolkits/ainetwork/toolkit.py b/libs/community/langchain_community/agent_toolkits/ainetwork/toolkit.py index b645aeeb2c79f..fa7bd7da7b1e9 100644 --- a/libs/community/langchain_community/agent_toolkits/ainetwork/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/ainetwork/toolkit.py @@ -25,6 +25,12 @@ class AINetworkToolkit(BaseToolkit): data associated with this service. See https://python.langchain.com/docs/security for more information. + + Parameters: + network: Optional. The network to connect to. Default is "testnet". + Options are "mainnet" or "testnet". + interface: Optional. The interface to use. If not provided, will + attempt to authenticate with the network. Default is None. """ network: Optional[Literal["mainnet", "testnet"]] = "testnet" @@ -32,6 +38,7 @@ class AINetworkToolkit(BaseToolkit): @root_validator(pre=True) def set_interface(cls, values: dict) -> dict: + """Set the interface if not provided.""" if not values.get("interface"): values["interface"] = authenticate(network=values.get("network", "testnet")) return values @@ -39,7 +46,9 @@ def set_interface(cls, values: dict) -> dict: class Config: """Pydantic config.""" + # Allow extra fields. This is needed for the `interface` field. validate_all = True + # Allow arbitrary types. This is needed for the `interface` field. arbitrary_types_allowed = True def get_tools(self) -> List[BaseTool]: diff --git a/libs/community/langchain_community/agent_toolkits/amadeus/toolkit.py b/libs/community/langchain_community/agent_toolkits/amadeus/toolkit.py index 78d121e4c588e..123f0f0beeff1 100644 --- a/libs/community/langchain_community/agent_toolkits/amadeus/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/amadeus/toolkit.py @@ -16,7 +16,12 @@ class AmadeusToolkit(BaseToolkit): - """Toolkit for interacting with Amadeus which offers APIs for travel.""" + """Toolkit for interacting with Amadeus which offers APIs for travel. + + Parameters: + client: Optional. The Amadeus client. Default is None. + llm: Optional. The language model to use. Default is None. + """ client: Client = Field(default_factory=authenticate) llm: Optional[BaseLanguageModel] = Field(default=None) @@ -24,6 +29,7 @@ class AmadeusToolkit(BaseToolkit): class Config: """Pydantic config.""" + # Allow extra fields. This is needed for the `client` field. arbitrary_types_allowed = True def get_tools(self) -> List[BaseTool]: diff --git a/libs/community/langchain_community/agent_toolkits/base.py b/libs/community/langchain_community/agent_toolkits/base.py index 0776de523b5c1..885eec3363d2c 100644 --- a/libs/community/langchain_community/agent_toolkits/base.py +++ b/libs/community/langchain_community/agent_toolkits/base.py @@ -1,4 +1,5 @@ """Toolkits for agents.""" + from langchain_core.tools import BaseToolkit __all__ = ["BaseToolkit"] diff --git a/libs/community/langchain_community/agent_toolkits/cassandra_database/toolkit.py b/libs/community/langchain_community/agent_toolkits/cassandra_database/toolkit.py index af5d5d6f88a4f..63599ffa59f8c 100644 --- a/libs/community/langchain_community/agent_toolkits/cassandra_database/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/cassandra_database/toolkit.py @@ -1,4 +1,5 @@ """Apache Cassandra Toolkit.""" + from typing import List from langchain_core.pydantic_v1 import Field @@ -14,13 +15,19 @@ class CassandraDatabaseToolkit(BaseToolkit): - """Toolkit for interacting with an Apache Cassandra database.""" + """Toolkit for interacting with an Apache Cassandra database. + + Parameters: + db: CassandraDatabase. The Cassandra database to interact + with. + """ db: CassandraDatabase = Field(exclude=True) class Config: """Configuration for this pydantic object.""" + # Allow arbitrary types. This is needed for the `db` field. arbitrary_types_allowed = True def get_tools(self) -> List[BaseTool]: diff --git a/libs/community/langchain_community/agent_toolkits/clickup/toolkit.py b/libs/community/langchain_community/agent_toolkits/clickup/toolkit.py index 9e0188da93ad0..25e0961ed7066 100644 --- a/libs/community/langchain_community/agent_toolkits/clickup/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/clickup/toolkit.py @@ -28,6 +28,9 @@ class ClickupToolkit(BaseToolkit): data associated with this service. See https://python.langchain.com/docs/security for more information. + + Parameters: + tools: List[BaseTool]. The tools in the toolkit. Default is an empty list. """ tools: List[BaseTool] = [] @@ -36,6 +39,14 @@ class ClickupToolkit(BaseToolkit): def from_clickup_api_wrapper( cls, clickup_api_wrapper: ClickupAPIWrapper ) -> "ClickupToolkit": + """Create a ClickupToolkit from a ClickupAPIWrapper. + + Args: + clickup_api_wrapper: ClickupAPIWrapper. The Clickup API wrapper. + + Returns: + ClickupToolkit. The Clickup toolkit. + """ operations: List[Dict] = [ { "mode": "get_task", diff --git a/libs/community/langchain_community/agent_toolkits/cogniswitch/toolkit.py b/libs/community/langchain_community/agent_toolkits/cogniswitch/toolkit.py index 8e3669ea9b2ff..19d020c9ba100 100644 --- a/libs/community/langchain_community/agent_toolkits/cogniswitch/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/cogniswitch/toolkit.py @@ -12,16 +12,20 @@ class CogniswitchToolkit(BaseToolkit): - """ - Toolkit for CogniSwitch. + """Toolkit for CogniSwitch. + + Use the toolkit to get all the tools present in the Cogniswitch and + use them to interact with your knowledge. - Use the toolkit to get all the tools present in the cogniswitch and - use them to interact with your knowledge + Parameters: + cs_token: str. The Cogniswitch token. + OAI_token: str. The OpenAI API token. + apiKey: str. The Cogniswitch OAuth token. """ - cs_token: str # cogniswitch token - OAI_token: str # OpenAI API token - apiKey: str # Cogniswitch OAuth token + cs_token: str + OAI_token: str + apiKey: str def get_tools(self) -> List[BaseTool]: """Get the tools in the toolkit.""" diff --git a/libs/community/langchain_community/agent_toolkits/connery/toolkit.py b/libs/community/langchain_community/agent_toolkits/connery/toolkit.py index 05a8a6870633f..edfc64268f0ad 100644 --- a/libs/community/langchain_community/agent_toolkits/connery/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/connery/toolkit.py @@ -9,6 +9,9 @@ class ConneryToolkit(BaseToolkit): """ Toolkit with a list of Connery Actions as tools. + + Parameters: + tools (List[BaseTool]): The list of Connery Actions. """ tools: List[BaseTool] @@ -23,6 +26,7 @@ def get_tools(self) -> List[BaseTool]: def validate_attributes(cls, values: dict) -> dict: """ Validate the attributes of the ConneryToolkit class. + Parameters: values (dict): The arguments to validate. Returns: @@ -38,9 +42,10 @@ def validate_attributes(cls, values: dict) -> dict: def create_instance(cls, connery_service: ConneryService) -> "ConneryToolkit": """ Creates a Connery Toolkit using a Connery Service. + Parameters: connery_service (ConneryService): The Connery Service - to to get the list of Connery Actions. + to to get the list of Connery Actions. Returns: ConneryToolkit: The Connery Toolkit. """ diff --git a/libs/community/langchain_community/agent_toolkits/file_management/toolkit.py b/libs/community/langchain_community/agent_toolkits/file_management/toolkit.py index 28384c00905ac..866bd59c0f568 100644 --- a/libs/community/langchain_community/agent_toolkits/file_management/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/file_management/toolkit.py @@ -49,6 +49,13 @@ class FileManagementToolkit(BaseToolkit): - Sandbox the agent by running it in a container. See https://python.langchain.com/docs/security for more information. + + Parameters: + root_dir: Optional. The root directory to perform file operations. + If not provided, file operations are performed relative to the current + working directory. + selected_tools: Optional. The tools to include in the toolkit. If not + provided, all tools are included. """ root_dir: Optional[str] = None diff --git a/libs/community/langchain_community/agent_toolkits/github/toolkit.py b/libs/community/langchain_community/agent_toolkits/github/toolkit.py index 81ee2a7eecb7c..014dc5f321a72 100644 --- a/libs/community/langchain_community/agent_toolkits/github/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/github/toolkit.py @@ -1,4 +1,5 @@ """GitHub Toolkit.""" + from typing import Dict, List from langchain_core.pydantic_v1 import BaseModel, Field @@ -162,6 +163,9 @@ class GitHubToolkit(BaseToolkit): and comments on GitHub. See [Security](https://python.langchain.com/docs/security) for more information. + + Parameters: + tools: List[BaseTool]. The tools in the toolkit. Default is an empty list. """ tools: List[BaseTool] = [] @@ -170,6 +174,14 @@ class GitHubToolkit(BaseToolkit): def from_github_api_wrapper( cls, github_api_wrapper: GitHubAPIWrapper ) -> "GitHubToolkit": + """Create a GitHubToolkit from a GitHubAPIWrapper. + + Args: + github_api_wrapper: GitHubAPIWrapper. The GitHub API wrapper. + + Returns: + GitHubToolkit. The GitHub toolkit. + """ operations: List[Dict] = [ { "mode": "get_issues", diff --git a/libs/community/langchain_community/agent_toolkits/gitlab/toolkit.py b/libs/community/langchain_community/agent_toolkits/gitlab/toolkit.py index 739ea5f70dd99..2ca47e6e2ae3f 100644 --- a/libs/community/langchain_community/agent_toolkits/gitlab/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/gitlab/toolkit.py @@ -1,4 +1,5 @@ """GitHub Toolkit.""" + from typing import Dict, List from langchain_core.tools import BaseToolkit @@ -29,6 +30,9 @@ class GitLabToolkit(BaseToolkit): and comments on GitLab. See https://python.langchain.com/docs/security for more information. + + Parameters: + tools: List[BaseTool]. The tools in the toolkit. Default is an empty list. """ tools: List[BaseTool] = [] diff --git a/libs/community/langchain_community/agent_toolkits/gmail/toolkit.py b/libs/community/langchain_community/agent_toolkits/gmail/toolkit.py index db520edd48064..6e8ef34d3cba3 100644 --- a/libs/community/langchain_community/agent_toolkits/gmail/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/gmail/toolkit.py @@ -38,6 +38,9 @@ class GmailToolkit(BaseToolkit): associated account. See https://python.langchain.com/docs/security for more information. + + Parameters: + api_resource: Optional. The Google API resource. Default is None. """ api_resource: Resource = Field(default_factory=build_resource_service) diff --git a/libs/community/langchain_community/agent_toolkits/jira/toolkit.py b/libs/community/langchain_community/agent_toolkits/jira/toolkit.py index 1ef1acfa68d30..840d1aa3e72b6 100644 --- a/libs/community/langchain_community/agent_toolkits/jira/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/jira/toolkit.py @@ -22,12 +22,24 @@ class JiraToolkit(BaseToolkit): reading underlying data. See https://python.langchain.com/docs/security for more information. + + Parameters: + tools: List[BaseTool]. The tools in the toolkit. Default is an empty list. """ tools: List[BaseTool] = [] @classmethod def from_jira_api_wrapper(cls, jira_api_wrapper: JiraAPIWrapper) -> "JiraToolkit": + """Create a JiraToolkit from a JiraAPIWrapper. + + Args: + jira_api_wrapper: JiraAPIWrapper. The Jira API wrapper. + + Returns: + JiraToolkit. The Jira toolkit. + """ + operations: List[Dict] = [ { "mode": "jql", diff --git a/libs/community/langchain_community/agent_toolkits/json/base.py b/libs/community/langchain_community/agent_toolkits/json/base.py index 06830d902282f..fc1aafd7ba34e 100644 --- a/libs/community/langchain_community/agent_toolkits/json/base.py +++ b/libs/community/langchain_community/agent_toolkits/json/base.py @@ -1,4 +1,5 @@ """Json agent.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, List, Optional @@ -25,7 +26,23 @@ def create_json_agent( agent_executor_kwargs: Optional[Dict[str, Any]] = None, **kwargs: Any, ) -> AgentExecutor: - """Construct a json agent from an LLM and tools.""" + """Construct a json agent from an LLM and tools. + + Args: + llm: The language model to use. + toolkit: The toolkit to use. + callback_manager: The callback manager to use. Default is None. + prefix: The prefix to use. Default is JSON_PREFIX. + suffix: The suffix to use. Default is JSON_SUFFIX. + format_instructions: The format instructions to use. Default is None. + input_variables: The input variables to use. Default is None. + verbose: Whether to print verbose output. Default is False. + agent_executor_kwargs: Optional additional arguments for the agent executor. + **kwargs: Additional arguments for the agent. + + Returns: + The agent executor. + """ from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent from langchain.chains.llm import LLMChain diff --git a/libs/community/langchain_community/agent_toolkits/json/toolkit.py b/libs/community/langchain_community/agent_toolkits/json/toolkit.py index 6c39a3dd9a191..19759c0758b75 100644 --- a/libs/community/langchain_community/agent_toolkits/json/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/json/toolkit.py @@ -13,7 +13,11 @@ class JsonToolkit(BaseToolkit): - """Toolkit for interacting with a JSON spec.""" + """Toolkit for interacting with a JSON spec. + + Parameters: + spec: The JSON spec. + """ spec: JsonSpec diff --git a/libs/community/langchain_community/agent_toolkits/load_tools.py b/libs/community/langchain_community/agent_toolkits/load_tools.py index 8d9ae0f84b2da..c01d0d7a0c939 100644 --- a/libs/community/langchain_community/agent_toolkits/load_tools.py +++ b/libs/community/langchain_community/agent_toolkits/load_tools.py @@ -14,6 +14,7 @@ See [Security](https://python.langchain.com/docs/security) for more information. """ + import warnings from typing import Any, Dict, List, Optional, Callable, Tuple diff --git a/libs/community/langchain_community/agent_toolkits/multion/toolkit.py b/libs/community/langchain_community/agent_toolkits/multion/toolkit.py index 3b22459a241f3..e814ab928fed8 100644 --- a/libs/community/langchain_community/agent_toolkits/multion/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/multion/toolkit.py @@ -1,4 +1,5 @@ """MultiOn agent.""" + from __future__ import annotations from typing import List diff --git a/libs/community/langchain_community/agent_toolkits/nasa/toolkit.py b/libs/community/langchain_community/agent_toolkits/nasa/toolkit.py index 5a18a22e32884..91ca9ec7882d3 100644 --- a/libs/community/langchain_community/agent_toolkits/nasa/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/nasa/toolkit.py @@ -14,7 +14,11 @@ class NasaToolkit(BaseToolkit): - """Nasa Toolkit.""" + """Nasa Toolkit. + + Parameters: + tools: List[BaseTool]. The tools in the toolkit. Default is an empty list. + """ tools: List[BaseTool] = [] diff --git a/libs/community/langchain_community/agent_toolkits/nla/tool.py b/libs/community/langchain_community/agent_toolkits/nla/tool.py index c19a738f967e9..997a83275a61b 100644 --- a/libs/community/langchain_community/agent_toolkits/nla/tool.py +++ b/libs/community/langchain_community/agent_toolkits/nla/tool.py @@ -20,7 +20,15 @@ class NLATool(Tool): def from_open_api_endpoint_chain( cls, chain: OpenAPIEndpointChain, api_title: str ) -> "NLATool": - """Convert an endpoint chain to an API endpoint tool.""" + """Convert an endpoint chain to an API endpoint tool. + + Args: + chain: The endpoint chain. + api_title: The title of the API. + + Returns: + The API endpoint tool. + """ expanded_name = ( f'{api_title.replace(" ", "_")}.{chain.api_operation.operation_id}' ) @@ -43,7 +51,22 @@ def from_llm_and_method( return_intermediate_steps: bool = False, **kwargs: Any, ) -> "NLATool": - """Instantiate the tool from the specified path and method.""" + """Instantiate the tool from the specified path and method. + + Args: + llm: The language model to use. + path: The path of the API. + method: The method of the API. + spec: The OpenAPI spec. + requests: Optional requests object. Default is None. + verbose: Whether to print verbose output. Default is False. + return_intermediate_steps: Whether to return intermediate steps. + Default is False. + **kwargs: Additional arguments. + + Returns: + The tool. + """ api_operation = APIOperation.from_openapi_spec(spec, path, method) chain = OpenAPIEndpointChain.from_api_operation( api_operation, diff --git a/libs/community/langchain_community/agent_toolkits/nla/toolkit.py b/libs/community/langchain_community/agent_toolkits/nla/toolkit.py index afedd0d537491..1155ec415a71a 100644 --- a/libs/community/langchain_community/agent_toolkits/nla/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/nla/toolkit.py @@ -69,7 +69,18 @@ def from_llm_and_spec( verbose: bool = False, **kwargs: Any, ) -> NLAToolkit: - """Instantiate the toolkit by creating tools for each operation.""" + """Instantiate the toolkit by creating tools for each operation. + + Args: + llm: The language model to use. + spec: The OpenAPI spec. + requests: Optional requests object. Default is None. + verbose: Whether to print verbose output. Default is False. + **kwargs: Additional arguments. + + Returns: + The toolkit. + """ http_operation_tools = cls._get_http_operation_tools( llm=llm, spec=spec, requests=requests, verbose=verbose, **kwargs ) @@ -84,7 +95,19 @@ def from_llm_and_url( verbose: bool = False, **kwargs: Any, ) -> NLAToolkit: - """Instantiate the toolkit from an OpenAPI Spec URL""" + """Instantiate the toolkit from an OpenAPI Spec URL. + + Args: + llm: The language model to use. + open_api_url: The URL of the OpenAPI spec. + requests: Optional requests object. Default is None. + verbose: Whether to print verbose output. Default is False. + **kwargs: Additional arguments. + + Returns: + The toolkit. + """ + spec = OpenAPISpec.from_url(open_api_url) return cls.from_llm_and_spec( llm=llm, spec=spec, requests=requests, verbose=verbose, **kwargs diff --git a/libs/community/langchain_community/agent_toolkits/office365/toolkit.py b/libs/community/langchain_community/agent_toolkits/office365/toolkit.py index d68314f796ab8..6030877b07742 100644 --- a/libs/community/langchain_community/agent_toolkits/office365/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/office365/toolkit.py @@ -33,6 +33,9 @@ class O365Toolkit(BaseToolkit): are appropriate for your use case. See https://python.langchain.com/docs/security for more information. + + Parameters: + account: Optional. The Office 365 account. Default is None. """ account: Account = Field(default_factory=authenticate) diff --git a/libs/community/langchain_community/agent_toolkits/openapi/base.py b/libs/community/langchain_community/agent_toolkits/openapi/base.py index 63a513811ea44..15ed8344b65d8 100644 --- a/libs/community/langchain_community/agent_toolkits/openapi/base.py +++ b/libs/community/langchain_community/agent_toolkits/openapi/base.py @@ -1,4 +1,5 @@ """OpenAPI spec agent.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, List, Optional @@ -45,6 +46,28 @@ def create_openapi_agent( what network access it has. See https://python.langchain.com/docs/security for more information. + + Args: + llm: The language model to use. + toolkit: The OpenAPI toolkit. + callback_manager: Optional. The callback manager. Default is None. + prefix: Optional. The prefix for the prompt. Default is OPENAPI_PREFIX. + suffix: Optional. The suffix for the prompt. Default is OPENAPI_SUFFIX. + format_instructions: Optional. The format instructions for the prompt. + Default is None. + input_variables: Optional. The input variables for the prompt. Default is None. + max_iterations: Optional. The maximum number of iterations. Default is 15. + max_execution_time: Optional. The maximum execution time. Default is None. + early_stopping_method: Optional. The early stopping method. Default is "force". + verbose: Optional. Whether to print verbose output. Default is False. + return_intermediate_steps: Optional. Whether to return intermediate steps. + Default is False. + agent_executor_kwargs: Optional. Additional keyword arguments + for the agent executor. + **kwargs: Additional arguments. + + Returns: + The agent executor. """ from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent diff --git a/libs/community/langchain_community/agent_toolkits/openapi/planner.py b/libs/community/langchain_community/agent_toolkits/openapi/planner.py index 87f25303481f3..9f801b0ca2d64 100644 --- a/libs/community/langchain_community/agent_toolkits/openapi/planner.py +++ b/libs/community/langchain_community/agent_toolkits/openapi/planner.py @@ -403,6 +403,24 @@ def create_openapi_agent( and avoid accepting inputs from untrusted sources without proper sandboxing. Please see: https://python.langchain.com/docs/security for further security information. + + Args: + api_spec: The OpenAPI spec. + requests_wrapper: The requests wrapper. + llm: The language model. + shared_memory: Optional. The shared memory. Default is None. + callback_manager: Optional. The callback manager. Default is None. + verbose: Optional. Whether to print verbose output. Default is True. + agent_executor_kwargs: Optional. Additional keyword arguments + for the agent executor. + allow_dangerous_requests: Optional. Whether to allow dangerous requests. + Default is False. + allowed_operations: Optional. The allowed operations. + Default is ("GET", "POST"). + **kwargs: Additional arguments. + + Returns: + The agent executor. """ from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent diff --git a/libs/community/langchain_community/agent_toolkits/openapi/spec.py b/libs/community/langchain_community/agent_toolkits/openapi/spec.py index 29b529fc71e00..befdf0215400e 100644 --- a/libs/community/langchain_community/agent_toolkits/openapi/spec.py +++ b/libs/community/langchain_community/agent_toolkits/openapi/spec.py @@ -12,7 +12,7 @@ class ReducedOpenAPISpec: This is a quick and dirty representation for OpenAPI specs. - Attributes: + Parameters: servers: The servers in the spec. description: The description of the spec. endpoints: The endpoints in the spec. @@ -30,6 +30,13 @@ def reduce_openapi_spec(spec: dict, dereference: bool = True) -> ReducedOpenAPIS I want smaller results from retrieval. I was hoping https://openapi.tools/ would have some useful bits to this end, but doesn't seem so. + + Args: + spec: The OpenAPI spec. + dereference: Whether to dereference the spec. Default is True. + + Returns: + ReducedOpenAPISpec: The reduced OpenAPI spec. """ # 1. Consider only get, post, patch, put, delete endpoints. endpoints = [ diff --git a/libs/community/langchain_community/agent_toolkits/openapi/toolkit.py b/libs/community/langchain_community/agent_toolkits/openapi/toolkit.py index c0a9ab1f7ece8..124612ae54d14 100644 --- a/libs/community/langchain_community/agent_toolkits/openapi/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/openapi/toolkit.py @@ -1,4 +1,5 @@ """Requests toolkit.""" + from __future__ import annotations from typing import Any, List @@ -40,6 +41,7 @@ class RequestsToolkit(BaseToolkit): """ requests_wrapper: TextRequestsWrapper + """The requests wrapper.""" allow_dangerous_requests: bool = False """Allow dangerous requests. See documentation for details.""" @@ -81,7 +83,9 @@ class OpenAPIToolkit(BaseToolkit): """ json_agent: Any + """The JSON agent.""" requests_wrapper: TextRequestsWrapper + """The requests wrapper.""" allow_dangerous_requests: bool = False """Allow dangerous requests. See documentation for details.""" diff --git a/libs/community/langchain_community/agent_toolkits/playwright/__init__.py b/libs/community/langchain_community/agent_toolkits/playwright/__init__.py index 7fc7f6d995095..5ab9dfcd0aae5 100644 --- a/libs/community/langchain_community/agent_toolkits/playwright/__init__.py +++ b/libs/community/langchain_community/agent_toolkits/playwright/__init__.py @@ -1,4 +1,5 @@ """Playwright browser toolkit.""" + from langchain_community.agent_toolkits.playwright.toolkit import ( PlayWrightBrowserToolkit, ) diff --git a/libs/community/langchain_community/agent_toolkits/playwright/toolkit.py b/libs/community/langchain_community/agent_toolkits/playwright/toolkit.py index beef2123c7884..40b4c411491e1 100644 --- a/libs/community/langchain_community/agent_toolkits/playwright/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/playwright/toolkit.py @@ -1,4 +1,5 @@ """Playwright web browser toolkit.""" + from __future__ import annotations from typing import TYPE_CHECKING, List, Optional, Type, cast @@ -58,6 +59,10 @@ class PlayWrightBrowserToolkit(BaseToolkit): tools. See https://python.langchain.com/docs/security for more information. + + Parameters: + sync_browser: Optional. The sync browser. Default is None. + async_browser: Optional. The async browser. Default is None. """ sync_browser: Optional["SyncBrowser"] = None @@ -103,7 +108,15 @@ def from_browser( sync_browser: Optional[SyncBrowser] = None, async_browser: Optional[AsyncBrowser] = None, ) -> PlayWrightBrowserToolkit: - """Instantiate the toolkit.""" + """Instantiate the toolkit. + + Args: + sync_browser: Optional. The sync browser. Default is None. + async_browser: Optional. The async browser. Default is None. + + Returns: + The toolkit. + """ # This is to raise a better error than the forward ref ones Pydantic would have lazy_import_playwright_browsers() return cls(sync_browser=sync_browser, async_browser=async_browser) diff --git a/libs/community/langchain_community/agent_toolkits/polygon/toolkit.py b/libs/community/langchain_community/agent_toolkits/polygon/toolkit.py index 72e87829efe86..4b23a0c8e9253 100644 --- a/libs/community/langchain_community/agent_toolkits/polygon/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/polygon/toolkit.py @@ -13,7 +13,11 @@ class PolygonToolkit(BaseToolkit): - """Polygon Toolkit.""" + """Polygon Toolkit. + + Parameters: + tools: List[BaseTool]. The tools in the toolkit. + """ tools: List[BaseTool] = [] @@ -21,6 +25,14 @@ class PolygonToolkit(BaseToolkit): def from_polygon_api_wrapper( cls, polygon_api_wrapper: PolygonAPIWrapper ) -> "PolygonToolkit": + """Create a Polygon Toolkit from a Polygon API Wrapper. + + Args: + polygon_api_wrapper: PolygonAPIWrapper. The Polygon API Wrapper. + + Returns: + PolygonToolkit. The Polygon Toolkit. + """ tools = [ PolygonAggregates( api_wrapper=polygon_api_wrapper, diff --git a/libs/community/langchain_community/agent_toolkits/powerbi/base.py b/libs/community/langchain_community/agent_toolkits/powerbi/base.py index 486e55f4e7c14..fc5500aa4a4ac 100644 --- a/libs/community/langchain_community/agent_toolkits/powerbi/base.py +++ b/libs/community/langchain_community/agent_toolkits/powerbi/base.py @@ -1,4 +1,5 @@ """Power BI agent.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, List, Optional @@ -32,7 +33,27 @@ def create_pbi_agent( agent_executor_kwargs: Optional[Dict[str, Any]] = None, **kwargs: Any, ) -> AgentExecutor: - """Construct a Power BI agent from an LLM and tools.""" + """Construct a Power BI agent from an LLM and tools. + + Args: + llm: The language model to use. + toolkit: Optional. The Power BI toolkit. Default is None. + powerbi: Optional. The Power BI dataset. Default is None. + callback_manager: Optional. The callback manager. Default is None. + prefix: Optional. The prefix for the prompt. Default is POWERBI_PREFIX. + suffix: Optional. The suffix for the prompt. Default is POWERBI_SUFFIX. + format_instructions: Optional. The format instructions for the prompt. + Default is None. + examples: Optional. The examples for the prompt. Default is None. + input_variables: Optional. The input variables for the prompt. Default is None. + top_k: Optional. The top k for the prompt. Default is 10. + verbose: Optional. Whether to print verbose output. Default is False. + agent_executor_kwargs: Optional. The agent executor kwargs. Default is None. + kwargs: Any. Additional keyword arguments. + + Returns: + The agent executor. + """ from langchain.agents import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent from langchain.chains.llm import LLMChain diff --git a/libs/community/langchain_community/agent_toolkits/powerbi/chat_base.py b/libs/community/langchain_community/agent_toolkits/powerbi/chat_base.py index acad61b442206..974ee80cd93b0 100644 --- a/libs/community/langchain_community/agent_toolkits/powerbi/chat_base.py +++ b/libs/community/langchain_community/agent_toolkits/powerbi/chat_base.py @@ -1,4 +1,5 @@ """Power BI agent.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, List, Optional @@ -38,6 +39,25 @@ def create_pbi_chat_agent( """Construct a Power BI agent from a Chat LLM and tools. If you supply only a toolkit and no Power BI dataset, the same LLM is used for both. + + Args: + llm: The language model to use. + toolkit: Optional. The Power BI toolkit. Default is None. + powerbi: Optional. The Power BI dataset. Default is None. + callback_manager: Optional. The callback manager. Default is None. + output_parser: Optional. The output parser. Default is None. + prefix: Optional. The prefix for the prompt. Default is POWERBI_CHAT_PREFIX. + suffix: Optional. The suffix for the prompt. Default is POWERBI_CHAT_SUFFIX. + examples: Optional. The examples for the prompt. Default is None. + input_variables: Optional. The input variables for the prompt. Default is None. + memory: Optional. The memory. Default is None. + top_k: Optional. The top k for the prompt. Default is 10. + verbose: Optional. Whether to print verbose output. Default is False. + agent_executor_kwargs: Optional. The agent executor kwargs. Default is None. + kwargs: Any. Additional keyword arguments. + + Returns: + The agent executor. """ from langchain.agents import AgentExecutor from langchain.agents.conversational_chat.base import ConversationalChatAgent diff --git a/libs/community/langchain_community/agent_toolkits/powerbi/prompt.py b/libs/community/langchain_community/agent_toolkits/powerbi/prompt.py index 673a6bed29bc4..b633a3c1382da 100644 --- a/libs/community/langchain_community/agent_toolkits/powerbi/prompt.py +++ b/libs/community/langchain_community/agent_toolkits/powerbi/prompt.py @@ -1,7 +1,6 @@ # flake8: noqa """Prompts for PowerBI agent.""" - POWERBI_PREFIX = """You are an agent designed to help users interact with a PowerBI Dataset. Agent has access to a tool that can write a query based on the question and then run those against PowerBI, Microsofts business intelligence tool. The questions from the users should be interpreted as related to the dataset that is available and not general questions about the world. If the question does not seem related to the dataset, return "This does not appear to be part of this dataset." as the answer. diff --git a/libs/community/langchain_community/agent_toolkits/powerbi/toolkit.py b/libs/community/langchain_community/agent_toolkits/powerbi/toolkit.py index 07f680714dea8..6422005f3a67e 100644 --- a/libs/community/langchain_community/agent_toolkits/powerbi/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/powerbi/toolkit.py @@ -1,4 +1,5 @@ """Toolkit for interacting with a Power BI dataset.""" + from __future__ import annotations from typing import TYPE_CHECKING, List, Optional, Union @@ -43,6 +44,15 @@ class PowerBIToolkit(BaseToolkit): code are appropriately scoped to the application. See https://python.langchain.com/docs/security for more information. + + Parameters: + powerbi: The Power BI dataset. + llm: The language model to use. + examples: Optional. The examples for the prompt. Default is None. + max_iterations: Optional. The maximum iterations to run. Default is 5. + callback_manager: Optional. The callback manager. Default is None. + output_token_limit: Optional. The output token limit. Default is None. + tiktoken_model_name: Optional. The TikToken model name. Default is None. """ powerbi: PowerBIDataset = Field(exclude=True) diff --git a/libs/community/langchain_community/agent_toolkits/slack/toolkit.py b/libs/community/langchain_community/agent_toolkits/slack/toolkit.py index f1babcb8aae8a..6bff03985c6e0 100644 --- a/libs/community/langchain_community/agent_toolkits/slack/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/slack/toolkit.py @@ -17,7 +17,11 @@ class SlackToolkit(BaseToolkit): - """Toolkit for interacting with Slack.""" + """Toolkit for interacting with Slack. + + Parameters: + client: The Slack client. + """ client: WebClient = Field(default_factory=login) diff --git a/libs/community/langchain_community/agent_toolkits/spark_sql/base.py b/libs/community/langchain_community/agent_toolkits/spark_sql/base.py index dca019b04252a..b02aee239072c 100644 --- a/libs/community/langchain_community/agent_toolkits/spark_sql/base.py +++ b/libs/community/langchain_community/agent_toolkits/spark_sql/base.py @@ -1,4 +1,5 @@ """Spark SQL agent.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, List, Optional @@ -30,7 +31,29 @@ def create_spark_sql_agent( agent_executor_kwargs: Optional[Dict[str, Any]] = None, **kwargs: Any, ) -> AgentExecutor: - """Construct a Spark SQL agent from an LLM and tools.""" + """Construct a Spark SQL agent from an LLM and tools. + + Args: + llm: The language model to use. + toolkit: The Spark SQL toolkit. + callback_manager: Optional. The callback manager. Default is None. + callbacks: Optional. The callbacks. Default is None. + prefix: Optional. The prefix for the prompt. Default is SQL_PREFIX. + suffix: Optional. The suffix for the prompt. Default is SQL_SUFFIX. + format_instructions: Optional. The format instructions for the prompt. + Default is None. + input_variables: Optional. The input variables for the prompt. Default is None. + top_k: Optional. The top k for the prompt. Default is 10. + max_iterations: Optional. The maximum iterations to run. Default is 15. + max_execution_time: Optional. The maximum execution time. Default is None. + early_stopping_method: Optional. The early stopping method. Default is "force". + verbose: Optional. Whether to print verbose output. Default is False. + agent_executor_kwargs: Optional. The agent executor kwargs. Default is None. + kwargs: Any. Additional keyword arguments. + + Returns: + The agent executor. + """ from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent from langchain.chains.llm import LLMChain diff --git a/libs/community/langchain_community/agent_toolkits/spark_sql/toolkit.py b/libs/community/langchain_community/agent_toolkits/spark_sql/toolkit.py index 4379fffcf4c04..8e8f87c5b4665 100644 --- a/libs/community/langchain_community/agent_toolkits/spark_sql/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/spark_sql/toolkit.py @@ -1,4 +1,5 @@ """Toolkit for interacting with Spark SQL.""" + from typing import List from langchain_core.language_models import BaseLanguageModel @@ -16,7 +17,12 @@ class SparkSQLToolkit(BaseToolkit): - """Toolkit for interacting with Spark SQL.""" + """Toolkit for interacting with Spark SQL. + + Parameters: + db: SparkSQL. The Spark SQL database. + llm: BaseLanguageModel. The language model. + """ db: SparkSQL = Field(exclude=True) llm: BaseLanguageModel = Field(exclude=True) diff --git a/libs/community/langchain_community/agent_toolkits/sql/base.py b/libs/community/langchain_community/agent_toolkits/sql/base.py index e9871e076f5c4..12a1200ee9d61 100644 --- a/libs/community/langchain_community/agent_toolkits/sql/base.py +++ b/libs/community/langchain_community/agent_toolkits/sql/base.py @@ -1,4 +1,5 @@ """SQL agent.""" + from __future__ import annotations from typing import ( diff --git a/libs/community/langchain_community/agent_toolkits/sql/toolkit.py b/libs/community/langchain_community/agent_toolkits/sql/toolkit.py index acc2c46f71c1e..e502498b68182 100644 --- a/libs/community/langchain_community/agent_toolkits/sql/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/sql/toolkit.py @@ -1,4 +1,5 @@ """Toolkit for interacting with an SQL database.""" + from typing import List from langchain_core.language_models import BaseLanguageModel @@ -16,7 +17,12 @@ class SQLDatabaseToolkit(BaseToolkit): - """Toolkit for interacting with SQL databases.""" + """Toolkit for interacting with SQL databases. + + Parameters: + db: SQLDatabase. The SQL database. + llm: BaseLanguageModel. The language model. + """ db: SQLDatabase = Field(exclude=True) llm: BaseLanguageModel = Field(exclude=True) diff --git a/libs/community/langchain_community/agent_toolkits/steam/toolkit.py b/libs/community/langchain_community/agent_toolkits/steam/toolkit.py index f6c89b5aed4f8..50e7ec4589b66 100644 --- a/libs/community/langchain_community/agent_toolkits/steam/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/steam/toolkit.py @@ -1,4 +1,5 @@ """Steam Toolkit.""" + from typing import List from langchain_core.tools import BaseToolkit @@ -13,7 +14,11 @@ class SteamToolkit(BaseToolkit): - """Steam Toolkit.""" + """Steam Toolkit. + + Parameters: + tools: List[BaseTool]. The tools in the toolkit. Default is an empty list. + """ tools: List[BaseTool] = [] @@ -21,6 +26,14 @@ class SteamToolkit(BaseToolkit): def from_steam_api_wrapper( cls, steam_api_wrapper: SteamWebAPIWrapper ) -> "SteamToolkit": + """Create a Steam Toolkit from a Steam API Wrapper. + + Args: + steam_api_wrapper: SteamWebAPIWrapper. The Steam API Wrapper. + + Returns: + SteamToolkit. The Steam Toolkit. + """ operations: List[dict] = [ { "mode": "get_games_details", diff --git a/libs/community/langchain_community/agent_toolkits/zapier/toolkit.py b/libs/community/langchain_community/agent_toolkits/zapier/toolkit.py index c5842db92d411..966793ba471c1 100644 --- a/libs/community/langchain_community/agent_toolkits/zapier/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/zapier/toolkit.py @@ -1,4 +1,5 @@ """[DEPRECATED] Zapier Toolkit.""" + from typing import List from langchain_core._api import warn_deprecated @@ -10,7 +11,11 @@ class ZapierToolkit(BaseToolkit): - """Zapier Toolkit.""" + """Zapier Toolkit. + + Parameters: + tools: List[BaseTool]. The tools in the toolkit. Default is an empty list. + """ tools: List[BaseTool] = [] @@ -18,7 +23,14 @@ class ZapierToolkit(BaseToolkit): def from_zapier_nla_wrapper( cls, zapier_nla_wrapper: ZapierNLAWrapper ) -> "ZapierToolkit": - """Create a toolkit from a ZapierNLAWrapper.""" + """Create a toolkit from a ZapierNLAWrapper. + + Args: + zapier_nla_wrapper: ZapierNLAWrapper. The Zapier NLA wrapper. + + Returns: + ZapierToolkit. The Zapier toolkit. + """ actions = zapier_nla_wrapper.list() tools = [ ZapierNLARunAction( @@ -35,7 +47,14 @@ def from_zapier_nla_wrapper( async def async_from_zapier_nla_wrapper( cls, zapier_nla_wrapper: ZapierNLAWrapper ) -> "ZapierToolkit": - """Create a toolkit from a ZapierNLAWrapper.""" + """Async create a toolkit from a ZapierNLAWrapper. + + Args: + zapier_nla_wrapper: ZapierNLAWrapper. The Zapier NLA wrapper. + + Returns: + ZapierToolkit. The Zapier toolkit. + """ actions = await zapier_nla_wrapper.alist() tools = [ ZapierNLARunAction(