Hi,
I am working on chat bot project in my organization and i am stuck in one issue from couple of days. Below is the requirement of my project.
- user should ask the question from frontend and get the answer back
- chat history need to be captured and shown in UI
- for latest question and answer pair, we need to show the feedback button (thumbs up and down) and need to capture the feedback in the backend.
- if there is no feedback given by user, the feedback should be captured as N/A
i managed to code till first 2 points but i am stuck in last 2 points. Since i can share the organization code i have given the example code below. from that code when i click on feedback button, the screen goes blank.
import streamlit as st
from streamlit_feedback import streamlit_feedback
def display_answer():
for i in st.session_state.chat_history:
with st.chat_message("human"):
st.write(i["question"])
with st.chat_message("ai"):
st.write(i["answer"])
def create_answer(question):
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
message_id = len(st.session_state.chat_history)
st.session_state.chat_history.append(
{
"question": question,
"answer": f"{question}_Answer",
"message_id": message_id,
}
)
if question := st.chat_input(placeholder="Ask your question here .... !!!!"):
create_answer(question)
display_answer()
if feedback := streamlit_feedback(feedback_type="thumbs", align="flex-start"):
print(feedback)