Create a generative AI–powered customized Google Chat utility utilizing Amazon Bedrock
AWS affords highly effective generative AI services, together with Amazon Bedrock, which permits organizations to create tailor-made use circumstances resembling AI chat-based assistants that give solutions primarily based on data contained within the clients’ paperwork, and rather more. Many companies need to combine these cutting-edge AI capabilities with their current collaboration instruments, resembling Google Chat, to reinforce productiveness and decision-making processes.
This publish reveals how one can implement an AI-powered enterprise assistant, resembling a customized Google Chat app, utilizing the facility of Amazon Bedrock. The answer integrates giant language fashions (LLMs) along with your group’s knowledge and supplies an clever chat assistant that understands dialog context and supplies related, interactive responses instantly inside the Google Chat interface.
This answer showcases the way to bridge the hole between Google Workspace and AWS providers, providing a sensible method to enhancing worker effectivity by conversational AI. By implementing this architectural sample, organizations that use Google Workspace can empower their workforce to entry groundbreaking AI options powered by Amazon Web Services (AWS) and make knowledgeable choices with out leaving their collaboration software.
With this answer, you possibly can work together instantly with the chat assistant powered by AWS out of your Google Chat surroundings, as proven within the following instance.
Answer overview
We use the next key providers to construct this clever chat assistant:
- Amazon Bedrock is a totally managed service that provides a selection of high-performing basis fashions (FMs) from main AI corporations resembling AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon by a single API, together with a broad set of capabilities to construct generative AI purposes with safety, privateness, and accountable AI
- AWS Lambda, a serverless computing service, enables you to deal with the applying logic, processing requests, and interplay with Amazon Bedrock
- Amazon DynamoDB enables you to retailer session reminiscence knowledge to keep up context throughout conversations
- Amazon API Gateway enables you to create a safe API endpoint for the customized Google Chat app to speak with our AWS primarily based answer.
The next determine illustrates the high-level design of the answer.
The workflow consists of the next steps:
- The method begins when a person sends a message by Google Chat, both in a direct message or in a chat area the place the applying is put in.
- The customized Google Chat app, configured for HTTP integration, sends an HTTP request to an API Gateway endpoint. This request incorporates the person’s message and related metadata.
- Earlier than processing the request, a Lambda authorizer perform related to the API Gateway authenticates the incoming message. This verifies that solely respectable requests from the customized Google Chat app are processed.
- After it’s authenticated, the request is forwarded to a different Lambda perform that incorporates our core utility logic. This perform is answerable for decoding the person’s request and formulating an acceptable response.
- The Lambda perform interacts with Amazon Bedrock by its runtime APIs, utilizing both the RetrieveAndGenerate API that connects to a data base, or the Converse API to speak instantly with an LLM out there on Amazon Bedrock. This additionally permits the Lambda perform to go looking by the group’s data base and generate an clever, context-aware response utilizing the facility of LLMs. The Lambda perform additionally makes use of a DynamoDB desk to maintain observe of the dialog historical past, both instantly with a person or inside a Google Chat area.
- After receiving the generated response from Amazon Bedrock, the Lambda perform sends this reply again by API Gateway to the Google Chat app.
- Lastly, the AI-generated response seems within the person’s Google Chat interface, offering the reply to their query.
This structure permits for a seamless integration between Google Workspace and AWS providers, creating an AI-driven assistant that enhances info accessibility inside the acquainted Google Chat surroundings. You possibly can customise this structure to attach different options that you just develop in AWS to Google Chat.
Within the following sections, we clarify the way to deploy this structure.
Conditions
To implement the answer outlined on this publish, you could have the next:
- A Linux or MacOS growth surroundings with at the least 20 GB of free disk area. It may be a neighborhood machine or a cloud occasion. If you happen to use an AWS Cloud9 occasion, be sure to have increased the disk size to twenty GB.
- The AWS Command Line Interface (AWS CLI) put in in your growth surroundings. This software permits you to work together with AWS providers by command line instructions.
- An AWS account and an AWS Identity and Access Management (IAM) principal with enough permissions to create and handle the sources wanted for this utility. If you happen to don’t have an AWS account, seek advice from How do I create and activate a new Amazon Web Services account? To configure the AWS CLI with the related credentials, usually, you arrange an AWS entry key ID and secret entry key for a chosen IAM person with acceptable permissions.
- Request access to Amazon Bedrock FMs. On this publish, we use both Anthropic’s Claude Sonnet 3 or Amazon Titan Textual content G1 Premier out there in Amazon Bedrock, however you may as well select different fashions which might be supported for Amazon Bedrock knowledge bases.
- Optionally, an Amazon Bedrock data base created in your account, which lets you combine your individual paperwork into your generative AI purposes. If you happen to don’t have an current data base, seek advice from Create an Amazon Bedrock knowledge base. Alternatively, the answer proposes an choice with no data base, with solutions generated solely by the FM on the backend.
- A Enterprise or Enterprise Google Workspace account with entry to Google Chat. You additionally want a Google Cloud mission with billing enabled. To verify that an current mission has billing enabled, see Verify the billing status of your projects.
- Docker put in in your growth surroundings.
Deploy the answer
The appliance introduced on this publish is accessible within the accompanying GitHub repository and offered as an AWS Cloud Development Kit (AWS CDK) mission. Full the next steps to deploy the AWS CDK mission in your AWS account:
- Clone the GitHub repository in your native machine.
- Set up the Python bundle dependencies which might be wanted to construct and deploy the mission. This mission is ready up like a typical Python mission. We suggest that you just create a digital surroundings inside this mission, saved below the
.venv
. To manually create a digital surroundings on MacOS and Linux, use the next command:
- After the initialization course of is full and the digital surroundings is created, you should utilize the next command to activate your digital surroundings:
- Set up the Python bundle dependencies which might be wanted to construct and deploy the mission. Within the root listing, run the next command:
- Run the cdk bootstrap command to arrange an AWS surroundings for deploying the AWS CDK utility.
- Run the script
init-script.bash
:
This script prompts you for the next:
- The Amazon Bedrock data base ID to affiliate along with your Google Chat app (seek advice from the conditions part). Maintain this clean should you resolve to not use an current data base.
- Which LLM you need to use in Amazon Bedrock for textual content era. For this answer, you possibly can select between Anthropic’s Claude Sonnet 3 or Amazon Titan Text G1 – Premier
The next screenshot reveals the enter variables to the init-script.bash
script.
The script deploys the AWS CDK mission in your account. After it runs efficiently, it outputs the parameter ApiEndpoint
, whose worth designates the invoke URL for the HTTP API endpoint deployed as a part of this mission. Notice the worth of this parameter since you use it later within the Google Chat app configuration.
The next screenshot reveals the output of the init-script.bash
script.
You can too discover this parameter on the AWS CloudFormation console, on the stack’s Outputs tab.
Register a brand new app in Google Chat
To combine the AWS powered chat assistant into Google Chat, you create a customized Google Chat app. Google Chat apps are extensions that carry exterior providers and sources instantly into the Google Chat surroundings. These apps can take part in direct messages, group conversations, or devoted chat areas, permitting customers to entry info and take actions with out leaving their chat interface.
For our AI-powered enterprise assistant, we create an interactive customized Google Chat app that makes use of the HTTP integration method. This method permits our app to obtain and reply to person messages in actual time, offering a seamless conversational expertise.
After you have got deployed the AWS CDK stack within the earlier part, full the next steps to register a Google Chat app within the Google Cloud portal:
- Open the Google Cloud portal and log in along with your Google account.
- Seek for “Google Chat API” and navigate to the Google Chat API web page, which helps you to construct Google Chat apps to combine your providers with Google Chat.
- If that is your first time utilizing the Google Chat API, select ACTIVATE. In any other case, select MANAGE.
- On the Configuration tab, below Software information, present the next info, as proven within the following screenshot:
- For App title, enter an app title (for instance,
bedrock-chat
). - For Avatar URL, enter the URL on your app’s avatar picture. As a default, you possibly can present the Google chat product icon.
- For Description, enter an outline of the app (for instance,
Chat App with Amazon Bedrock
).
- For App title, enter an app title (for instance,
- Below Interactive options, activate Allow Interactive options.
- Below Performance, choose Obtain 1:1 messages and Be part of areas and group conversations, as proven within the following screenshot.
- Below Connection settings, present the next info:
- Choose App URL.
- For App URL, enter the Invoke URL related to the deployment stage of the HTTP API gateway. That is the
ApiEndpoint
parameter that you just famous on the finish of the deployment of the AWS CDK template. - For Authentication Viewers, choose App URL, as proven within the following screenshot.
- Below Visibility, choose Make this Chat app out there to particular folks and teams in <your-company-name> and supply electronic mail addresses for people and teams who can be approved to make use of your app. It is advisable add at the least your individual electronic mail if you wish to entry the app.
- Select Save.
The next animation illustrates these steps on the Google Cloud console.
By finishing these steps, the brand new Amazon Bedrock chat app ought to be accessible on the Google Chat console for the individuals or teams that you just approved in your Google Workspace.
To dispatch interplay occasions to the answer deployed on this publish, Google Chat sends requests to your API Gateway endpoint. To confirm the authenticity of those requests, Google Chat features a bearer token within the Authorization
header of each HTTPS request to your endpoint. The Lambda authorizer perform supplied with this answer verifies that the bearer token was issued by Google Chat and focused at your particular app utilizing the Google OAuth consumer library. You possibly can additional customise the Lambda authorizer perform to implement extra management guidelines primarily based on User or Space objects included within the request from Google Chat to your API Gateway endpoint. This lets you fine-tune entry management, for instance, by limiting sure options to particular customers or limiting the app’s performance specifically chat areas, enhancing safety and customization choices on your group.
Converse along with your customized Google Chat app
Now you can converse with the brand new app inside your Google Chat interface. Connect with Google Chat with an electronic mail that you just approved throughout the configuration of your app and provoke a dialog by discovering the app:
- Select New chat within the chat pane, then enter the title of the applying (
bedrock-chat
) within the search subject. - Select Chat and enter a pure language phrase to work together with the applying.
Though we beforehand demonstrated a utilization state of affairs that includes a direct chat with the Amazon Bedrock utility, you may as well invoke the applying from inside a Google chat area, as illustrated within the following demo.
Customise the answer
On this publish, we used Amazon Bedrock to energy the chat-based assistant. Nevertheless, you possibly can customise the answer to make use of quite a lot of AWS providers and create an answer that matches your particular enterprise wants.
To customise the applying, full the next steps:
- Edit the file
lambda/lambda-chat-app/lambda-chatapp-code.py
within the GitHub repository you cloned to your native machine throughout deployment. - Implement your small business logic on this file.
The code runs in a Lambda perform. Every time a request is processed, Lambda runs the lambda_handler
perform:
When Google Chat sends a request, the lambda_handler
perform calls the handle_post
perform.
- Let’s substitute the
handle_post
perform with the next code:
- Save your file, then run the next command in your terminal to deploy your new code:
The deployment ought to take a couple of minute. When it’s full, you possibly can go to Google Chat and check your new enterprise logic. The next screenshot reveals an instance chat.
Because the picture reveals, your perform will get the person message and an area title. You should use this area title as a novel ID for the dialog, which helps you to to handle historical past.
As you grow to be extra accustomed to the answer, it’s possible you’ll need to discover superior Amazon Bedrock options to considerably develop its capabilities and make it extra strong and versatile. Take into account integrating Amazon Bedrock Guardrails to implement safeguards personalized to your utility necessities and accountable AI insurance policies. Take into account additionally increasing the assistant’s capabilities by perform calling, to carry out actions on behalf of customers, resembling scheduling conferences or initiating workflows. You may additionally use Amazon Bedrock Prompt Flows to speed up the creation, testing, and deployment of workflows by an intuitive visible builder. For extra superior interactions, you can discover implementing Amazon Bedrock Agents able to reasoning about advanced issues, making choices, and executing multistep duties autonomously.
Efficiency optimization
The serverless structure used on this publish supplies a scalable answer out of the field. As your person base grows or when you have particular efficiency necessities, there are a number of methods to additional optimize efficiency. You possibly can implement API caching to hurry up repeated requests or use provisioned concurrency for Lambda features to remove chilly begins. To beat API Gateway timeout limitations in situations requiring longer processing instances, you possibly can increase the integration timeout on API Gateway, otherwise you would possibly substitute it with an Application Load Balancer, which permits for prolonged connection durations. You can too fine-tune your selection of Amazon Bedrock mannequin to steadiness accuracy and velocity. Lastly, Provisioned Throughput in Amazon Bedrock enables you to provision the next degree of throughput for a mannequin at a set price.
Clear up
On this publish, you deployed an answer that allows you to work together instantly with a chat assistant powered by AWS out of your Google Chat surroundings. The structure incurs utilization price for a number of AWS providers. First, you’ll be charged for mannequin inference and for the vector databases you utilize with Amazon Bedrock Knowledge Bases. AWS Lambda prices are primarily based on the variety of requests and compute time, and Amazon DynamoDB expenses depend upon learn/write capability models and storage used. Moreover, Amazon API Gateway incurs expenses primarily based on the variety of API calls and knowledge switch. For extra particulars about pricing, seek advice from Amazon Bedrock pricing.
There may additionally be prices related to utilizing Google providers. For detailed details about potential expenses associated to Google Chat, seek advice from the Google Chat product documentation.
To keep away from pointless prices, clear up the sources created in your AWS surroundings while you’re completed exploring this answer. Use the cdk destroy command to delete the AWS CDK stack beforehand deployed on this publish. Alternatively, open the AWS CloudFormation console and delete the stack you deployed.
Conclusion
On this publish, we demonstrated a sensible answer for creating an AI-powered enterprise assistant for Google Chat. This answer seamlessly integrates Google Workspace with AWS hosted knowledge by utilizing LLMs on Amazon Bedrock, Lambda for utility logic, DynamoDB for session administration, and API Gateway for safe communication. By implementing this answer, organizations can present their workforce with a streamlined strategy to entry AI-driven insights and data bases instantly inside their acquainted Google Chat interface, enabling pure language interplay and data-driven discussions with out the necessity to swap between completely different purposes or platforms.
Moreover, we showcased the way to customise the applying to implement tailor-made enterprise logic that may use different AWS providers. This flexibility empowers you to tailor the assistant’s capabilities to their particular necessities, offering a seamless integration along with your current AWS infrastructure and knowledge sources.
AWS affords a complete suite of cutting-edge AI providers to satisfy your group’s distinctive wants, together with Amazon Bedrock and Amazon Q. Now that you understand how to combine AWS providers with Google Chat, you possibly can discover their capabilities and construct superior purposes!
In regards to the Authors
Nizar Kheir is a Senior Options Architect at AWS with greater than 15 years of expertise spanning numerous business segments. He at the moment works with public sector clients in France and throughout EMEA to assist them modernize their IT infrastructure and foster innovation by harnessing the facility of the AWS Cloud.
Lior Perez is a Principal Options Architect on the development group primarily based in Toulouse, France. He enjoys supporting clients of their digital transformation journey, utilizing massive knowledge, machine studying, and generative AI to assist clear up their enterprise challenges. He’s additionally personally keen about robotics and Web of Issues (IoT), and he always seems for brand spanking new methods to make use of applied sciences for innovation.