Spaces:
Sleeping
Sleeping
matthew.farant commited on
Commit ·
eb2df8f
1
Parent(s): eb3dba5
Add mantra to context mgmt & Monday msg
Browse files- app/assistants.py +1 -1
- app/user.py +32 -3
- app/utils.py +2 -1
app/assistants.py
CHANGED
|
@@ -676,7 +676,7 @@ class Assistant:
|
|
| 676 |
user_info = '** If the user asks for their progress, also include a link to their Revelation Dashboard: {OURCOACH_DASHBOARD_URL} so that they can find out more **\n\n'
|
| 677 |
if category == "personal":
|
| 678 |
user_info += f"** Personal Information **\n\n{self.cm.user.user_info}"
|
| 679 |
-
user_info += f"\n\n** User's Mantra This Week
|
| 680 |
elif category == "challenges":
|
| 681 |
user_info += f"** User's Challenges (prioritise ONGOING challenges) **\n\n{self.cm.user.challenges}\n\nLet the user know that ongoing challenges from their growth guide will be integrated into their day-to-day interaction."
|
| 682 |
elif category == "recommended_actions":
|
|
|
|
| 676 |
user_info = '** If the user asks for their progress, also include a link to their Revelation Dashboard: {OURCOACH_DASHBOARD_URL} so that they can find out more **\n\n'
|
| 677 |
if category == "personal":
|
| 678 |
user_info += f"** Personal Information **\n\n{self.cm.user.user_info}"
|
| 679 |
+
user_info += f"\n\n** User's Mantra This Week:**\n\n{self.cm.user.mantra or "Mantra not available."}"
|
| 680 |
elif category == "challenges":
|
| 681 |
user_info += f"** User's Challenges (prioritise ONGOING challenges) **\n\n{self.cm.user.challenges}\n\nLet the user know that ongoing challenges from their growth guide will be integrated into their day-to-day interaction."
|
| 682 |
elif category == "recommended_actions":
|
app/user.py
CHANGED
|
@@ -6,6 +6,7 @@ import pandas as pd
|
|
| 6 |
from datetime import datetime, timezone
|
| 7 |
import json
|
| 8 |
from app.assistants import Assistant
|
|
|
|
| 9 |
import glob
|
| 10 |
import pickle # Replace dill with pickle
|
| 11 |
import random
|
|
@@ -328,9 +329,33 @@ class User:
|
|
| 328 |
return False
|
| 329 |
|
| 330 |
@catch_error
|
| 331 |
-
def set_mantra(self
|
| 332 |
-
|
| 333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
@catch_error
|
| 336 |
def set_goal(self, goal, goal_area, add=True, completed=False):
|
|
@@ -847,6 +872,8 @@ class User:
|
|
| 847 |
|
| 848 |
Today is day {self.cumulative_plan_day} of the user's growth journey (out of {final_day} days). You may (or may not) mention this occasionally in your first message of the day.
|
| 849 |
|
|
|
|
|
|
|
| 850 |
Today's Theme:
|
| 851 |
{formatted_message}
|
| 852 |
"""
|
|
@@ -869,6 +896,8 @@ class User:
|
|
| 869 |
self.conversations.delete_hidden_messages()
|
| 870 |
# update the date in the state
|
| 871 |
self.conversations.state['date'] = date
|
|
|
|
|
|
|
| 872 |
|
| 873 |
action = self.growth_plan.current()
|
| 874 |
|
|
|
|
| 6 |
from datetime import datetime, timezone
|
| 7 |
import json
|
| 8 |
from app.assistants import Assistant
|
| 9 |
+
from app.exceptions import DBError
|
| 10 |
import glob
|
| 11 |
import pickle # Replace dill with pickle
|
| 12 |
import random
|
|
|
|
| 329 |
return False
|
| 330 |
|
| 331 |
@catch_error
|
| 332 |
+
def set_mantra(self):
|
| 333 |
+
### To save mantra in database to user object
|
| 334 |
+
logger.info(f"Getting mantra from user...", extra={"user_id": self.user_id, "endpoint": "get_mantra"})
|
| 335 |
+
user_id = self.user_id
|
| 336 |
+
db_params = {
|
| 337 |
+
'dbname': 'ourcoach',
|
| 338 |
+
'user': 'ourcoach',
|
| 339 |
+
'password': 'hvcTL3kN3pOG5KteT17T',
|
| 340 |
+
'host': 'staging-ourcoach.cx8se8o0iaiy.ap-southeast-1.rds.amazonaws.com',
|
| 341 |
+
'port': '5432'
|
| 342 |
+
}
|
| 343 |
+
try:
|
| 344 |
+
with psycopg2.connect(**db_params) as conn:
|
| 345 |
+
with conn.cursor() as cursor:
|
| 346 |
+
query = sql.SQL("SELECT mantra FROM {table} WHERE user_id = %s").format(table=sql.Identifier('public', 'user_growth_status'))
|
| 347 |
+
cursor.execute(query, (user_id,))
|
| 348 |
+
row = cursor.fetchone()
|
| 349 |
+
if (row):
|
| 350 |
+
colnames = [desc[0] for desc in cursor.description]
|
| 351 |
+
user_data = dict(zip(colnames, row))
|
| 352 |
+
### SAVE MANTRA IN USER OBJECT
|
| 353 |
+
self.mantra = user_data['mantra']
|
| 354 |
+
else:
|
| 355 |
+
logger.warning(f"No user info found for {user_id}", extra={'user_id': user_id, 'endpoint': "get_mantra"})
|
| 356 |
+
except psycopg2.Error as e:
|
| 357 |
+
logger.error(f"Database error while retrieving user info for {user_id}: {e}", extra={'user_id': user_id, 'endpoint': "get_mantra"})
|
| 358 |
+
raise DBError(user_id=user_id, message="Error retrieving user info", code="SQLError", e=str(e))
|
| 359 |
|
| 360 |
@catch_error
|
| 361 |
def set_goal(self, goal, goal_area, add=True, completed=False):
|
|
|
|
| 872 |
|
| 873 |
Today is day {self.cumulative_plan_day} of the user's growth journey (out of {final_day} days). You may (or may not) mention this occasionally in your first message of the day.
|
| 874 |
|
| 875 |
+
If today is a "Monday" or "Mon", you must include the user's Mantra of the Week : {self.mantra} to your first message of the day (include with today-theme's first message below)
|
| 876 |
+
|
| 877 |
Today's Theme:
|
| 878 |
{formatted_message}
|
| 879 |
"""
|
|
|
|
| 896 |
self.conversations.delete_hidden_messages()
|
| 897 |
# update the date in the state
|
| 898 |
self.conversations.state['date'] = date
|
| 899 |
+
# update mantra
|
| 900 |
+
self.set_mantra()
|
| 901 |
|
| 902 |
action = self.growth_plan.current()
|
| 903 |
|
app/utils.py
CHANGED
|
@@ -984,7 +984,8 @@ def get_user_life_status(user_id):
|
|
| 984 |
mantra = json.loads(response.choices[0].message.content)["mantra_of_the_week"]
|
| 985 |
|
| 986 |
# Update the users mantra
|
| 987 |
-
user.set_mantra(mantra)
|
|
|
|
| 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,
|
|
|
|
| 984 |
mantra = json.loads(response.choices[0].message.content)["mantra_of_the_week"]
|
| 985 |
|
| 986 |
# Update the users mantra
|
| 987 |
+
# user.set_mantra(mantra)
|
| 988 |
+
# We remove because we want the mantra to be updated weekly (by backend), not updated everytime we call this endpoint/func
|
| 989 |
|
| 990 |
cumulative_life_score = {
|
| 991 |
"overall": user.personal_growth_score + user.career_growth_score + user.relationship_score + user.mental_well_being_score + user.health_and_wellness_score,
|