From e4caa41aa9530f5ebda24c8ea4dbdc7dda2141e9 Mon Sep 17 00:00:00 2001 From: Leonid Ganeline Date: Fri, 28 Jun 2024 05:40:52 -0700 Subject: [PATCH] community: docstrings `toolkits` (#23616) Added missed docstrings. Formatted docstrings to the consistent form. --- .../agent_toolkits/ainetwork/toolkit.py | 12 ++++++++++- .../agent_toolkits/connery/toolkit.py | 7 +++++-- .../agent_toolkits/gitlab/toolkit.py | 9 ++++++++ .../agent_toolkits/load_tools.py | 21 +++++++++++++++---- .../agents/openai_assistant/base.py | 3 +++ 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/libs/community/langchain_community/agent_toolkits/ainetwork/toolkit.py b/libs/community/langchain_community/agent_toolkits/ainetwork/toolkit.py index fa7bd7da7b..5559ded665 100644 --- a/libs/community/langchain_community/agent_toolkits/ainetwork/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/ainetwork/toolkit.py @@ -38,7 +38,17 @@ class AINetworkToolkit(BaseToolkit): @root_validator(pre=True) def set_interface(cls, values: dict) -> dict: - """Set the interface if not provided.""" + """Set the interface if not provided. + + If the interface is not provided, attempt to authenticate with the + network using the network value provided. + + Args: + values: The values to validate. + + Returns: + The validated values. + """ if not values.get("interface"): values["interface"] = authenticate(network=values.get("network", "testnet")) return values diff --git a/libs/community/langchain_community/agent_toolkits/connery/toolkit.py b/libs/community/langchain_community/agent_toolkits/connery/toolkit.py index edfc64268f..6b7493a597 100644 --- a/libs/community/langchain_community/agent_toolkits/connery/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/connery/toolkit.py @@ -27,10 +27,13 @@ class ConneryToolkit(BaseToolkit): """ Validate the attributes of the ConneryToolkit class. - Parameters: + Args: values (dict): The arguments to validate. Returns: dict: The validated arguments. + + Raises: + ValueError: If the 'tools' attribute is not set """ if not values.get("tools"): @@ -45,7 +48,7 @@ class ConneryToolkit(BaseToolkit): Parameters: connery_service (ConneryService): The Connery Service - to to get the list of Connery Actions. + to get the list of Connery Actions. Returns: ConneryToolkit: The Connery Toolkit. """ diff --git a/libs/community/langchain_community/agent_toolkits/gitlab/toolkit.py b/libs/community/langchain_community/agent_toolkits/gitlab/toolkit.py index 2ca47e6e2a..9cba9afc41 100644 --- a/libs/community/langchain_community/agent_toolkits/gitlab/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/gitlab/toolkit.py @@ -41,6 +41,15 @@ class GitLabToolkit(BaseToolkit): def from_gitlab_api_wrapper( cls, gitlab_api_wrapper: GitLabAPIWrapper ) -> "GitLabToolkit": + """Create a GitLabToolkit from a GitLabAPIWrapper. + + Args: + gitlab_api_wrapper: GitLabAPIWrapper. The GitLab API wrapper. + + Returns: + GitLabToolkit. The GitLab toolkit. + """ + operations: List[Dict] = [ { "mode": "get_issues", diff --git a/libs/community/langchain_community/agent_toolkits/load_tools.py b/libs/community/langchain_community/agent_toolkits/load_tools.py index c01d0d7a0c..cc72afd232 100644 --- a/libs/community/langchain_community/agent_toolkits/load_tools.py +++ b/libs/community/langchain_community/agent_toolkits/load_tools.py @@ -587,13 +587,17 @@ def load_huggingface_tool( Args: task_or_repo_id: Task or model repo id. - model_repo_id: Optional model repo id. - token: Optional token. + model_repo_id: Optional model repo id. Defaults to None. + token: Optional token. Defaults to None. remote: Optional remote. Defaults to False. - **kwargs: + **kwargs: Additional keyword arguments. Returns: A tool. + + Raises: + ImportError: If the required libraries are not installed. + NotImplementedError: If multimodal outputs or inputs are not supported. """ try: from transformers import load_tool @@ -649,7 +653,8 @@ def load_tools( Args: tool_names: name of tools to load. - llm: An optional language model, may be needed to initialize certain tools. + llm: An optional language model may be needed to initialize certain tools. + Defaults to None. callbacks: Optional callback manager or list of callback handlers. If not provided, default global callback manager will be used. allow_dangerous_tools: Optional flag to allow dangerous tools. @@ -661,9 +666,17 @@ def load_tools( Please note that this list may not be fully exhaustive. It is your responsibility to understand which tools you're using and the risks associated with them. + Defaults to False. + **kwargs: Additional keyword arguments. Returns: List of tools. + + Raises: + ValueError: If the tool name is unknown. + ValueError: If the tool requires an LLM to be provided. + ValueError: If the tool requires some parameters that were not provided. + ValueError: If the tool is a dangerous tool and allow_dangerous_tools is False. """ tools = [] callbacks = _handle_callbacks( diff --git a/libs/community/langchain_community/agents/openai_assistant/base.py b/libs/community/langchain_community/agents/openai_assistant/base.py index 806fef2bd8..09b6d615b9 100644 --- a/libs/community/langchain_community/agents/openai_assistant/base.py +++ b/libs/community/langchain_community/agents/openai_assistant/base.py @@ -288,6 +288,9 @@ class OpenAIAssistantV2Runnable(OpenAIAssistantRunnable): Union[List[OpenAIAssistantAction], OpenAIAssistantFinish]. Otherwise, will return OpenAI types Union[List[ThreadMessage], List[RequiredActionFunctionToolCall]]. + + Raises: + BaseException: If an error occurs during the invocation. """ config = ensure_config(config)