ngcanh commited on
Commit
af9cd0d
·
verified ·
1 Parent(s): 70e41fc

Update pages/chatbot.py

Browse files
Files changed (1) hide show
  1. pages/chatbot.py +47 -47
pages/chatbot.py CHANGED
@@ -1,47 +1,47 @@
1
- # import streamlit as st
2
- # from app import rag_query, memory, process_feedback
3
-
4
- # st.title("🛡️ RAG Chatbot MB Ageas Life 🛡️")
5
-
6
- # # Initialize session history
7
- # if "messages" not in st.session_state:
8
- # st.session_state.messages = []
9
-
10
- # # Hiển thị lại tin nhắn cũ
11
- # for i, message in enumerate(st.session_state.messages):
12
- # with st.chat_message(message["role"]):
13
- # st.markdown(message["content"])
14
- # if message["role"] == "assistant":
15
- # col1, col2 = st.columns([1, 15])
16
- # with col1:
17
- # if st.button("👍", key=f"thumbs_up_{i}"):
18
- # process_feedback(st.session_state.messages[i-1]["content"], message["content"], True)
19
- # with col2:
20
- # if st.button("👎", key=f"thumbs_down_{i}"):
21
- # process_feedback(st.session_state.messages[i-1]["content"], message["content"], False)
22
-
23
- # # Nhận input người dùng
24
- # if prompt := st.chat_input("Ask me any question related to MBAL"):
25
- # # Hiển thị tin nhắn người dùng
26
- # st.chat_message("user").markdown(prompt)
27
- # st.session_state.messages.append({"role": "user", "content": prompt})
28
- # memory.chat_memory.add_user_message(prompt)
29
-
30
- # # Gọi hàm RAG để trả lời
31
- # response = rag_query(prompt)
32
-
33
- # # Hiển thị tin nhắn chatbot
34
- # with st.chat_message("assistant"):
35
- # st.markdown(response)
36
- # st.session_state.messages.append({"role": "assistant", "content": response})
37
- # memory.chat_memory.add_ai_message(response)
38
-
39
- # st.rerun()
40
-
41
- # # Sidebar
42
- # # with st.sidebar:
43
- # # st.header("Lựa chọn khác")
44
- # # if st.button("Xóa lịch sử chat"):
45
- # # st.session_state.messages = []
46
- # # memory.clear()
47
- # # st.rerun()
 
1
+ import streamlit as st
2
+ from app import rag_query, memory, process_feedback
3
+
4
+ st.title("🛡️ RAG Chatbot MB Ageas Life 🛡️")
5
+
6
+ # Initialize session history
7
+ if "messages" not in st.session_state:
8
+ st.session_state.messages = []
9
+
10
+ # Hiển thị lại tin nhắn cũ
11
+ for i, message in enumerate(st.session_state.messages):
12
+ with st.chat_message(message["role"]):
13
+ st.markdown(message["content"])
14
+ if message["role"] == "assistant":
15
+ col1, col2 = st.columns([1, 15])
16
+ with col1:
17
+ if st.button("👍", key=f"thumbs_up_{i}"):
18
+ process_feedback(st.session_state.messages[i-1]["content"], message["content"], True)
19
+ with col2:
20
+ if st.button("👎", key=f"thumbs_down_{i}"):
21
+ process_feedback(st.session_state.messages[i-1]["content"], message["content"], False)
22
+
23
+ # Nhận input người dùng
24
+ if prompt := st.chat_input("Ask me any question related to MBAL"):
25
+ # Hiển thị tin nhắn người dùng
26
+ st.chat_message("user").markdown(prompt)
27
+ st.session_state.messages.append({"role": "user", "content": prompt})
28
+ memory.chat_memory.add_user_message(prompt)
29
+
30
+ # Gọi hàm RAG để trả lời
31
+ response = rag_query(prompt)
32
+
33
+ # Hiển thị tin nhắn chatbot
34
+ with st.chat_message("assistant"):
35
+ st.markdown(response)
36
+ st.session_state.messages.append({"role": "assistant", "content": response})
37
+ memory.chat_memory.add_ai_message(response)
38
+
39
+ st.rerun()
40
+
41
+ # Sidebar
42
+ # with st.sidebar:
43
+ # st.header("Lựa chọn khác")
44
+ # if st.button("Xóa lịch sử chat"):
45
+ # st.session_state.messages = []
46
+ # memory.clear()
47
+ # st.rerun()