-
Notifications
You must be signed in to change notification settings - Fork 2
/
streamlit.py
37 lines (30 loc) · 1.24 KB
/
streamlit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from main import ChatBot
import streamlit as st
bot = ChatBot()
st.set_page_config(page_title="Alteryx Support Chatbot")
with st.sidebar:
st.title('Alteryx Support Chatbot')
# Function for generating LLM response
def generate_response(input):
result = bot.rag_chain.invoke(input)
return result
# Store LLM generated responses
if "messages" not in st.session_state.keys():
st.session_state.messages = [{"role": "assistant", "content": "Welcome, please ask me a question!"}]
# Display chat messages
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.write(message["content"])
# User-provided prompt
if input := st.chat_input():
st.session_state.messages.append({"role": "user", "content": input})
with st.chat_message("user"):
st.write(input)
# Generate a new response if last message is not from assistant
if st.session_state.messages[-1]["role"] != "assistant":
with st.chat_message("assistant"):
with st.spinner("Getting your answer from known data.."):
response = generate_response(input)
st.write(response)
message = {"role": "assistant", "content": response}
st.session_state.messages.append(message)