eagle0504 commited on
Commit
3eccf2a
Β·
verified Β·
1 Parent(s): 693b54d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -21
app.py CHANGED
@@ -53,7 +53,7 @@ with st.sidebar:
53
  # Add a button to clear the session state
54
  if st.button("Clear Session"):
55
  st.session_state.messages = []
56
- st.session_state["bot"] = None
57
  st.experimental_rerun()
58
 
59
 
@@ -69,23 +69,23 @@ for message in st.session_state.messages:
69
 
70
 
71
  # React to user input
72
- bot = ChatBot()
73
- if bot:
74
- st.session_state["bot"] = bot
75
-
76
- if prompt := st.chat_input("πŸ˜‰ Ask any question or feel free to use the examples provided in the left sidebar."):
77
-
78
- # Display user message in chat message container
79
- st.chat_message("user").markdown(prompt)
80
-
81
- # Add user message to chat history
82
- st.session_state.messages.append({"role": "user", "content": prompt})
83
-
84
- # API Call
85
- response = bot.generate_response(prompt)
86
-
87
- # Display assistant response in chat message container
88
- with st.chat_message("assistant"):
89
- st.markdown(response)
90
- # Add assistant response to chat history
91
- st.session_state.messages.append({"role": "assistant", "content": response})
 
53
  # Add a button to clear the session state
54
  if st.button("Clear Session"):
55
  st.session_state.messages = []
56
+ st.session_state["history"] = [{"role": "system", "content": "You are a helpful assistant."}]
57
  st.experimental_rerun()
58
 
59
 
 
69
 
70
 
71
  # React to user input
72
+ if prompt := st.chat_input("πŸ˜‰ Ask any question or feel free to use the examples provided in the left sidebar."):
73
+
74
+ # Display user message in chat message container
75
+ st.chat_message("user").markdown(prompt)
76
+
77
+ # Add user message to chat history
78
+ st.session_state.messages.append({"role": "user", "content": prompt})
79
+ st.session_state["history"].append({"role": "user", "content": prompt})
80
+
81
+ # API Call
82
+ bot = ChatBot(history=st.session_state["history"])
83
+ response = bot.generate_response(prompt)
84
+
85
+ # Display assistant response in chat message container
86
+ with st.chat_message("assistant"):
87
+ st.markdown(response)
88
+
89
+ # Add assistant response to chat history
90
+ st.session_state.messages.append({"role": "assistant", "content": response})
91
+ st.session_state["history"].append({"role": "assistant", "content": response})