jostlebot commited on
Commit
bf623c0
·
1 Parent(s): 7eee57b

Add comprehensive debrief functionality

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +64 -10
src/streamlit_app.py CHANGED
@@ -60,6 +60,10 @@ if 'setup_complete' not in st.session_state:
60
  st.session_state.setup_complete = False
61
  if 'system_message' not in st.session_state:
62
  st.session_state.system_message = ""
 
 
 
 
63
 
64
  # Main page header
65
  st.title("Attachment Style Roleplay Simulator")
@@ -146,6 +150,14 @@ with st.form("setup_form"):
146
  submitted = st.form_submit_button("Start Simulation")
147
 
148
  if submitted:
 
 
 
 
 
 
 
 
149
  # Prepare system message with simulation parameters
150
  st.session_state.system_message = f"""
151
  You are a conversational partner helping someone practice difficult conversations.
@@ -154,11 +166,30 @@ with st.form("setup_form"):
154
  Respond in a {tone} manner. Help them achieve their goals: {goals}
155
 
156
  Maintain a realistic conversation while providing gentle guidance when needed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  """
158
 
159
- # Reset message history
160
  st.session_state.messages = []
161
  st.session_state.setup_complete = True
 
162
  st.rerun()
163
 
164
  # Display status or chat interface
@@ -171,7 +202,28 @@ else:
171
  st.markdown(message["content"])
172
 
173
  # Chat input
174
- if prompt := st.chat_input("Type your message here..."):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  # Add user message to chat history
176
  st.session_state.messages.append({"role": "user", "content": prompt})
177
 
@@ -182,14 +234,6 @@ else:
182
  # Get AI response
183
  with st.chat_message("assistant"):
184
  with st.spinner("Thinking..."):
185
- # Construct conversation history
186
- messages = []
187
- if st.session_state.system_message:
188
- messages.append({"role": "system", "content": st.session_state.system_message})
189
- for msg in st.session_state.messages:
190
- messages.append({"role": msg["role"], "content": msg["content"]})
191
-
192
- # Get completion
193
  try:
194
  message = c.messages.create(
195
  model="claude-3-opus-20240229",
@@ -212,6 +256,16 @@ else:
212
  st.error(f"Error getting AI response: {str(e)}")
213
  st.error("Please try again or contact support if the issue persists.")
214
 
 
 
 
 
 
 
 
 
 
 
215
  # Footer
216
  st.markdown("---")
217
  st.markdown(
 
60
  st.session_state.setup_complete = False
61
  if 'system_message' not in st.session_state:
62
  st.session_state.system_message = ""
63
+ if 'simulation_params' not in st.session_state:
64
+ st.session_state.simulation_params = {}
65
+ if 'in_debrief' not in st.session_state:
66
+ st.session_state.in_debrief = False
67
 
68
  # Main page header
69
  st.title("Attachment Style Roleplay Simulator")
 
150
  submitted = st.form_submit_button("Start Simulation")
151
 
152
  if submitted:
153
+ # Store simulation parameters for debrief
154
+ st.session_state.simulation_params = {
155
+ "attachment_style": attachment_style,
156
+ "scenario": scenario,
157
+ "tone": tone,
158
+ "goals": goals
159
+ }
160
+
161
  # Prepare system message with simulation parameters
162
  st.session_state.system_message = f"""
163
  You are a conversational partner helping someone practice difficult conversations.
 
166
  Respond in a {tone} manner. Help them achieve their goals: {goals}
167
 
168
  Maintain a realistic conversation while providing gentle guidance when needed.
169
+
170
+ IMPORTANT: If the user types "debrief" or "end roleplay", switch to debrief mode using this format:
171
+
172
+ 📝 DEBRIEF SUMMARY
173
+
174
+ **Emotional Arc**: [Analyze how the user shifted emotionally during the interaction, noting moments of courage, freeze, protest, backtracking, or people-pleasing]
175
+
176
+ **Goal Alignment**: [Reflect on how well they stayed aligned with their stated goal. Note small wins and struggles, affirm effort and awareness]
177
+
178
+ **Attachment Insight**: [Offer one insight based on their {attachment_style} attachment style. Normalize the response as protective. Gently suggest a next growth step without shaming]
179
+
180
+ **Practical Tool**: [Offer a brief NVC or DBT tool they could try next time (e.g., needs check-in, opposite action, self-validation, distress tolerance)]
181
+
182
+ **Bold Reframe**: [Offer one bold, loving sentence they might say if they trusted their relational worth]
183
+
184
+ **Journaling Prompt**: [Suggest one reflective question or embodied inquiry for integration]
185
+
186
+ Speak warmly and with psychological precision, like an emotionally attuned therapist.
187
  """
188
 
189
+ # Reset message history and state
190
  st.session_state.messages = []
191
  st.session_state.setup_complete = True
192
+ st.session_state.in_debrief = False
193
  st.rerun()
194
 
195
  # Display status or chat interface
 
202
  st.markdown(message["content"])
203
 
204
  # Chat input
205
+ if prompt := st.chat_input("Type your message here (type 'debrief' or 'end roleplay' when ready to reflect)"):
206
+ # Check for debrief trigger
207
+ if prompt.lower() in ["debrief", "end roleplay"] and not st.session_state.in_debrief:
208
+ st.session_state.in_debrief = True
209
+ # Construct conversation summary
210
+ conversation_summary = "\n".join([
211
+ f"{msg['role']}: {msg['content']}"
212
+ for msg in st.session_state.messages
213
+ ])
214
+
215
+ # Add debrief request to messages
216
+ prompt = f"""Please provide a therapeutic debrief for this roleplay session using:
217
+
218
+ Attachment Style: {st.session_state.simulation_params['attachment_style']}
219
+ Scenario: {st.session_state.simulation_params['scenario']}
220
+ Goals: {st.session_state.simulation_params['goals']}
221
+ AI Tone: {st.session_state.simulation_params['tone']}
222
+
223
+ Conversation Summary:
224
+ {conversation_summary}
225
+ """
226
+
227
  # Add user message to chat history
228
  st.session_state.messages.append({"role": "user", "content": prompt})
229
 
 
234
  # Get AI response
235
  with st.chat_message("assistant"):
236
  with st.spinner("Thinking..."):
 
 
 
 
 
 
 
 
237
  try:
238
  message = c.messages.create(
239
  model="claude-3-opus-20240229",
 
256
  st.error(f"Error getting AI response: {str(e)}")
257
  st.error("Please try again or contact support if the issue persists.")
258
 
259
+ # Add restart button after debrief
260
+ if st.session_state.in_debrief:
261
+ if st.button("Start New Roleplay"):
262
+ st.session_state.setup_complete = False
263
+ st.session_state.in_debrief = False
264
+ st.session_state.messages = []
265
+ st.session_state.system_message = ""
266
+ st.session_state.simulation_params = {}
267
+ st.rerun()
268
+
269
  # Footer
270
  st.markdown("---")
271
  st.markdown(