Skip to content

Commit

Permalink
community: toolkits docstrings (#23286)
Browse files Browse the repository at this point in the history
Added missed docstrings. Formatted docstrings to the consistent form.

---------

Co-authored-by: ccurme <[email protected]>
  • Loading branch information
leo-gan and ccurme authored Jun 22, 2024
1 parent 0cd3f93 commit 987099c
Show file tree
Hide file tree
Showing 38 changed files with 387 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,30 @@ 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"
interface: Optional[Ain] = None

@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

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]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@


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)

class Config:
"""Pydantic config."""

# Allow extra fields. This is needed for the `client` field.
arbitrary_types_allowed = True

def get_tools(self) -> List[BaseTool]:
Expand Down
1 change: 1 addition & 0 deletions libs/community/langchain_community/agent_toolkits/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Toolkits for agents."""

from langchain_core.tools import BaseToolkit

__all__ = ["BaseToolkit"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Apache Cassandra Toolkit."""

from typing import List

from langchain_core.pydantic_v1 import Field
Expand All @@ -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]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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:
Expand All @@ -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.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""GitHub Toolkit."""

from typing import Dict, List

from langchain_core.pydantic_v1 import BaseModel, Field
Expand Down Expand Up @@ -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] = []
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""GitHub Toolkit."""

from typing import Dict, List

from langchain_core.tools import BaseToolkit
Expand Down Expand Up @@ -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] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions libs/community/langchain_community/agent_toolkits/jira/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 18 additions & 1 deletion libs/community/langchain_community/agent_toolkits/json/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Json agent."""

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List, Optional
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""MultiOn agent."""

from __future__ import annotations

from typing import List
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []

Expand Down
27 changes: 25 additions & 2 deletions libs/community/langchain_community/agent_toolkits/nla/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
)
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 987099c

Please sign in to comment.