ogegadavis254 commited on
Commit
e8f8a5f
·
verified ·
1 Parent(s): a25491c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -10,6 +10,7 @@ def reset_conversation():
10
  Resets Conversation
11
  '''
12
  st.session_state.messages = []
 
13
  return None
14
 
15
  # Define model links for the Addiction Recovery and Mental Health models
@@ -28,8 +29,11 @@ model_pre_instructions = {
28
  def interact_with_together_api(messages, model_link):
29
  all_messages = []
30
 
31
- # Add pre-instructions to the message history
32
- all_messages.append({"role": "system", "content": model_pre_instructions[selected_model]})
 
 
 
33
 
34
  # Append user and assistant messages
35
  for human, assistant in messages:
@@ -70,15 +74,28 @@ def interact_with_together_api(messages, model_link):
70
  selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
71
  st.sidebar.button('Reset Chat', on_click=reset_conversation)
72
 
73
- # Initialize chat history
 
 
 
74
  if "messages" not in st.session_state:
75
  st.session_state.messages = []
 
 
76
 
77
  # Display chat messages from history on app rerun
78
  for message in st.session_state.messages:
79
  with st.chat_message(message[0]):
80
  st.markdown(message[1])
81
 
 
 
 
 
 
 
 
 
82
  # Accept user input
83
  if prompt := st.chat_input(f"Hi, I'm {selected_model}, ask me a question"):
84
  # Display user message in chat message container
 
10
  Resets Conversation
11
  '''
12
  st.session_state.messages = []
13
+ st.session_state.user_interactions = 0 # Reset user interactions counter
14
  return None
15
 
16
  # Define model links for the Addiction Recovery and Mental Health models
 
29
  def interact_with_together_api(messages, model_link):
30
  all_messages = []
31
 
32
+ # Add pre-instructions to the message history if it's the first interaction with this model
33
+ if not any("role" in msg for msg in messages):
34
+ all_messages.append({"role": "system", "content": model_pre_instructions[selected_model]})
35
+ else:
36
+ all_messages.append({"role": "system", "content": f"Switched to model: {selected_model}"})
37
 
38
  # Append user and assistant messages
39
  for human, assistant in messages:
 
74
  selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
75
  st.sidebar.button('Reset Chat', on_click=reset_conversation)
76
 
77
+ # Add cautionary message about testing phase at the bottom of the sidebar
78
+ st.sidebar.markdown("**Note**: This model is still in the testing phase. Responses may be inaccurate or undesired. Use it cautiously, especially for critical issues.")
79
+
80
+ # Initialize chat history and user interactions counter
81
  if "messages" not in st.session_state:
82
  st.session_state.messages = []
83
+ if "user_interactions" not in st.session_state:
84
+ st.session_state.user_interactions = 0
85
 
86
  # Display chat messages from history on app rerun
87
  for message in st.session_state.messages:
88
  with st.chat_message(message[0]):
89
  st.markdown(message[1])
90
 
91
+ # Increment user interactions counter
92
+ st.session_state.user_interactions += 1
93
+
94
+ # Display recommendation popup after the first 10 user interactions
95
+ if st.session_state.user_interactions == 10:
96
+ recommendation = st.sidebar.radio("Would you recommend this model to others?", ("Yes", "No"))
97
+ st.sidebar.write(f"You recommended: {recommendation}")
98
+
99
  # Accept user input
100
  if prompt := st.chat_input(f"Hi, I'm {selected_model}, ask me a question"):
101
  # Display user message in chat message container