1- #
2- # Streamlit App to demo OCI AI GenAI
3- # this is the main code, with the UI
4- #
51import streamlit as st
2+ import time
3+ import traceback
4+ import sys
65
7- # this function initialise the rag chain, creating retriever, llm and chain
86from init_rag_streamlit_exp import initialize_rag_chain , get_answer
97
10- #
11- # Configs
12- #
8+ from streamlit_feedback import streamlit_feedback
139
10+ def process_feedback (feedback_value ):
11+ st .write ("Feedback value:" , feedback_value )
12+ with open ("feedback.txt" , "a" , encoding = "utf-8" ) as f :
13+ f .write (f"{ feedback_value } \n " )
1414
1515def reset_conversation ():
1616 st .session_state .messages = []
17+ st .session_state .feedback_rendered = False
18+ st .session_state .feedback_key = 0
1719
18-
19- #
20- # Main
21- #
22- st .title ("Oracle Database AI Bot powered by RAG" )
20+ st .title ("Developing an AI bot powered by RAG and Oracle Database" )
2321
2422# Added reset button
2523st .button ("Clear Chat History" , on_click = reset_conversation )
@@ -43,18 +41,33 @@ def reset_conversation():
4341 # Add user message to chat history
4442 st .session_state .messages .append ({"role" : "user" , "content" : question })
4543
46- # here we call OCI genai...
47-
4844 try :
49- print ("..." )
5045 response = get_answer (rag_chain , question )
5146
52- # Display assistant response in chat message container
5347 with st .chat_message ("assistant" ):
5448 st .markdown (response )
5549
56- # Add assistant response to chat history
50+ with st .container ():
51+ st .markdown ("How was my response?" )
52+
53+ if not st .session_state .feedback_rendered :
54+ def _submit_feedback (feedback_value , * args , ** kwargs ):
55+ print ("Feedback submitted:" , feedback_value , file = sys .stderr ) # Redirect to stderr
56+ process_feedback (feedback_value )
57+ st .session_state .feedback_rendered = False
58+
59+ feedback_component = streamlit_feedback (
60+ feedback_type = "faces" ,
61+ on_submit = _submit_feedback ,
62+ key = f"feedback_{ st .session_state .feedback_key } " ,
63+ optional_text_label = "Please provide some more information" ,
64+ args = ["✅" ]
65+ )
66+ st .session_state .feedback_key += 1
67+ st .session_state .feedback_rendered = True
68+
5769 st .session_state .messages .append ({"role" : "assistant" , "content" : response })
5870
5971 except Exception as e :
60- st .error ("An error occurred: " + str (e ))
72+ st .error (f"An error occurred: { e } " )
73+ traceback .print_exc ()
0 commit comments