AWS Lambda API

这份笔记介绍了如何使用 AWS Lambda 工具组件。

AWS Lambda 是由亚马逊网络服务(Amazon Web Services,AWS)提供的无服务器计算服务,旨在使开发人员能够构建和运行应用程序和服务,而无需进行服务器的预配或管理。这种无服务器架构使您能够专注于编写和部署代码,而 AWS 会自动处理扩展、打补丁和管理运行应用程序所需的基础架构。

通过将 awslambda 包含在提供给 Agent 的工具列表中,您可以授予 Agent 调用在您的 AWS 云中运行的代码的能力,以满足您的需求。

当 Agent 使用 awslambda 工具时,它将提供一个字符串类型的参数,该参数将通过事件参数传递给 Lambda 函数。

首先,您需要安装 boto3 的 Python 包。

!pip install boto3 > /dev/null

为了让代理使用该工具,您必须提供与 Lambda 函数逻辑相匹配的名称和描述。您还必须提供函数的名称。

请注意,由于该工具实际上只是 boto3 库的一个包装器,您需要运行 aws configure 来使用该工具。有关更多详细信息,请参阅此处open in new window

from langchain import OpenAI
from langchain.agents import load_tools, AgentType

llm = OpenAI(temperature=0)

tools = load_tools(
    ["awslambda"],
    awslambda_tool_name="email-sender",
    awslambda_tool_description="sends an email with the specified content to test@testing123.com",
    function_name="testFunction1"
)

agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)

agent.run("Send an email to test@testing123.com saying hello world.")
Last Updated:
Contributors: 刘强