1
- #
2
- # Streamlit App to demo OCI AI GenAI
3
- # this is the main code, with the UI
4
- #
5
1
import streamlit as st
2
+ import time
3
+ import traceback
4
+ import sys
6
5
7
- # this function initialise the rag chain, creating retriever, llm and chain
8
6
from init_rag_streamlit_exp import initialize_rag_chain , get_answer
9
7
10
- #
11
- # Configs
12
- #
8
+ from streamlit_feedback import streamlit_feedback
13
9
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 " )
14
14
15
15
def reset_conversation ():
16
16
st .session_state .messages = []
17
+ st .session_state .feedback_rendered = False
18
+ st .session_state .feedback_key = 0
17
19
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" )
23
21
24
22
# Added reset button
25
23
st .button ("Clear Chat History" , on_click = reset_conversation )
@@ -43,18 +41,33 @@ def reset_conversation():
43
41
# Add user message to chat history
44
42
st .session_state .messages .append ({"role" : "user" , "content" : question })
45
43
46
- # here we call OCI genai...
47
-
48
44
try :
49
- print ("..." )
50
45
response = get_answer (rag_chain , question )
51
46
52
- # Display assistant response in chat message container
53
47
with st .chat_message ("assistant" ):
54
48
st .markdown (response )
55
49
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
+
57
69
st .session_state .messages .append ({"role" : "assistant" , "content" : response })
58
70
59
71
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