Shageenderan Sapai commited on
Commit
1aa17f4
·
2 Parent(s): 4908d19 2c1010b

Merge remote-tracking branch 'origin/main' into pr/7

Browse files
Files changed (4) hide show
  1. app/flows.py +43 -13
  2. app/main.py +0 -7
  3. app/user.py +5 -0
  4. app/utils.py +19 -13
app/flows.py CHANGED
@@ -40,6 +40,11 @@ The user has just completed their growth guide session. Generate an appropriate
40
  """
41
 
42
  MICRO_ACTION_STATE = f"""
 
 
 
 
 
43
  **Micro-Action** *(PLEASE READ CAREFULLY)*
44
  **Objective:** Build momentum toward the user’s goal with small, actionable tasks that feel immediately achievable. Avoid saying “Today’s micro-action is:”—state the action naturally.
45
 
@@ -50,19 +55,24 @@ MICRO_ACTION_STATE = f"""
50
 
51
  *(If the user has postponed micro-actions from the list above, remind them of the postponed micro-actions and ask if they are ready to do it today. If the user says yes, proceed with the postponed micro-action. If the user says no, propose a new micro-action.)*
52
  ---
53
- **The Order of Your Conversation Flow (Follow these step-by-step instructions):**
 
 
 
 
54
 
55
- **Step 1: Your First Message: Micro-Action Suggestion**
56
 
57
  - Propose one clear, actionable task for the day.
58
  - Ensure it is relevant, easy to begin, and framed positively.
59
  - Avoid repeating previous actions.
60
- - Be concise (use Whatsapp texting length)
 
61
 
62
- **Step 2: User Response Handling**
63
 
64
  - **If the user says they can only do it on a later time:**
65
- - Send an understanding yet encouraging message.
66
  - **Ask** what time to remind them (use this question only if necessary).
67
  - Immediately call the `process_reminder()` function:
68
  ```
@@ -74,20 +84,20 @@ MICRO_ACTION_STATE = f"""
74
  )
75
  ```
76
  - Ensure that you set the `'recurrence'` to `'postponed'`.
77
- - Then, end the conversation:
78
- - Provide two short, specific, technical, and practical pieces of advice in bullet points. (Ignore if you've given the two bullet points already)
79
  - Immediately call the `end_conversation()` function without waiting for user's response
80
  - *(Do **not** explicitly mention the content of the reminder to the user.)*
81
 
82
  - **If the user has decided to try out the micro-action:**
83
- - Encourage them to proceed with the task.
84
  - Do **not** ask any questions at this point.
85
  - After the user confirms they've completed the micro-action:
86
  - Acknowledge their effort.
87
- - (Ignore if you've given the two bullet points already) Provide value with two short, specific, technical, and practical pieces of advice in bullet points, **without** asking further questions. Again, do **NOT** ask any question if you don't have to.
88
  - Be concise with your message! (use Whatsapp texting length)
89
 
90
- **Step 3: End Gracefully**
91
 
92
  - After the user's reply, immediately call the `end_conversation()` function.
93
  - Conclude with:
@@ -95,7 +105,7 @@ MICRO_ACTION_STATE = f"""
95
  - Be concise! (use Whatsapp texting length)
96
 
97
  *Note: If the user wishes to change the time of a previously set reminder, you may call the `process_reminder()` function again with the **updated** time.*
98
-
99
  ---
100
 
101
  **Key Rules for Micro-Actions**
@@ -147,6 +157,11 @@ MICRO_ACTION_STATE = f"""
147
  """
148
 
149
  FOLLUP_ACTION_STATE = f"""
 
 
 
 
 
150
  **Following Up Yesterday's Micro Action**
151
  **Objective:** Follow up on the user's progress with their micro-action from yesterday and share useful knowledge, tools, or practices from your persona. State the action naturally; avoid phrases like "Yesterday’s micro-action is:".
152
 
@@ -163,12 +178,15 @@ FOLLUP_ACTION_STATE = f"""
163
 
164
  **Conversation Flow**
165
 
 
 
 
 
166
  **If the user has no upcoming reminders:**
167
 
168
  1. **Follow Up:**
169
  - **If** the user has completed yesterday's micro-action:
170
- - Ask about their experience while doing it.
171
- - Or, ask one discussion question about the micro-action (if they already shared their experience).
172
  - **If** the user hasn't completed it:
173
  - Ask if they're going to do it today.
174
  - **Unless** they've specified a different day—then proceed to Step 2.
@@ -369,6 +387,11 @@ MOTIVATION_INSPIRATION_STATE = f"""
369
  """
370
 
371
  OPEN_DISCUSSION_STATE = f"""
 
 
 
 
 
372
  ## ** Open Discussion and Personalization ** (PLEASE READ CAREFULLY)
373
  Objective: Build rapport, create space for the user to express themselves, and adapt the interaction to their needs.
374
 
@@ -377,6 +400,7 @@ User’s Context
377
  • Day: {{}}/{{}} of their journey.
378
 
379
  The Order of Your Conversation Flow (Do these step-by-step instructions):
 
380
  Step 1. Start with a **creative** or unexpected open question to discuss together.
381
  Step 2. Acknowledge their response and using the tone of your persona, give valuable/deep advice that suits the user's challenge.
382
  Step 3. End the conversation by giving assertive advice, valuable encouragement, validation, or even a different POV that challenges the user's argument.
@@ -536,6 +560,11 @@ Based on the above, coach and engage the user in a succinct and brief conversati
536
  ** IMPORTANT **: Although asking the user for their feedback and views is good, ensure not to pose too many questions to the user. Maintain a healthy coaching conversation flow."""
537
 
538
  FUNFACT_STATE = f"""
 
 
 
 
 
539
  ## ** Giving Value to The User ** (PLEASE READ CAREFULLY)
540
  Objective: Provide a personalized and uplifting message that resonates with the user's unique attributes, recent actions, and surroundings, to motivate them on their journey to achieve their goal. The message topic could be a fun fact, mantra, or any topic about the user's profile, and it will be stated in the User's Context below!
541
 
@@ -545,6 +574,7 @@ User’s Context:
545
  • For today's message, use this user's information as the topic: {{}}
546
 
547
  The Order of Your Conversation Flow (Do these step-by-step instructions):
 
548
  Step 1. Start with a warm greeting that includes the user's name or a reference to their unique attribute (e.g., "Hi, Problem-Solver!").
549
  Step 2. Offer a fun fact or an encouraging motivational message that subtly incorporates a paraphrased quote from your persona, without mentioning the persona's name.
550
  Step 3. Close with well-wishes and an offer of support, maintaining a friendly and uplifting tone. Call the end_conversation() immediately!
 
40
  """
41
 
42
  MICRO_ACTION_STATE = f"""
43
+ Note: If the user has not answered your question yesterday, you must say something like (but warmer) "Hey, you didn't answer my question. Do you still want to continue?"
44
+ If the user says "no", then ask if they want to set a new goal (therefore later, call the change_goal() function)
45
+ But if the user says "yes", then proceed to the theme below.
46
+ Otherwise, you may directly proceed to today's theme below without asking the user.
47
+
48
  **Micro-Action** *(PLEASE READ CAREFULLY)*
49
  **Objective:** Build momentum toward the user’s goal with small, actionable tasks that feel immediately achievable. Avoid saying “Today’s micro-action is:”—state the action naturally.
50
 
 
55
 
56
  *(If the user has postponed micro-actions from the list above, remind them of the postponed micro-actions and ask if they are ready to do it today. If the user says yes, proceed with the postponed micro-action. If the user says no, propose a new micro-action.)*
57
  ---
58
+ **The Order of Your Conversation Flow (Follow these step-by-step instructions! You are sending 3 messages in a day):**
59
+
60
+ Step 0: Check whether the user has answered your yesterday's question (if any)
61
+
62
+ Step 1:
63
 
64
+ **First Message: Micro-Action Suggestion**
65
 
66
  - Propose one clear, actionable task for the day.
67
  - Ensure it is relevant, easy to begin, and framed positively.
68
  - Avoid repeating previous actions.
69
+ - Your message must be concise! (use Whatsapp texting length)
70
+ - Wait for the user's response
71
 
72
+ **Second Message: User Response Handling**
73
 
74
  - **If the user says they can only do it on a later time:**
75
+ - Send an understanding yet encouraging message (Your message must be concise!)
76
  - **Ask** what time to remind them (use this question only if necessary).
77
  - Immediately call the `process_reminder()` function:
78
  ```
 
84
  )
85
  ```
86
  - Ensure that you set the `'recurrence'` to `'postponed'`.
87
+ - Then, end the conversation by:
88
+ - Providing two short, specific, technical, and practical pieces of advice in bullet points
89
  - Immediately call the `end_conversation()` function without waiting for user's response
90
  - *(Do **not** explicitly mention the content of the reminder to the user.)*
91
 
92
  - **If the user has decided to try out the micro-action:**
93
+ - Encourage them to proceed with the task (Your message must be concise!)
94
  - Do **not** ask any questions at this point.
95
  - After the user confirms they've completed the micro-action:
96
  - Acknowledge their effort.
97
+ - (Ignore if you've given the two bullet points before) Provide value with two short, specific, technical, and practical pieces of advice in bullet points, **without** asking further questions. Again, do **NOT** ask any question if you don't have to.
98
  - Be concise with your message! (use Whatsapp texting length)
99
 
100
+ **Third Message: End Gracefully**
101
 
102
  - After the user's reply, immediately call the `end_conversation()` function.
103
  - Conclude with:
 
105
  - Be concise! (use Whatsapp texting length)
106
 
107
  *Note: If the user wishes to change the time of a previously set reminder, you may call the `process_reminder()` function again with the **updated** time.*
108
+ *Note: If the user wishes to continue the conversation after it ends, reply concisely, give a short one sentence advice, and end the conversation*
109
  ---
110
 
111
  **Key Rules for Micro-Actions**
 
157
  """
158
 
159
  FOLLUP_ACTION_STATE = f"""
160
+ Note: If the user has not answered your question yesterday, you must say something like (but warmer) "Hey, you didn't answer my question. Do you still want to continue?"
161
+ If the user says "no", then ask if they want to set a new goal (therefore later, call the change_goal() function)
162
+ But if the user says "yes", then proceed to the theme below.
163
+ Otherwise, you may directly proceed to today's theme below without asking the user.
164
+
165
  **Following Up Yesterday's Micro Action**
166
  **Objective:** Follow up on the user's progress with their micro-action from yesterday and share useful knowledge, tools, or practices from your persona. State the action naturally; avoid phrases like "Yesterday’s micro-action is:".
167
 
 
178
 
179
  **Conversation Flow**
180
 
181
+ Step 0: Check whether the user has answered your yesterday's question (if any)
182
+
183
+ Step 1:
184
+
185
  **If the user has no upcoming reminders:**
186
 
187
  1. **Follow Up:**
188
  - **If** the user has completed yesterday's micro-action:
189
+ - Do **not** ask anything and proceed to step 2
 
190
  - **If** the user hasn't completed it:
191
  - Ask if they're going to do it today.
192
  - **Unless** they've specified a different day—then proceed to Step 2.
 
387
  """
388
 
389
  OPEN_DISCUSSION_STATE = f"""
390
+ Note: If the user has not answered your question yesterday, you must say something like (but warmer) "Hey, you didn't answer my question. Do you still want to continue?"
391
+ If the user says "no", then ask if they want to set a new goal (therefore later, call the change_goal() function)
392
+ But if the user says "yes", then proceed to the theme below.
393
+ Otherwise, you may directly proceed to today's theme below without asking the user.
394
+
395
  ## ** Open Discussion and Personalization ** (PLEASE READ CAREFULLY)
396
  Objective: Build rapport, create space for the user to express themselves, and adapt the interaction to their needs.
397
 
 
400
  • Day: {{}}/{{}} of their journey.
401
 
402
  The Order of Your Conversation Flow (Do these step-by-step instructions):
403
+ Step 0. Check whether the user has answered your yesterday's question (if any)
404
  Step 1. Start with a **creative** or unexpected open question to discuss together.
405
  Step 2. Acknowledge their response and using the tone of your persona, give valuable/deep advice that suits the user's challenge.
406
  Step 3. End the conversation by giving assertive advice, valuable encouragement, validation, or even a different POV that challenges the user's argument.
 
560
  ** IMPORTANT **: Although asking the user for their feedback and views is good, ensure not to pose too many questions to the user. Maintain a healthy coaching conversation flow."""
561
 
562
  FUNFACT_STATE = f"""
563
+ Note: If the user has not answered your question yesterday, you must say something like (but warmer) "Hey, you didn't answer my question. Do you still want to continue?"
564
+ If the user says "no", then ask if they want to set a new goal (therefore later, call the change_goal() function)
565
+ But if the user says "yes", then proceed to the theme below.
566
+ Otherwise, you may directly proceed to today's theme below without asking the user.
567
+
568
  ## ** Giving Value to The User ** (PLEASE READ CAREFULLY)
569
  Objective: Provide a personalized and uplifting message that resonates with the user's unique attributes, recent actions, and surroundings, to motivate them on their journey to achieve their goal. The message topic could be a fun fact, mantra, or any topic about the user's profile, and it will be stated in the User's Context below!
570
 
 
574
  • For today's message, use this user's information as the topic: {{}}
575
 
576
  The Order of Your Conversation Flow (Do these step-by-step instructions):
577
+ Step 0. Check whether the user has answered your yesterday's question (if any)
578
  Step 1. Start with a warm greeting that includes the user's name or a reference to their unique attribute (e.g., "Hi, Problem-Solver!").
579
  Step 2. Offer a fun fact or an encouraging motivational message that subtly incorporates a paraphrased quote from your persona, without mentioning the persona's name.
580
  Step 3. Close with well-wishes and an offer of support, maintaining a friendly and uplifting tone. Call the end_conversation() immediately!
app/main.py CHANGED
@@ -403,13 +403,6 @@ def catch_endpoint_error(func):
403
  # )
404
  return wrapper
405
 
406
-
407
- @app.get("/sentry-debug")
408
- @catch_endpoint_error
409
- async def trigger_error():
410
- # testing sentry
411
- division_by_zero = 1 / 0
412
-
413
  # Apply decorator to all endpoints
414
  @app.post("/set_intro_done")
415
  @catch_endpoint_error
 
403
  # )
404
  return wrapper
405
 
 
 
 
 
 
 
 
406
  # Apply decorator to all endpoints
407
  @app.post("/set_intro_done")
408
  @catch_endpoint_error
app/user.py CHANGED
@@ -651,6 +651,11 @@ class User:
651
 
652
  (If the day is a public holiday (e.g., Christmas, New Year, or other significant occasions), customize your message to reflect the context appropriately, acknowledging the holiday or its significance.)
653
 
 
 
 
 
 
654
  Additional System Instruction:
655
  ** Always remember to incorporate your personality (based on your persona) into all of your responses. **
656
  1. Focus on giving more wisdom than questions:
 
651
 
652
  (If the day is a public holiday (e.g., Christmas, New Year, or other significant occasions), customize your message to reflect the context appropriately, acknowledging the holiday or its significance.)
653
 
654
+ Note: If the user has not answered your question yesterday, you must say something like (but warmer) "Hey, you didn't answer my question. Do you still want to continue?"
655
+ If the user says "no", then ask if they want to set a new goal (therefore later, call the change_goal() function)
656
+ But if the user says "yes", then proceed to the theme below.
657
+ Otherwise, you may directly proceed to today's theme below without asking the user.
658
+
659
  Additional System Instruction:
660
  ** Always remember to incorporate your personality (based on your persona) into all of your responses. **
661
  1. Focus on giving more wisdom than questions:
app/utils.py CHANGED
@@ -354,6 +354,7 @@ def get_user_summary(user_id):
354
  user = get_user(user_id)
355
  user_info = user.user_info
356
  user_messages = user.get_messages()
 
357
 
358
  # Step 2: Construct the Prompt
359
  chat_history = "\n".join(
@@ -426,22 +427,27 @@ def get_user_summary(user_id):
426
  ### **2. User's Growth Guide Preparation Brief**
427
 
428
  **Objective**: Guide the user on what to discuss with the Growth Guide, providing actionable advice and highlighting key areas to focus on during their session, covering the five key areas.
 
429
 
430
- **ALWAYS** be succinct, valuable and personalized!
 
 
 
 
431
 
432
  **Format**:
433
 
434
- Structure the brief with the following sections, and output it as a JSON object with these keys:
435
 
436
- - **reflect**: Give a succinct, valuable and personalized advice to the user to consider what each focus area means to them and which aspects they want to improve.
437
 
438
- - **recall_successes**: Give a succinct, valuable and personalized prompt to the user to think of times when they effectively managed or improved in the five key areas, and what strategies worked for them then.
439
 
440
- - **identify_challenges**: Give a succinct, valuable and personalized advice to the user to be ready to discuss any obstacles they're facing in each area, and to consider possible solutions or resources that might help.
441
 
442
- - **set_goals**: Ask the user to decide what they hope to achieve from the session and how improvements in each area will impact their life.
443
 
444
- - **additional_tips**: Give a succinct, valuable and personalized practical advice for the session, such as choosing a quiet space, having materials ready, and being open to sharing thoughts honestly.
445
 
446
  ---
447
 
@@ -544,23 +550,23 @@ def get_user_summary(user_id):
544
  "users_growth_guide_preparation_brief": [
545
  {
546
  "key": "reflect",
547
- "value": "⁠Reflect on what career growth means to you and the goals you’re striving for."
548
  },
549
  {
550
  "key": "recall_successes",
551
- "value": "⁠Recall moments when you successfully navigated challenges in your career or relationships—what worked"
552
  },
553
  {
554
  "key": "identify_challenges",
555
- "value": "⁠Think about any current obstacles and possible ways to overcome them"
556
  },
557
  {
558
  "key": "set_goals",
559
- "value": "⁠Define what you want to achieve from this session and how those changes could impact your life."
560
  },
561
  {
562
  "key": "additional_tips",
563
- "value": "⁠Prepare by choosing a quiet space, having a notebook ready, and being open to sharing honestly."
564
  }
565
  ],
566
  "30_minute_coaching_session_script": {
@@ -605,7 +611,7 @@ def get_user_summary(user_id):
605
  # Step 3: Call the OpenAI API using the specified function
606
  client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
607
  response = client.chat.completions.create(
608
- model="gpt-4o-mini",
609
  messages=[
610
  {
611
  "role": "system",
 
354
  user = get_user(user_id)
355
  user_info = user.user_info
356
  user_messages = user.get_messages()
357
+ user_goal = '' if not user.goal else user.goal[-1].content
358
 
359
  # Step 2: Construct the Prompt
360
  chat_history = "\n".join(
 
427
  ### **2. User's Growth Guide Preparation Brief**
428
 
429
  **Objective**: Guide the user on what to discuss with the Growth Guide, providing actionable advice and highlighting key areas to focus on during their session, covering the five key areas.
430
+ You must use the user's current **challenges** and **life goal** to make the preparation brief **personalized**!
431
 
432
+ Important Rules:
433
+ 1. **ALWAYS** be succinct, valuable and personalized! Do **NOT** ask generic question. Ask a personalized question! And bold the key parts of the user brief!
434
+ 2. **Session Length Awareness**: Be realistic about what can be effectively discussed in a 30-minute session. Prioritize the areas that are most pressing or offer the greatest opportunity for positive change.
435
+ 3. **Guidance for Interaction**: Provide specific suggestions for topics to discuss with the **Growth Guide**, you are encouraged to use phrases like "Discuss with your Growth Guide how to...".
436
+ 4. And for the second time, please be succinct and concise!!!
437
 
438
  **Format**:
439
 
440
+ Structure the brief with the following sections, and output it as a JSON object with these keys (don't forget to BE CONCISE! and you **must** bold some words that you think is important! but it does **not** have to be the first few words!):
441
 
442
+ - **reflect**: Provide personalized advice that encourages the user to contemplate their specific experiences, feelings, and thoughts related to each of the five key areas. Help them identify particular aspects they wish to improve, based on their challenges and goals.
443
 
444
+ - **recall_successes**: Prompt the user to remember past occasions when they effectively managed or made improvements in these areas. Encourage them to consider the strategies, habits, or resources that contributed to these successes, and how they might apply them now.
445
 
446
+ - **identify_challenges**: Advise the user to acknowledge current obstacles they are facing in each area. Encourage them to think critically about these challenges and consider potential solutions or support systems that could assist in overcoming them.
447
 
448
+ - **set_goals**: Encourage the user to define clear and achievable objectives for the upcoming session. Guide them to consider how making improvements in each key area can positively impact their overall well-being and life satisfaction.
449
 
450
+ - **additional_tips**: Offer practical advice to help the user prepare for the session. Suggestions may include arranging a quiet and comfortable space, gathering any relevant materials or notes, and approaching the session with openness and honesty.
451
 
452
  ---
453
 
 
550
  "users_growth_guide_preparation_brief": [
551
  {
552
  "key": "reflect",
553
+ "value": "⁠..."
554
  },
555
  {
556
  "key": "recall_successes",
557
+ "value": "⁠..."
558
  },
559
  {
560
  "key": "identify_challenges",
561
+ "value": "..."
562
  },
563
  {
564
  "key": "set_goals",
565
+ "value": "⁠..."
566
  },
567
  {
568
  "key": "additional_tips",
569
+ "value": "⁠..."
570
  }
571
  ],
572
  "30_minute_coaching_session_script": {
 
611
  # Step 3: Call the OpenAI API using the specified function
612
  client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
613
  response = client.chat.completions.create(
614
+ model="gpt-4o",
615
  messages=[
616
  {
617
  "role": "system",