2023-12-11 21:53:30 +00:00
|
|
|
"""[DEPRECATED] Zapier Toolkit."""
|
2024-06-22 14:37:52 +00:00
|
|
|
|
2023-12-11 21:53:30 +00:00
|
|
|
from typing import List
|
|
|
|
|
|
|
|
from langchain_core._api import warn_deprecated
|
2024-04-26 21:45:51 +00:00
|
|
|
from langchain_core.tools import BaseToolkit
|
2023-12-11 21:53:30 +00:00
|
|
|
|
|
|
|
from langchain_community.tools import BaseTool
|
|
|
|
from langchain_community.tools.zapier.tool import ZapierNLARunAction
|
|
|
|
from langchain_community.utilities.zapier import ZapierNLAWrapper
|
|
|
|
|
|
|
|
|
|
|
|
class ZapierToolkit(BaseToolkit):
|
2024-06-22 14:37:52 +00:00
|
|
|
"""Zapier Toolkit.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
tools: List[BaseTool]. The tools in the toolkit. Default is an empty list.
|
|
|
|
"""
|
2023-12-11 21:53:30 +00:00
|
|
|
|
|
|
|
tools: List[BaseTool] = []
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_zapier_nla_wrapper(
|
|
|
|
cls, zapier_nla_wrapper: ZapierNLAWrapper
|
|
|
|
) -> "ZapierToolkit":
|
2024-06-22 14:37:52 +00:00
|
|
|
"""Create a toolkit from a ZapierNLAWrapper.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
zapier_nla_wrapper: ZapierNLAWrapper. The Zapier NLA wrapper.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
ZapierToolkit. The Zapier toolkit.
|
|
|
|
"""
|
2023-12-11 21:53:30 +00:00
|
|
|
actions = zapier_nla_wrapper.list()
|
|
|
|
tools = [
|
|
|
|
ZapierNLARunAction(
|
|
|
|
action_id=action["id"],
|
|
|
|
zapier_description=action["description"],
|
|
|
|
params_schema=action["params"],
|
|
|
|
api_wrapper=zapier_nla_wrapper,
|
|
|
|
)
|
|
|
|
for action in actions
|
|
|
|
]
|
2024-05-13 18:55:07 +00:00
|
|
|
return cls(tools=tools) # type: ignore[arg-type]
|
2023-12-11 21:53:30 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
async def async_from_zapier_nla_wrapper(
|
|
|
|
cls, zapier_nla_wrapper: ZapierNLAWrapper
|
|
|
|
) -> "ZapierToolkit":
|
2024-06-22 14:37:52 +00:00
|
|
|
"""Async create a toolkit from a ZapierNLAWrapper.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
zapier_nla_wrapper: ZapierNLAWrapper. The Zapier NLA wrapper.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
ZapierToolkit. The Zapier toolkit.
|
|
|
|
"""
|
2023-12-11 21:53:30 +00:00
|
|
|
actions = await zapier_nla_wrapper.alist()
|
|
|
|
tools = [
|
|
|
|
ZapierNLARunAction(
|
|
|
|
action_id=action["id"],
|
|
|
|
zapier_description=action["description"],
|
|
|
|
params_schema=action["params"],
|
|
|
|
api_wrapper=zapier_nla_wrapper,
|
|
|
|
)
|
|
|
|
for action in actions
|
|
|
|
]
|
2024-05-13 18:55:07 +00:00
|
|
|
return cls(tools=tools) # type: ignore[arg-type]
|
2023-12-11 21:53:30 +00:00
|
|
|
|
|
|
|
def get_tools(self) -> List[BaseTool]:
|
|
|
|
"""Get the tools in the toolkit."""
|
|
|
|
warn_deprecated(
|
|
|
|
since="0.0.319",
|
|
|
|
message=(
|
|
|
|
"This tool will be deprecated on 2023-11-17. See "
|
2024-06-18 18:49:58 +00:00
|
|
|
"<https://nla.zapier.com/sunset/> for details"
|
2023-12-11 21:53:30 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
return self.tools
|