Spaces:
Sleeping
Sleeping
Context Mgmt: Answering Questions about Life Status
#6
by
LittleKnife - opened
- app/assistants.py +16 -2
- app/flows.py +4 -3
- app/user.py +75 -64
app/assistants.py
CHANGED
|
@@ -614,8 +614,11 @@ class Assistant:
|
|
| 614 |
# "micro_actions",
|
| 615 |
# "other_focusses",
|
| 616 |
# "reminders",
|
| 617 |
-
# "goal"
|
| 618 |
-
# "growth_guide_session"
|
|
|
|
|
|
|
|
|
|
| 619 |
logger.info(f"Getting user information: {category}",
|
| 620 |
extra={"user_id": self.cm.user.user_id, "endpoint": "assistant_get_user_info"})
|
| 621 |
user_info = ''
|
|
@@ -638,6 +641,10 @@ class Assistant:
|
|
| 638 |
user_info += f"** GG Session **\n\n{get_growth_guide_summary(self.cm.user.user_id, self.cm.user.last_gg_session)}"
|
| 639 |
else:
|
| 640 |
user_info += f"** GG Session **\n\nNo GG yet. Let the user know they can book one now through their Revelation Dashboard: {OURCOACH_DASHBOARD_URL}!"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 641 |
|
| 642 |
logger.info(f"Finish Getting user information: {user_info}",
|
| 643 |
extra={"user_id": self.cm.user.user_id, "endpoint": "assistant_get_user_info"})
|
|
@@ -645,6 +652,13 @@ class Assistant:
|
|
| 645 |
"tool_call_id": tool.id,
|
| 646 |
"output": f"** User Info:\n\n{user_info} **"
|
| 647 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
|
| 649 |
# Submit all tool outputs at once after collecting them in a list
|
| 650 |
if tool_outputs:
|
|
|
|
| 614 |
# "micro_actions",
|
| 615 |
# "other_focusses",
|
| 616 |
# "reminders",
|
| 617 |
+
# "goal",
|
| 618 |
+
# "growth_guide_session",
|
| 619 |
+
# "life_score",
|
| 620 |
+
# "recent_wins",
|
| 621 |
+
# ]
|
| 622 |
logger.info(f"Getting user information: {category}",
|
| 623 |
extra={"user_id": self.cm.user.user_id, "endpoint": "assistant_get_user_info"})
|
| 624 |
user_info = ''
|
|
|
|
| 641 |
user_info += f"** GG Session **\n\n{get_growth_guide_summary(self.cm.user.user_id, self.cm.user.last_gg_session)}"
|
| 642 |
else:
|
| 643 |
user_info += f"** GG Session **\n\nNo GG yet. Let the user know they can book one now through their Revelation Dashboard: {OURCOACH_DASHBOARD_URL}!"
|
| 644 |
+
elif category == "life_score":
|
| 645 |
+
user_info += f"** Life scores for each area **\n\n Personal Growth: {self.cm.user.personal_growth_score} || Career: {self.cm.user.career_growth_score} || Health/Wellness: {self.cm.user.health_and_wellness_score} || Relationships: {self.cm.user.relationship_score} || Mental Health: {self.cm.user.mental_well_being_score}"
|
| 646 |
+
elif category == "recent_wins":
|
| 647 |
+
user_info += f"** Recent Wins / Achievements **\n\n {self.cm.user.recent_wins}"
|
| 648 |
|
| 649 |
logger.info(f"Finish Getting user information: {user_info}",
|
| 650 |
extra={"user_id": self.cm.user.user_id, "endpoint": "assistant_get_user_info"})
|
|
|
|
| 652 |
"tool_call_id": tool.id,
|
| 653 |
"output": f"** User Info:\n\n{user_info} **"
|
| 654 |
})
|
| 655 |
+
elif tool.function.name == "extend_two_weeks":
|
| 656 |
+
logger.info(f"Changing plan from 1 week to 2 weeks...", extra={"user_id": self.cm.user.user_id, "endpoint": "extend_two_weeks"})
|
| 657 |
+
goal = self.cm.user.extend_growth_plan()
|
| 658 |
+
tool_outputs.append({
|
| 659 |
+
"tool_call_id": tool.id,
|
| 660 |
+
"output": f"Changed plan from 1 week to 2 weeks."
|
| 661 |
+
})
|
| 662 |
|
| 663 |
# Submit all tool outputs at once after collecting them in a list
|
| 664 |
if tool_outputs:
|
app/flows.py
CHANGED
|
@@ -75,7 +75,7 @@ MICRO_ACTION_STATE = f"""
|
|
| 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.
|
| 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 |
|
|
@@ -84,7 +84,7 @@ MICRO_ACTION_STATE = f"""
|
|
| 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 |
-
- 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**
|
|
@@ -511,8 +511,9 @@ And remember, a Growth Guide can help you reflect, strategize, and take things t
|
|
| 511 |
|
| 512 |
Keep the momentum going—you’ve got this! 💥
|
| 513 |
|
|
|
|
| 514 |
|
| 515 |
-
- If they want to
|
| 516 |
|
| 517 |
- If the user said that they've completed their goal, call the complete_goal() function!
|
| 518 |
|
|
|
|
| 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 |
|
|
|
|
| 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**
|
|
|
|
| 511 |
|
| 512 |
Keep the momentum going—you’ve got this! 💥
|
| 513 |
|
| 514 |
+
- If the user wants to extend the plan for another 2 weeks, call the extend_two_weeks() function!
|
| 515 |
|
| 516 |
+
- If they want to set a new goal, confirm to the user first, and then call the change_goal() function if the user confirms the goal change!
|
| 517 |
|
| 518 |
- If the user said that they've completed their goal, call the complete_goal() function!
|
| 519 |
|
app/user.py
CHANGED
|
@@ -321,69 +321,6 @@ class User:
|
|
| 321 |
self.recent_wins = []
|
| 322 |
|
| 323 |
# Read growth_plan.json and store it
|
| 324 |
-
# growth_plan = {"growthPlan": [
|
| 325 |
-
# {
|
| 326 |
-
# "day": 1,
|
| 327 |
-
# "coachingTheme": "MICRO_ACTION_STATE"
|
| 328 |
-
# },
|
| 329 |
-
# {
|
| 330 |
-
# "day": 2,
|
| 331 |
-
# "coachingTheme": "MICRO_ACTION_STATE"
|
| 332 |
-
# },
|
| 333 |
-
# {
|
| 334 |
-
# "day": 3,
|
| 335 |
-
# "coachingTheme": "EDUCATION_STATE"
|
| 336 |
-
# },
|
| 337 |
-
# {
|
| 338 |
-
# "day": 4,
|
| 339 |
-
# "coachingTheme": "MOTIVATION_INSPIRATION_STATE"
|
| 340 |
-
# },
|
| 341 |
-
# {
|
| 342 |
-
# "day": 5,
|
| 343 |
-
# "coachingTheme": "MICRO_ACTION_STATE"
|
| 344 |
-
# },
|
| 345 |
-
# {
|
| 346 |
-
# "day": 6,
|
| 347 |
-
# "coachingTheme": "EDUCATION_STATE"
|
| 348 |
-
# },
|
| 349 |
-
# {
|
| 350 |
-
# "day": 7,
|
| 351 |
-
# "coachingTheme": "PROGRESS_REFLECTION_STATE"
|
| 352 |
-
# },
|
| 353 |
-
# {
|
| 354 |
-
# "day": 8,
|
| 355 |
-
# "coachingTheme": "PROGRESS_SUMMARY_STATE"
|
| 356 |
-
# },
|
| 357 |
-
# {
|
| 358 |
-
# "day": 9,
|
| 359 |
-
# "coachingTheme": "MICRO_ACTION_STATE"
|
| 360 |
-
# },
|
| 361 |
-
# {
|
| 362 |
-
# "day": 10,
|
| 363 |
-
# "coachingTheme": "MICRO_ACTION_STATE"
|
| 364 |
-
# },
|
| 365 |
-
# {
|
| 366 |
-
# "day": 11,
|
| 367 |
-
# "coachingTheme": "EDUCATION_STATE"
|
| 368 |
-
# },
|
| 369 |
-
# {
|
| 370 |
-
# "day": 12,
|
| 371 |
-
# "coachingTheme": "MOTIVATION_INSPIRATION_STATE"
|
| 372 |
-
# },
|
| 373 |
-
# {
|
| 374 |
-
# "day": 13,
|
| 375 |
-
# "coachingTheme": "MICRO_ACTION_STATE"
|
| 376 |
-
# },
|
| 377 |
-
# {
|
| 378 |
-
# "day": 14,
|
| 379 |
-
# "coachingTheme": "EDUCATION_STATE"
|
| 380 |
-
# },
|
| 381 |
-
# {
|
| 382 |
-
# "day": 15,
|
| 383 |
-
# "coachingTheme": "FINAL_SUMMARY_STATE"
|
| 384 |
-
# }
|
| 385 |
-
# ]
|
| 386 |
-
# }
|
| 387 |
|
| 388 |
# TESTING PURPOSE
|
| 389 |
growth_plan = {"growthPlan": [
|
|
@@ -417,6 +354,77 @@ class User:
|
|
| 417 |
self.user_interaction_guidelines = self.generate_user_interaction_guidelines(user_info, client)
|
| 418 |
self.conversations = ConversationManager(client, self, asst_id)
|
| 419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
def add_recent_wins(self, wins, context = None):
|
| 421 |
prompt = f"""
|
| 422 |
## Role
|
|
@@ -654,7 +662,7 @@ class User:
|
|
| 654 |
# send the change goal prompt
|
| 655 |
logger.info("Sending change goal message...", extra={"user_id": self.user_id, "endpoint": "user_send_message"})
|
| 656 |
prompt = f"""
|
| 657 |
-
I want to change my goal!
|
| 658 |
|
| 659 |
Previous Goal:
|
| 660 |
{self.get_current_goal()}
|
|
@@ -852,6 +860,9 @@ class User:
|
|
| 852 |
# """
|
| 853 |
|
| 854 |
prompt = f"""** It is a new day: {date} ({day}) 10:00:00 **
|
|
|
|
|
|
|
|
|
|
| 855 |
Additional System Instruction:
|
| 856 |
** Always remember to incorporate your personality (based on your persona) into all of your responses. **
|
| 857 |
1. Focus on giving more wisdom than questions:
|
|
|
|
| 321 |
self.recent_wins = []
|
| 322 |
|
| 323 |
# Read growth_plan.json and store it
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
|
| 325 |
# TESTING PURPOSE
|
| 326 |
growth_plan = {"growthPlan": [
|
|
|
|
| 354 |
self.user_interaction_guidelines = self.generate_user_interaction_guidelines(user_info, client)
|
| 355 |
self.conversations = ConversationManager(client, self, asst_id)
|
| 356 |
|
| 357 |
+
def extend_growth_plan(self):
|
| 358 |
+
# Change current growth plan to 14d growth plan
|
| 359 |
+
logger.info(f"Changing plan to 14d...", extra={"user_id": self.user_id, "endpoint": "extend_growth_plan"})
|
| 360 |
+
try:
|
| 361 |
+
new_growth_plan = {"growthPlan": [
|
| 362 |
+
{
|
| 363 |
+
"day": 1,
|
| 364 |
+
"coachingTheme": "MICRO_ACTION_STATE"
|
| 365 |
+
},
|
| 366 |
+
{
|
| 367 |
+
"day": 2,
|
| 368 |
+
"coachingTheme": "FOLLUP_ACTION_STATE"
|
| 369 |
+
},
|
| 370 |
+
{
|
| 371 |
+
"day": 3,
|
| 372 |
+
"coachingTheme": "OPEN_DISCUSSION_STATE"
|
| 373 |
+
},
|
| 374 |
+
{
|
| 375 |
+
"day": 4,
|
| 376 |
+
"coachingTheme": "MICRO_ACTION_STATE"
|
| 377 |
+
},
|
| 378 |
+
{
|
| 379 |
+
"day": 5,
|
| 380 |
+
"coachingTheme": "FOLLUP_ACTION_STATE"
|
| 381 |
+
},
|
| 382 |
+
{
|
| 383 |
+
"day": 6,
|
| 384 |
+
"coachingTheme": "FUNFACT_STATE"
|
| 385 |
+
},
|
| 386 |
+
{
|
| 387 |
+
"day": 7,
|
| 388 |
+
"coachingTheme": "PROGRESS_REFLECTION_STATE"
|
| 389 |
+
},
|
| 390 |
+
{
|
| 391 |
+
"day": 8,
|
| 392 |
+
"coachingTheme": "MICRO_ACTION_STATE"
|
| 393 |
+
},
|
| 394 |
+
{
|
| 395 |
+
"day": 9,
|
| 396 |
+
"coachingTheme": "FOLLUP_ACTION_STATE"
|
| 397 |
+
},
|
| 398 |
+
{
|
| 399 |
+
"day": 10,
|
| 400 |
+
"coachingTheme": "OPEN_DISCUSSION_STATE"
|
| 401 |
+
},
|
| 402 |
+
{
|
| 403 |
+
"day": 11,
|
| 404 |
+
"coachingTheme": "MICRO_ACTION_STATE"
|
| 405 |
+
},
|
| 406 |
+
{
|
| 407 |
+
"day": 12,
|
| 408 |
+
"coachingTheme": "FOLLUP_ACTION_STATE"
|
| 409 |
+
},
|
| 410 |
+
{
|
| 411 |
+
"day": 13,
|
| 412 |
+
"coachingTheme": "FUNFACT_STATE"
|
| 413 |
+
},
|
| 414 |
+
{
|
| 415 |
+
"day": 14,
|
| 416 |
+
"coachingTheme": "FINAL_SUMMARY_STATE"
|
| 417 |
+
}
|
| 418 |
+
]
|
| 419 |
+
}
|
| 420 |
+
self.growth_plan = CircularQueue(array=new_growth_plan['growthPlan'], user_id=self.user_id)
|
| 421 |
+
logger.info(f"User Growth Plan: {self.growth_plan} (Day: {self.growth_plan.current()['day']}/{len(self.growth_plan.array)})", extra={"user_id": self.user_id, "endpoint": "user_init"})
|
| 422 |
+
logger.info(f"Success.", extra={"user_id": self.user_id, "endpoint": "extend_growth_plan"})
|
| 423 |
+
except Exception as e:
|
| 424 |
+
logger.error(f"Error occured when changing plan: {e}", extra={"user_id": self.user_id, "endpoint": "extend_growth_plan"})
|
| 425 |
+
raise
|
| 426 |
+
|
| 427 |
+
|
| 428 |
def add_recent_wins(self, wins, context = None):
|
| 429 |
prompt = f"""
|
| 430 |
## Role
|
|
|
|
| 662 |
# send the change goal prompt
|
| 663 |
logger.info("Sending change goal message...", extra={"user_id": self.user_id, "endpoint": "user_send_message"})
|
| 664 |
prompt = f"""
|
| 665 |
+
I want to change my goal! Based on my information below, suggest me a new goal, and **ONLY** if i approve, call the create_smart_goal() function
|
| 666 |
|
| 667 |
Previous Goal:
|
| 668 |
{self.get_current_goal()}
|
|
|
|
| 860 |
# """
|
| 861 |
|
| 862 |
prompt = f"""** It is a new day: {date} ({day}) 10:00:00 **
|
| 863 |
+
|
| 864 |
+
(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.)
|
| 865 |
+
|
| 866 |
Additional System Instruction:
|
| 867 |
** Always remember to incorporate your personality (based on your persona) into all of your responses. **
|
| 868 |
1. Focus on giving more wisdom than questions:
|