Spaces:
Sleeping
Sleeping
matthew.farant commited on
Commit ·
1cde511
1
Parent(s): a7e8afe
Initial commit
Browse files- app/main.py +24 -1
- app/user.py +10 -0
- app/utils.py +48 -12
app/main.py
CHANGED
|
@@ -491,6 +491,23 @@ async def migrate_user(
|
|
| 491 |
user.done_first_reflection = old_user_object.done_first_reflection
|
| 492 |
user.client = client
|
| 493 |
user.conversations.client = client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
|
| 495 |
api_response = {
|
| 496 |
"user": user.user_info,
|
|
@@ -504,7 +521,13 @@ async def migrate_user(
|
|
| 504 |
"challenges": user.challenges,
|
| 505 |
"other_focusses": user.other_focusses,
|
| 506 |
"scores": f"Personal Growth: {user.personal_growth_score} || Career: {user.career_growth_score} || Health/Wellness: {user.health_and_wellness_score} || Relationships: {user.relationship_score} || Mental Health: {user.mental_well_being_score}",
|
| 507 |
-
"recent_wins": user.recent_wins
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
}
|
| 509 |
|
| 510 |
add_to_cache(user)
|
|
|
|
| 491 |
user.done_first_reflection = old_user_object.done_first_reflection
|
| 492 |
user.client = client
|
| 493 |
user.conversations.client = client
|
| 494 |
+
if hasattr(old_user_object, "goal"): setattr(user, "goal", old_user_object.goal)
|
| 495 |
+
if hasattr(old_user_object, "last_gg_session"): setattr(user, "last_gg_session", old_user_object.last_gg_session)
|
| 496 |
+
if hasattr(old_user_object, "micro_actions"): setattr(user, "micro_actions", old_user_object.micro_actions)
|
| 497 |
+
if hasattr(old_user_object, "recommended_micro_actions"): setattr(user, "recommended_micro_actions", old_user_object.recommended_micro_actions)
|
| 498 |
+
if hasattr(old_user_object, "challenges"): setattr(user, "challenges", old_user_object.challenges)
|
| 499 |
+
if hasattr(old_user_object, "other_focusses"): setattr(user, "other_focusses", old_user_object.other_focusses)
|
| 500 |
+
if hasattr(old_user_object, "personal_growth_score"): setattr(user, "personal_growth_score", old_user_object.personal_growth_score)
|
| 501 |
+
if hasattr(old_user_object, "career_growth_score"): setattr(user, "career_growth_score", old_user_object.career_growth_score)
|
| 502 |
+
if hasattr(old_user_object, "relationship_score"): setattr(user, "relationship_score", old_user_object.relationship_score)
|
| 503 |
+
if hasattr(old_user_object, "mental_well_being_score"): setattr(user, "mental_well_being_score", old_user_object.mental_well_being_score)
|
| 504 |
+
if hasattr(old_user_object, "health_and_wellness_score"): setattr(user, "health_and_wellness_score", old_user_object.health_and_wellness_score)
|
| 505 |
+
if hasattr(old_user_object, "reminders"): setattr(user, "reminders", old_user_object.reminders)
|
| 506 |
+
if hasattr(old_user_object, "recent_wins"): setattr(user, "recent_wins", old_user_object.recent_wins)
|
| 507 |
+
if hasattr(old_user_object, "recommended_gg_topics"): setattr(user, "recommended_gg_topics", old_user_object.recommended_gg_topics)
|
| 508 |
+
if hasattr(old_user_object, "growth_plan"): setattr(user, "growth_plan", old_user_object.growth_plan)
|
| 509 |
+
if hasattr(old_user_object, "user_interaction_guidelines"): setattr(user, "user_interaction_guidelines", old_user_object.user_interaction_guidelines)
|
| 510 |
+
if hasattr(old_user_object, "score_history"): setattr(user, "score_history", old_user_object.score_history)
|
| 511 |
|
| 512 |
api_response = {
|
| 513 |
"user": user.user_info,
|
|
|
|
| 521 |
"challenges": user.challenges,
|
| 522 |
"other_focusses": user.other_focusses,
|
| 523 |
"scores": f"Personal Growth: {user.personal_growth_score} || Career: {user.career_growth_score} || Health/Wellness: {user.health_and_wellness_score} || Relationships: {user.relationship_score} || Mental Health: {user.mental_well_being_score}",
|
| 524 |
+
"recent_wins": user.recent_wins,
|
| 525 |
+
"last_gg_session": user.last_gg_session,
|
| 526 |
+
"reminders": user.reminders,
|
| 527 |
+
"recommended_gg_topics": user.recommended_gg_topics,
|
| 528 |
+
"growth_plan": user.growth_plan,
|
| 529 |
+
"user_interaction_guidelines": user.user_interaction_guidelines,
|
| 530 |
+
"score_history": user.score_history
|
| 531 |
}
|
| 532 |
|
| 533 |
add_to_cache(user)
|
app/user.py
CHANGED
|
@@ -117,6 +117,8 @@ class User:
|
|
| 117 |
self.user_interaction_guidelines = self.generate_user_interaction_guidelines(user_info, client)
|
| 118 |
self.conversations = ConversationManager(client, self, asst_id)
|
| 119 |
|
|
|
|
|
|
|
| 120 |
@catch_error
|
| 121 |
def extend_growth_plan(self):
|
| 122 |
# Change current growth plan to 14d growth plan
|
|
@@ -267,6 +269,14 @@ class User:
|
|
| 267 |
elif variable == 'Relationship':
|
| 268 |
self.relationship_score += points_added
|
| 269 |
logger.info(f"Added {points_added} points to Relationship for {notes}", extra={"user_id": self.user_id, "endpoint": "add_life_score_point"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
@catch_error
|
| 272 |
def get_current_goal(self, full=False):
|
|
|
|
| 117 |
self.user_interaction_guidelines = self.generate_user_interaction_guidelines(user_info, client)
|
| 118 |
self.conversations = ConversationManager(client, self, asst_id)
|
| 119 |
|
| 120 |
+
self.score_history = []
|
| 121 |
+
|
| 122 |
@catch_error
|
| 123 |
def extend_growth_plan(self):
|
| 124 |
# Change current growth plan to 14d growth plan
|
|
|
|
| 269 |
elif variable == 'Relationship':
|
| 270 |
self.relationship_score += points_added
|
| 271 |
logger.info(f"Added {points_added} points to Relationship for {notes}", extra={"user_id": self.user_id, "endpoint": "add_life_score_point"})
|
| 272 |
+
# Add historical data (append) to score_history
|
| 273 |
+
historical_entry = {
|
| 274 |
+
"area": variable,
|
| 275 |
+
"points_added": points_added,
|
| 276 |
+
"notes": notes,
|
| 277 |
+
"created_at": pd.Timestamp.now()
|
| 278 |
+
}
|
| 279 |
+
self.score_history.append(historical_entry)
|
| 280 |
|
| 281 |
@catch_error
|
| 282 |
def get_current_goal(self, full=False):
|
app/utils.py
CHANGED
|
@@ -371,6 +371,9 @@ def get_user_summary(user_id):
|
|
| 371 |
|
| 372 |
3. **30-Minute Coaching Session Script**: A detailed, partitioned script to help the coach prepare for the session, including dialogue, questions, and guidance tailored to the client's needs, covering the five key areas. The script should be partitioned into several sections in the JSON output, similar to the structure provided for the Pre-Growth Guide Session Report.
|
| 373 |
|
|
|
|
|
|
|
|
|
|
| 374 |
---
|
| 375 |
|
| 376 |
**Instructions:**
|
|
@@ -600,12 +603,19 @@ def get_user_summary(user_id):
|
|
| 600 |
# Combine user information and chat history for context
|
| 601 |
user_context = f"""
|
| 602 |
Based on the following user profile and chat history, generate the required reports.
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
|
| 607 |
### CHAT HISTORY ###
|
| 608 |
{chat_history}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
"""
|
| 610 |
|
| 611 |
# Step 3: Call the OpenAI API using the specified function
|
|
@@ -975,16 +985,41 @@ def get_user_life_status(user_id):
|
|
| 975 |
|
| 976 |
# Get response and convert into dictionary
|
| 977 |
mantra = json.loads(response.choices[0].message.content)["mantra_of_the_week"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 978 |
|
| 979 |
# Get current life score
|
| 980 |
-
|
| 981 |
-
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 988 |
# Get current goal
|
| 989 |
current_goal = '' if not user.goal else user.goal[-1].content
|
| 990 |
# Get life score achievements in list
|
|
@@ -992,7 +1027,8 @@ def get_user_life_status(user_id):
|
|
| 992 |
# Combine everything
|
| 993 |
|
| 994 |
reports = {
|
| 995 |
-
"life_score":
|
|
|
|
| 996 |
"mantra_of_the_week": mantra,
|
| 997 |
"goal": current_goal,
|
| 998 |
"recent_wins": recent_wins
|
|
|
|
| 371 |
|
| 372 |
3. **30-Minute Coaching Session Script**: A detailed, partitioned script to help the coach prepare for the session, including dialogue, questions, and guidance tailored to the client's needs, covering the five key areas. The script should be partitioned into several sections in the JSON output, similar to the structure provided for the Pre-Growth Guide Session Report.
|
| 373 |
|
| 374 |
+
---
|
| 375 |
+
**Important Note**
|
| 376 |
+
The **chat history** shows the most updated information. Hence, if there is a difference between the goal/challenge/other key information in the user's chat history and the user's profile, you must create the reports based on the chat history!
|
| 377 |
---
|
| 378 |
|
| 379 |
**Instructions:**
|
|
|
|
| 603 |
# Combine user information and chat history for context
|
| 604 |
user_context = f"""
|
| 605 |
Based on the following user profile and chat history, generate the required reports.
|
| 606 |
+
|
| 607 |
+
**Important Note**
|
| 608 |
+
The **chat history** shows the most updated information. Hence, if there is a difference between the goal/challenge/other key information in the user's chat history and the user's profile, you must create the reports based on the chat history!
|
| 609 |
|
| 610 |
### CHAT HISTORY ###
|
| 611 |
{chat_history}
|
| 612 |
+
|
| 613 |
+
### USER GOAL ###
|
| 614 |
+
{user_goal}
|
| 615 |
+
|
| 616 |
+
### USER PROFILE ###
|
| 617 |
+
{user_info}
|
| 618 |
+
|
| 619 |
"""
|
| 620 |
|
| 621 |
# Step 3: Call the OpenAI API using the specified function
|
|
|
|
| 985 |
|
| 986 |
# Get response and convert into dictionary
|
| 987 |
mantra = json.loads(response.choices[0].message.content)["mantra_of_the_week"]
|
| 988 |
+
|
| 989 |
+
cumulative_life_score = {
|
| 990 |
+
"overall": user.personal_growth_score + user.career_growth_score + user.relationship_score + user.mental_well_being_score + user.health_and_wellness_score,
|
| 991 |
+
"personal_growth": user.personal_growth_score,
|
| 992 |
+
"health_and_wellness": user.health_and_wellness_score,
|
| 993 |
+
"mental_well_being": user.mental_well_being_score,
|
| 994 |
+
"career_growth": user.career_growth_score,
|
| 995 |
+
"relationship": user.relationship_score
|
| 996 |
+
}
|
| 997 |
|
| 998 |
# Get current life score
|
| 999 |
+
if len(user.score_history)==0:
|
| 1000 |
+
thirtydays_life_score = cumulative_life_score
|
| 1001 |
+
else:
|
| 1002 |
+
# Calculate previous 30 days date
|
| 1003 |
+
now = pd.Timestamp.now()
|
| 1004 |
+
thirty_days_ago = now - pd.Timedelta(days=30)
|
| 1005 |
+
|
| 1006 |
+
# Filter the data
|
| 1007 |
+
filtered_data = [entry for entry in user.score_history if thirty_days_ago <= entry["created_at"] <= now]
|
| 1008 |
+
|
| 1009 |
+
# Sum points_added, group by area
|
| 1010 |
+
temp_df = pd.DataFrame(filtered_data)
|
| 1011 |
+
grouped_points = temp_df.groupby("area")["points_added"].sum()
|
| 1012 |
+
|
| 1013 |
+
# Structure the output
|
| 1014 |
+
thirtydays_life_score = {
|
| 1015 |
+
"overall": grouped_points.get("Personal Growth", 0) + grouped_points.get("Career Growth", 0) + grouped_points.get("Health and Wellness", 0) + grouped_points.get("Mental Well-being", 0) + grouped_points.get("Relationship", 0),
|
| 1016 |
+
"personal_growth": grouped_points.get("Personal Growth", 0),
|
| 1017 |
+
"health_and_wellness": grouped_points.get("Health and Wellness", 0),
|
| 1018 |
+
"mental_well_being": grouped_points.get("Mental Well-being", 0),
|
| 1019 |
+
"career_growth": grouped_points.get("Career Growth", 0),
|
| 1020 |
+
"relationship": grouped_points.get("Relationship", 0)
|
| 1021 |
+
}
|
| 1022 |
+
|
| 1023 |
# Get current goal
|
| 1024 |
current_goal = '' if not user.goal else user.goal[-1].content
|
| 1025 |
# Get life score achievements in list
|
|
|
|
| 1027 |
# Combine everything
|
| 1028 |
|
| 1029 |
reports = {
|
| 1030 |
+
"life_score": thirtydays_life_score,
|
| 1031 |
+
"cumulative_life_score": cumulative_life_score,
|
| 1032 |
"mantra_of_the_week": mantra,
|
| 1033 |
"goal": current_goal,
|
| 1034 |
"recent_wins": recent_wins
|