Amazon Q Demo for Product Executive Insights: All Via SDK
Purpose
The purpose of this blog is to introduce and explore a deep dive on an end to end creation of an Amazon Q financial chatbot application, creating data sources, syncing them with a NATIVE retriever and an index, and furthermore doing some product insights as a follow up to this blog to streamline executive reads and analysis of the business values of specific stories and use cases. We will also do some benchmarking against knowledge bases and what might be the best for our use case. Without further ado, a question you might have is, what is Amazon Q and where can it help in my use case?
What is Amazon Q?
Amazon Q is a sophisticated chat assistant tool for businesses, leveraging artificial intelligence to enhance employee productivity. It can handle a range of tasks like answering questions, finding information, composing emails, summarizing texts, creating document outlines, and brainstorming ideas. It responds in a conversational manner, making it user-friendly. Amazon Q can be integrated with various data sources like Amazon S3, SharePoint, and Salesforce, as well as with Amazon Kendra for intelligent search capabilities.
Benefits for a Product/Industry Oriented Chatbot:
- Comprehensive Assistance: Amazon Q can provide accurate and detailed responses to financial queries, making it an effective tool for a financial chatbot. It can access and analyze enterprise data to answer questions related to finance, investments, market trends, etc.
- Data-Driven Insights: By connecting to data sources like Amazon S3, Amazon Q can pull financial data for real-time analysis and reporting.
- Enhanced User Experience: The conversational nature of Amazon Q can make financial consultations more engaging and intuitive for users.
Data Analysis with Quicksight:
Amazon Q can be used in conjunction with AWS Quicksight for deeper financial data analysis. After fetching and processing data through Amazon Q, this data can be fed into Quicksight for visualization and advanced analytics, providing valuable insights for financial decision-making.
Creating via API:
The entire setup, including the creation of Amazon Q applications, configuration of data source connectors, and integration with other AWS services, can be managed programmatically using the Amazon Q API. This means you can automate the deployment and management of your financial chatbot and its data analysis capabilities, leading to:
- Efficiency: Faster setup and updates.
- Scalability: Easy to scale as your business grows.
- Flexibility: Customize and configure as per specific business needs.
NOTE: I work at AWS, but the thoughts, ideas, and implementations on these blogs are my own.
Deep Dive — End to End application creation via API + Invocations
Now, let’s focus on an end to end deployment of our chatbot to get the best experience via boto3 sdk programmatically:
Amazon Q Configuration: Create a chatbot to interact with your company data, send out quicksite reports
## Install the latest version of boto3 sdk to be able to use the Amazon Q APIs to create insights and reports
!pip install boto3
First, create the application:
import requests
import json
# AWS credentials - replace with your credentials
aws_access_key_id = ''
aws_secret_access_key = ''
import boto3
# Initialize a Boto3 client for Amazon Q
# Note: 'amazon_q' is a placeholder. Replace it with the actual client name if different.
client = boto3.client('qbusiness', region_name='us-east-1')
# Parameters for the application creation
params = {
# "attachmentsConfiguration": {"attachmentsControlMode": "string"},
# "clientToken": "string",
# "description": "string",
"displayName": "FinancialBot2039",
# "encryptionConfiguration": {"kmsKeyId": "string"},
"roleArn": "",
# "tags": [
# {"key": "string", "value": "string"}
# ]
}
# Create the application
response = client.create_application(**params)
# Print the response
print(response)
Create your Data Source for your application
We will be using and pumping in some simple PDF files from our S3 bucket here. Our goal is to be able to use this data and generate quicksite findings based on the answers returned by the chatbot
## Let's install the requests right now
!pip install requests
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/platformdirs-4.1.0.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/filelock-3.13.1.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/six-1.16.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/platformdirs-4.1.0.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/filelock-3.13.1.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/six-1.16.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/distlib-0.3.8.dist-info due to invalid metadata entry 'name'
Requirement already satisfied: requests in /opt/homebrew/lib/python3.11/site-packages (2.31.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/homebrew/lib/python3.11/site-packages (from requests) (3.3.0)
Requirement already satisfied: idna<4,>=2.5 in /opt/homebrew/lib/python3.11/site-packages (from requests) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/homebrew/lib/python3.11/site-packages (from requests) (2.0.7)
Requirement already satisfied: certifi>=2017.4.17 in /opt/homebrew/lib/python3.11/site-packages (from requests) (2023.7.22)WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/platformdirs-4.1.0.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/filelock-3.13.1.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/six-1.16.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/distlib-0.3.8.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/platformdirs-4.1.0.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/filelock-3.13.1.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/six-1.16.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/platformdirs-4.1.0.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/filelock-3.13.1.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/six-1.16.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/distlib-0.3.8.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/platformdirs-4.1.0.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/filelock-3.13.1.dist-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/six-1.16.0-py3.11.egg-info due to invalid metadata entry 'name'
WARNING: Skipping /opt/homebrew/lib/python3.11/site-packages/distlib-0.3.8.dist-info due to invalid metadata entry 'name'
Creating the retriever
import boto3
## Size of the file here is 1.1MB
# Initialize a Boto3 client for Amazon Q
# Note: 'amazon_q' is a placeholder. Replace it with the actual client name if different.
client = boto3.client('qbusiness', region_name='us-east-1')
# Parameters for the retriever creation
params = {
"applicationId": "",
# "clientToken": "",
"configuration": {
"nativeIndexConfiguration": {
"indexId": "" ## add your index id here
}
},
"displayName": "nativefinancialretriever",
"roleArn": "",
# "tags": [
# {"key": "Key1", "value": "Value1"},
# # Additional tags as needed
# ],
"type": "NATIVE_INDEX" # or "KENDRA_INDEX"
}
# Create the retriever
response = client.create_retriever(**params)
# Print the response
print(response)
Now create, a data source: In our case we will be using an S3 bucket object
Please make sure your role exists, has qbusiness.amazonaws.com
as trusted entity
import boto3
# Initialize a Boto3 client for Amazon Q
client = boto3.client('qbusiness', region_name='us-east-1')
# Define the configuration for your data source
# Note: Replace 'your_configuration_details' with actual configuration details
configuration = {
# Example configuration details
# This will vary based on your specific data source requirements
"your_configuration_key": "your_configuration_value"
}
# Parameters for the data source creation
params = {
"applicationId": "",
"indexId": "", # Replace with your actual index ID
"displayName": "financialdocs2039",
"configuration": configuration, # Add the configuration details here
# "type": "Your Data Source Type", # Uncomment and replace if necessary
# Include other required parameters
}
# Create the data source
response = client.create_data_source(**params)
# Print the response
print(response)
Sync your data source that you have created
import boto3
# Initialize a Boto3 client for Amazon Q
client = boto3.client('qbusiness', region_name='us-east-1')
# Replace these with your actual application ID, data source ID, and index ID
application_id = ''
data_source_id = ''
index_id = ''
try:
# Start the data source sync job
response = client.start_data_source_sync_job(
applicationId=application_id,
dataSourceId=data_source_id,
indexId=index_id
)
# Print the response
print(response)
except Exception as e:
# Handle any exceptions
print(f"An error occurred: {e}")
Now, let’s create a web like experience
import boto3
# Initialize the Boto3 client for Amazon Q
client = boto3.client('qbusiness', region_name='us-east-1')
# Parameters for creating the web experience
application_id = '' # Replace with your actual application ID
params = {
# "clientToken": "optional-client-token", # Replace with your client token, if needed
"samplePromptsControlMode": "ENABLED", # Or "DISABLED", as required
"subtitle": "Chat about financial stocks",
"title": "Finance assistant",
"welcomeMessage": "Hi! Ask a question about finances.",
# # Add tags if needed
# "tags": [
# {"key": "exampleKey", "value": "exampleValue"}
# # ... other tags as required
# ],
}
try:
# Create the web experience
response = client.create_web_experience(
applicationId=application_id,
**params
)
# Print the response
print(response)
except Exception as e:
# Handle any exceptions
print(f"An error occurred: {e}")
Conclusion
We can now create an application via the sdk and interact with it. Now as an extension, we can set up a trigger such that as a question about stocks is asked, we can configure an agent to display a board of analysis for further product analysis.