以编程方式使用文档

Full docs here: https://docs.aws.amazon.com/lambda/index.html

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

通过在提供给 Agent 的工具列表中包含 AWSLambda,您可以让 Agent 能够调用在 AWS 云中运行的代码,以满足您的各种需求。

当 Agent 使用 AWSLambda 工具时,它将提供一个类型为的参数 string 该参数将通过以下方式传递给 Lambda 函数: event parameter.

本快速入门将演示 Agent 如何使用 Lambda 函数通过以下方式发送电子邮件 Amazon Simple Email Service。发送电子邮件的 Lambda 代码未提供,但如果您想了解如何实现,请参阅 如何使用 Lambda 和 SES 发送电子邮件。请记住,这是一个故意简化的示例;Lambda 可用于执行几乎无限数量的其他目的的代码(包括执行更多 Langchain)!

关于凭证的注意事项:

  • - 如果您尚未运行 aws configure 通过 AWS CLI,则 region, accessKeyId,以及 secretAccessKey 必须提供给 AWSLambda 构造函数。
  • - 与这些凭证对应的 IAM 角色必须具有调用 lambda 函数的权限。
npm install @langchain/openai @langchain/core
const model = new OpenAI({ temperature: 0 });
const emailSenderTool = new AWSLambda({
  name: "email-sender",
  // tell the Agent precisely what the tool does
  description:
    "Sends an email with the specified content to testing123@gmail.com",
  region: "us-east-1", // optional: AWS region in which the function is deployed
  accessKeyId: "abc123", // optional: access key id for a IAM user with invoke permissions
  secretAccessKey: "xyz456", // optional: secret access key for that IAM user
  functionName: "SendEmailViaSES", // the function name as seen in AWS Console
});
const tools = [emailSenderTool, new SerpAPI("api_key_goes_here")];
const executor = await initializeAgentExecutorWithOptions(tools, model, {
  agentType: "zero-shot-react-description",
});

const input = `Find out the capital of Croatia. Once you have it, email the answer to testing123@gmail.com.`;
const result = await executor.invoke({ input });
console.log(result);

相关