AWS Lambda
Amazon AWS Lambda是Amazon Web Services(AWS) 提供的一种无服务器计算服务。它帮助开发人员构建和运行应用程序和服务,无需预先配置或管理服务器。这种无服务器架构使您可以专注于编写和部署代码,而 AWS 会自动处理扩展、打补丁以及管理和运行您的应用程序所需的基础设施。
这个笔记本介绍了如何使用AWS Lambda工具。
通过在提供给代理的工具列表中包含AWS Lambda,您可以授予您的代理调用您AWS云中运行的代码以满足各种需求的能力。
当智能体使用工具AWS Lambda时,它将提供一个字符串类型的参数,该参数将通过event参数传递给Lambda函数。
首先,你需要安装 boto3 Python 包。
%pip install --upgrade --quiet boto3 > /dev/null
%pip install --upgrade --quiet langchain-community
要让代理使用该工具,您必须为其提供与其lambda函数逻辑相匹配的功能名称和描述。
您还必须提供函数的名称。
请注意,由于这个工具本质上只是boto3库的包装器,因此你需要运行aws configure才能使用该工具。更多信息,请参见这里
from langchain.agents import AgentType, initialize_agent, load_tools
from langchain_openai import OpenAI
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.")