AWS Machine Learning Blog 2024年07月04日
Build your multilingual personal calendar assistant with Amazon Bedrock and AWS Step Functions
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍了如何使用AWS服务(如Amazon Bedrock、AWS Step Functions和Amazon Simple Email Service (Amazon SES))来构建一个全自动的多语言日历人工智能(AI)助手。该助手可以理解传入的消息,将它们翻译成首选语言,并自动设置日历提醒。

🤔 **Amazon Bedrock:** Amazon Bedrock是一个完全托管的服务,它通过API提供来自领先的AI初创公司和亚马逊的基石模型(FM)。您可以从各种FM中选择最适合您的用例的模型。使用Amazon Bedrock,您可以快速入门,使用自己的数据私密地定制FM,并使用AWS工具轻松地将它们集成和部署到您的应用程序中,而无需管理任何基础设施。

🤖 **AWS Step Functions:** AWS Step Functions是一种可视化工作流服务,可帮助开发人员构建分布式应用程序、自动化流程、协调微服务以及创建数据和机器学习(ML)管道。它允许您协调管道中的多个步骤。这些步骤可以是生成提示、解析基石模型的输出或使用Amazon SES发送电子邮件提醒的AWS Lambda函数。Step Functions可以与220多种AWS服务交互,包括与Amazon Bedrock的优化集成。Step Functions管道可以包含循环、映射作业、并行作业、条件和人工交互,这对于AI-人交互场景非常有用。

📧 **解决方案概述:** 该解决方案的工作流程从Amazon API Gateway开始,然后经过Step Functions状态机中的不同步骤。请注意原始消息如何通过管道流动以及如何变化。首先,消息被添加到提示中。然后,它被基石模型转换为结构化的JSON。最后,此结构化JSON用于执行操作。

⏳ **部署和测试:** 借助AWS Cloud Development Kit (AWS CDK),您可以通过运行Github存储库中的部署说明,使用单个命令行来部署整个堆栈。部署将输出API Gateway端点URL和API密钥。可以使用curl等工具将不同语言的消息发送到API Gateway进行测试。

🧹 **清理:** 为了避免产生未来费用,请在源代码的根路径中运行以下命令来删除资源: $ cdk destroy

Foreigners and expats living outside of their home country deal with a large number of emails in various languages daily. They often find themselves struggling with language barriers when it comes to setting up reminders for events like business gatherings and customer meetings. To solve this problem, this post shows you how to apply AWS services such as Amazon Bedrock, AWS Step Functions, and Amazon Simple Email Service (Amazon SES) to build a fully-automated multilingual calendar artificial intelligence (AI) assistant. It understands the incoming messages, translates them to the preferred language, and automatically sets up calendar reminders.

Amazon Bedrock is a fully managed service that makes foundation models (FMs) from leading AI startups and Amazon available through an API, so you can choose from a wide range of FMs to find the model that’s best suited for your use case. With Amazon Bedrock, you can get started quickly, privately customize FMs with your own data, and easily integrate and deploy them into your applications using AWS tools without having to manage any infrastructure.

AWS Step Functions is a visual workflow service that helps developers build distributed applications, automate processes, orchestrate microservices, and create data and machine learning (ML) pipelines. It lets you orchestrate multiple steps in the pipeline. The steps could be AWS Lambda functions that generate prompts, parse foundation models’ output, or send email reminders using Amazon SES. Step Functions can interact with over 220 AWS services, including optimized integrations with Amazon Bedrock. Step Functions pipelines can contain loops, map jobs, parallel jobs, conditions, and human interaction, which can be useful for AI-human interaction scenarios.

This post shows you how to quickly combine the flexibility and capability of both Amazon Bedrock FMs and Step Functions to build a generative AI application in a few steps. You can reuse the same design pattern to implement more generative AI applications with low effort. Both Amazon Bedrock and Step Functions are serverless, so you don’t need to think about managing and scaling the infrastructure.

The source code and deployment instructions are available in the Github repository.

Overview of solution

Figure 1: Solution architecture

As shown in Figure 1, the workflow starts from the Amazon API Gateway, then goes through different steps in the Step Functions state machine. Pay attention to how the original message flows through the pipeline and how it changes. First, the message is added to the prompt. Then, it is transformed into structured JSON by the foundation model. Finally, this structured JSON is used to carry out actions.

    The original message (example in Norwegian) is sent to a Step Functions state machine using API Gateway. A Lambda function generates a prompt that includes system instructions, the original message, and other needed information such as the current date and time. (Here’s the generated prompt from the example message).
      Sometimes, the original message might not specify the exact date but instead says something like “please RSVP before this Friday,” implying the date based on the current context. Therefore, the function inserts the current date into the prompt to assist the model in interpreting the correct date for this Friday.
    Invoke the Bedrock FM to run the following tasks, as outlined in the prompt, and pass the output to the next step to the parser:
      Translate and summarize the original message in English. Extract events information such as subject, location, and time from the original message. Generate an action plan list for events. For now, the instruction only asks the FM to generate action plan for sending calendar reminder emails for attending an event.
    Parse the FM output to ensure it has a valid schema. (Here’s the parsed result of the sample message.)
      Anthropic Claude on Amazon Bedrock can control the output format and generate JSON, but it might still produce the result as “this is the json {…}.” To enhance robustness, we implement an output parser to ensure adherence to the schema, thereby strengthening this pipeline.
    Iterate through the action-plan list and perform step 6 for each item. Every action item follows the same schema:
    {          "tool_name": "create-calendar-reminder",          "parameters": {            "body": "Jeff, the CEO, invites employees to ...",            "raw_body": "Kjære ansatte,\n\nVi ..",            "subject": "Winter fun and team building event",            "start_datetime": "2024-05-30T10:00:00Z",            "end_datetime": "2024-05-30T23:00:00Z",            "location": "Holmenkollbakken, Oslo"          }}
    Choose the right tool to do the job:
      If the tool_name equals create-calendar-reminder, then run sub-flow A to send out a calendar reminder email using Lambda Function. For future support of other possible jobs, you can expand the prompt to create a different action plan (assign different values to tool_name), and run the appropriate action outlined in sub-flow B.
     Done.

Prerequisites

To run this solution, you must have the following prerequisites:

Deployment and testing

Thanks to AWS Cloud Development Kit (AWS CDK), you can deploy the full stack with a single command line by following the deployment instructions from the Github repository. The deployment will output the API Gateway endpoint URL and an API key.

Use a tool such as curl to send messages in different languages to API Gateway for testing:

apigw=[THE_VALUE_OF_GenaiCalendarAgentStack.APIUrl]apikey=[THE_VALUE_OF_GenaiCalendarAgentStack.GeneratedAPIKeyValue]curl -v $apigw --header "Content-Type: application/json" --header "x-api-key:$apikey" -d @./doc/sample-inputs/norsk1.json 

Within 1–2 minutes, email invitations should be sent to the recipient from your sender email address, as shown in Figure 2.

Figure 2: Email generated by the solution

Cleaning up

To avoid incurring future charges, delete the resources by running the following command in the root path of the source code:

$ cdk destroy

Future extension of the solution

In the current implementation, the solution only sends out calendar reminder emails; the prompt only instructs the foundation model to generate action items where tool_name equals create-calendar-reminder. You can extend the solution to support more actions. For example, automatically send an email to the event originator and politely decline it if the event is in July (summer vacation for many):

    Modify the prompt instruction: If the event date is in July, create an action item and set the value of tool_name to send-decline-mail. Similar to the sub-flow A, create a new sub-flow C where tool_name matches send-decline-mail:
      Invoke the Amazon Bedrock FM to generate email content explaining that you cannot attend the event because it’s in July (summer vacation). Invoke a Lambda function to send out the decline email with the generated content.

In addition, you can experiment with different foundation models on Amazon Bedrock, such as Meta Llma 3 or Mistral AI, for better performance or lower cost. You can also explore Agents for Amazon Bedrock, which can orchestrate and run multistep tasks.

Conclusion

In this post, we explored a solution pattern for using generative AI within a workflow. With the flexibility and capabilities offered by both Amazon Bedrock FMs and AWS Step Functions, you can build a powerful generative AI assistant in a few steps. This assistant can streamline processes, enhance productivity, and handle various tasks efficiently. You can easily modify or upgrade its capacity without being burdened by the operational overhead of managed services.

You can find the solution source code in the Github repository and deploy your own multilingual calendar assistant by following the deployment instructions.

Check out the following resources to learn more:


About the Author

Feng Lu is a Senior Solutions Architect at AWS with 20 years professional experience. He is passionate about helping organizations to craft scalable, flexible, and resilient architectures that address their business challenges. Currently, his focus lies in leveraging Artificial Intelligence (AI) and Internet of Things (IoT) technologies to enhance the intelligence and efficiency of our physical environment.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Amazon Bedrock AWS Step Functions Amazon SES 多语言日历AI助手 生成式AI
相关文章