Skip to content

Instantly share code, notes, and snippets.

@noahcoad
Created April 26, 2024 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahcoad/149954f49bcdafc5cb434fbaaf506d73 to your computer and use it in GitHub Desktop.
Save noahcoad/149954f49bcdafc5cb434fbaaf506d73 to your computer and use it in GitHub Desktop.
# created 2024-04-25 by Noah Coad ncoad@amazon.com
# demo video at https://youtu.be/9UkoTsXMnlQ
import streamlit as st, boto3
# setup app
amazon_q = boto3.client('qbusiness', 'us-west-2')
st.title("Amazon Q Chatbot") #page title
# get user input
input_text = st.chat_input("Chat with your bot here")
# when there's user input
if input_text:
# show user msg
with st.chat_message("user"): st.markdown(input_text)
# call out to Amazon Q
answer = amazon_q.chat_sync(applicationId='be05d006-3c25-439e-b25d-781ad5b2xxxx',
userMessage=input_text, userId = 'AmazonQ-Administrator')
# get Q response to user
chat_response = answer['systemMessage'].replace("<answer> ", "").replace("</answer> ", "")
# show Q response
with st.chat_message("assistant"): st.markdown(chat_response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment