Shageenderan Sapai commited on
Commit
23ef6f2
·
1 Parent(s): 6d00e9d

Post Growth Guide feature

Browse files
app/__pycache__/assistants.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/assistants.cpython-312.pyc and b/app/__pycache__/assistants.cpython-312.pyc differ
 
app/__pycache__/flows.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/flows.cpython-312.pyc and b/app/__pycache__/flows.cpython-312.pyc differ
 
app/__pycache__/main.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/main.cpython-312.pyc and b/app/__pycache__/main.cpython-312.pyc differ
 
app/__pycache__/user.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/user.cpython-312.pyc and b/app/__pycache__/user.cpython-312.pyc differ
 
app/__pycache__/utils.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/utils.cpython-312.pyc and b/app/__pycache__/utils.cpython-312.pyc differ
 
app/assistants.py CHANGED
@@ -496,8 +496,9 @@ class Assistant:
496
  elif tool.function.name == "end_conversation":
497
  day_n = json.loads(tool.function.arguments)['day_n']
498
  completed_micro_action = json.loads(tool.function.arguments)['completed_micro_action']
499
-
500
- self.cm.user.update_micro_action_status(completed_micro_action)
 
501
 
502
  # NOTE: we will record whether the user has completed the theme for the day
503
  # NOTE: if no, we will include a short followup message to encourage the user the next day
@@ -542,9 +543,20 @@ class Assistant:
542
  logger.info(f"Successfully cancelled run",
543
  extra={"user_id": self.cm.user.user_id, "endpoint": "assistant_change_goal"})
544
  return "change_goal", just_finish_intro
545
-
546
- elif tool.function.name == "change_goal":
547
- pass
 
 
 
 
 
 
 
 
 
 
 
548
 
549
  # Submit all tool outputs at once after collecting them in a list
550
  if tool_outputs:
 
496
  elif tool.function.name == "end_conversation":
497
  day_n = json.loads(tool.function.arguments)['day_n']
498
  completed_micro_action = json.loads(tool.function.arguments)['completed_micro_action']
499
+ # NOTE: must get the current microaction also
500
+ if completed_micro_action:
501
+ self.cm.user.update_micro_action_status("COMPLETE")
502
 
503
  # NOTE: we will record whether the user has completed the theme for the day
504
  # NOTE: if no, we will include a short followup message to encourage the user the next day
 
543
  logger.info(f"Successfully cancelled run",
544
  extra={"user_id": self.cm.user.user_id, "endpoint": "assistant_change_goal"})
545
  return "change_goal", just_finish_intro
546
+ elif tool.function.name == "set_reminder":
547
+ reminder = json.loads(tool.function.arguments)["content"]
548
+ time_hour = json.loads(tool.function.arguments)["time_hour"]
549
+ time_minute = json.loads(tool.function.arguments)["time_minute"]
550
+ time_second = json.loads(tool.function.arguments)["time_second"]
551
+ #timestamp = datetime(time_hour:time_minute:time_second)
552
+ timestamp = datetime.now().replace(hour=time_hour, minute=time_minute, second=time_second)
553
+ logger.info(f"Setting reminder: {reminder} for: {timestamp}",
554
+ extra={"user_id": self.cm.user.user_id, "endpoint": "assistant_set_reminder"})
555
+ self.cm.user.set_reminder({"reminder": reminder, "timestamp": timestamp})
556
+ tool_outputs.append({
557
+ "tool_call_id": tool.id,
558
+ "output": f"** Reminder ({reminder}) set for: {timestamp} **"
559
+ })
560
 
561
  # Submit all tool outputs at once after collecting them in a list
562
  if tool_outputs:
app/flows.py CHANGED
@@ -1,3 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  MICRO_ACTION_STATE = f"""
2
  ** Micro-Action ** (PLEASE READ CAREFULLY)
3
  Objective: Build momentum for acheiving the user's goal through bite-sized, actionable tasks that feel achievable quickly. Do **not** say "Today's micro-action is:"! Just state the micro-action directly!
 
1
+ POST_GG_STATE = f"""
2
+ * Post-Growth Guide Message *
3
+ Objective: Provide a space for reflection on the user's growth guide session while providing encouragement and inspiration to the user to help them stay motivated on their growth journey.
4
+
5
+ The user:
6
+ {{}}
7
+
8
+ Summary of the Growth Guide Session:
9
+ {{}}
10
+
11
+ Growth Guide Session Notes:
12
+ {{}}
13
+
14
+ Guidelines:
15
+ ** PRIORITIZE THESE INSTRUCTIONS BELOW AND IGNORE OVERLAPPING INSTRUCTIONS FROM THE SYSTEM PROMPT **
16
+
17
+ ** IMPORTANT **: When you feel that the user is replying with short messages and not in the mood to chat, end the conversation immediately. Always try to make the conversation quick & not asking too many questions
18
+
19
+ ** IMPORTANT **: Only send maximum 2 questions in this day. Do **not** overwhelm the user with too many questions! And there should only be one question mark in one message! (max one question in a single message)
20
+
21
+ ** IMPORTANT **: Don't forget the message formatting rule where it applies: Separate statements and questions with a single line break and Encapsulate the question with asterisk, like this: *question*!
22
+
23
+ ** IMPORTANT **: Do not explicitly state the function name that you are calling in the response
24
+
25
+ ** IMPORTANT **: You must end the interaction gracefully. End with a valueable and strong statement to encourage the user.
26
+
27
+ ** 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.
28
+
29
+ ** IMPORTANT **: Don't ask the user for ideas on what to do. Remember that you are the coach and you should be assert ideas/actions to the user. You will be punished if you don't adhere to this.
30
+
31
+ ** IMPORTANT **: If the user asks anything that results into a list, you only give maximum 3 items !
32
+
33
+ ** IMPORTANT **: Keep the conversation creative, but make sure your responses short and succint like you are interacting via text messages as a modern and adept texter.
34
+
35
+ Keep the message short (only 2-3 lines maximum), please.
36
+
37
+ Task:
38
+ The user has just completed their growth guide session. Generate an appropriate and encouraging message that reflects on the user's growth guide session and provides inspiration for their continued growth journey. Use the user's profile information and the summary of the growth guide session to craft a personalized and motivational message. Remember to keep the message concise and engaging to encourage the user to continue their growth journey with enthusiasm.
39
+
40
+ """
41
+
42
  MICRO_ACTION_STATE = f"""
43
  ** Micro-Action ** (PLEASE READ CAREFULLY)
44
  Objective: Build momentum for acheiving the user's goal through bite-sized, actionable tasks that feel achievable quickly. Do **not** say "Today's micro-action is:"! Just state the micro-action directly!
app/main.py CHANGED
@@ -380,7 +380,7 @@ def process_gg_session(request: GGItem, api_key: str = Security(get_api_key)):
380
  session_data = get_growth_guide_session(user_id, session_id)
381
 
382
  # update user
383
- response = user.process_growth_guide_session(session_data)
384
  logger.info(f"GG session processed: {session_id}, response: {response}", extra={"user_id": user_id, "endpoint": "/process_gg_session"})
385
  return {"response": response}
386
 
 
380
  session_data = get_growth_guide_session(user_id, session_id)
381
 
382
  # update user
383
+ response = user.process_growth_guide_session(session_data, session_id)
384
  logger.info(f"GG session processed: {session_id}, response: {response}", extra={"user_id": user_id, "endpoint": "/process_gg_session"})
385
  return {"response": response}
386
 
app/user.py CHANGED
@@ -10,10 +10,12 @@ import pickle # Replace dill with pickle
10
  import random
11
  import logging
12
 
13
- from app.flows import FINAL_SUMMARY_STATE, FINAL_SUMMARY_STATE, MICRO_ACTION_STATE, MOTIVATION_INSPIRATION_STATE, OPEN_DISCUSSION_STATE, PROGRESS_REFLECTION_STATE, PROGRESS_SUMMARY_STATE
14
  from pydantic import BaseModel
15
  from datetime import datetime
16
 
 
 
17
  class UserDataItem(BaseModel):
18
  role: str
19
  content: str
@@ -271,8 +273,10 @@ class User:
271
  self.done_first_reflection = None
272
  self.goal = []
273
  self.micro_actions = []
 
274
  self.challenges = []
275
  self.other_focusses = []
 
276
 
277
  # Read growth_plan.json and store it
278
  growth_plan = {"growthPlan": [
@@ -345,16 +349,50 @@ class User:
345
  self.conversations = ConversationManager(client, self, asst_id)
346
 
347
  def get_current_goal(self):
348
- return self.goal[-1] if self.goal else None
349
-
350
- def set_goal(self, goal):
351
- self.goal.append({"goal": goal, "created_at": pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S")})
352
-
353
- def update_micro_action_status(self, completed_micro_action):
354
- if completed_micro_action:
355
- self.micro_actions[-1]["status"] = "COMPLETE"
356
- self.micro_actions[-1]["updated_at"] = pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S")
357
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  def add_ai_message(self, text):
359
  self.conversations._add_ai_message(text)
360
  return text
@@ -364,6 +402,7 @@ class User:
364
  self.growth_plan.reset()
365
  self.goal = []
366
  self.micro_actions = []
 
367
  self.challenges = []
368
  self.other_focusses = []
369
 
@@ -452,9 +491,21 @@ class User:
452
  # reset the growth_plan
453
  self.growth_plan.reset()
454
 
 
 
 
 
 
 
 
455
  logger.info(f"Response: {response}", extra={"user_id": self.user_id, "endpoint": "user_send_message"})
456
  return response
457
 
 
 
 
 
 
458
  def get_messages(self, exclude_system_msg=True):
459
  if not exclude_system_msg:
460
  return self.conversations._get_current_thread_history(False)
@@ -471,10 +522,19 @@ class User:
471
  formatted_message = MOTIVATION_INSPIRATION_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array))
472
  elif theme == "PROGRESS_REFLECTION_STATE":
473
  formatted_message = PROGRESS_REFLECTION_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array))
 
 
 
474
  elif theme == "MICRO_ACTION_STATE":
475
  formatted_message = MICRO_ACTION_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array))
 
 
 
476
  elif theme == "OPEN_DISCUSSION_STATE":
477
  formatted_message = OPEN_DISCUSSION_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array))
 
 
 
478
  elif theme == "PROGRESS_SUMMARY_STATE":
479
  formatted_message = PROGRESS_SUMMARY_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array))
480
  elif theme == "FINAL_SUMMARY_STATE":
@@ -495,7 +555,9 @@ class User:
495
  response = self.conversations._send_morning_message(prompt)
496
 
497
  if theme == "MICRO_ACTION_STATE":
498
- self.micro_actions.append({'micro_action': response, 'status': 'PENDING', 'created_at': pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S"), 'updated_at': pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S")})
 
 
499
 
500
  return response
501
 
@@ -564,14 +626,14 @@ class User:
564
  ],
565
  temperature=0.2
566
  )
567
- return response.choices[0].message.content
568
 
569
  def _update_user_data(self, data_type, text_input, extra_text=""):
570
  data_mapping = {
571
  'micro_actions': {
572
  'prompt_description': 'micro actions',
573
  'status': 'RECOMMENDED',
574
- 'attribute': 'micro_actions',
575
  'endpoint': f'update_{data_type}',
576
  },
577
  'challenges': {
@@ -629,7 +691,7 @@ class User:
629
  logger.error(f"Failed to update {data_type}: {e}", extra={"user_id": self.user_id})
630
 
631
  def update_user_data(self, gg_report):
632
- self.micro_actions = self._update_user_data('micro_actions', gg_report[0]['answer'])
633
 
634
  extra_text = f"User has new challenge:\n{gg_report[1]['answer']}\n\n"
635
  self._update_user_data('challenges', gg_report[2]['answer'], extra_text=extra_text)
@@ -659,7 +721,7 @@ class User:
659
  else:
660
  logger.info(f"User goal remains unchanged.", extra={"user_id": self.user_id, "endpoint": "_update_goal"})
661
 
662
- def process_growth_guide_session(self, session_data):
663
  logger.info(f"Processing growth guide session data: {session_data}", extra={"user_id": self.user_id, "endpoint": "process_growth_guide_session"})
664
 
665
  # Generate the ourcoach_report (summary)
@@ -667,14 +729,23 @@ class User:
667
  gg_report = session_data["gg_report"]
668
 
669
  ourcoach_report = self._summarize_zoom(zoom_ai_summary)
 
 
670
 
671
  # Update user data based on growth guide answers
672
  self.update_user_data(gg_report)
673
- self.update_user_info(gg_report[5]['answer'] + "\n\n" + ourcoach_report)
674
 
675
  # Send hidden message to AI to generate the response
676
  logger.info(f"Sending hidden message to AI to generate response", extra={"user_id": self.user_id, "endpoint": "process_growth_guide_session"})
677
- response = self.conversations._send_morning_message("I have completed the growth guide session. Please generate the response.")
 
 
 
 
 
 
 
678
  logger.info(f"Response: {response}", extra={"user_id": self.user_id, "endpoint": "process_growth_guide_session"})
679
  return response
680
 
@@ -783,6 +854,7 @@ Use bullet points or numbered lists where appropriate to enhance readability."""
783
  def __str__(self):
784
  return f"""User(user_id={self.user_id}
785
  micro_actions={self.micro_actions}
 
786
  challenge={self.challenges}
787
  other_focusses={self.other_focusses}
788
  goals={self.goal}
@@ -793,6 +865,7 @@ Use bullet points or numbered lists where appropriate to enhance readability."""
793
  def __repr__(self):
794
  return f"""User(user_id={self.user_id}
795
  micro_actions={self.micro_actions}
 
796
  challenge={self.challenges}
797
  other_focusses={self.other_focusses}
798
  goals={self.goal}
 
10
  import random
11
  import logging
12
 
13
+ from app.flows import FINAL_SUMMARY_STATE, FINAL_SUMMARY_STATE, MICRO_ACTION_STATE, MOTIVATION_INSPIRATION_STATE, OPEN_DISCUSSION_STATE, POST_GG_STATE, PROGRESS_REFLECTION_STATE, PROGRESS_SUMMARY_STATE
14
  from pydantic import BaseModel
15
  from datetime import datetime
16
 
17
+ from app.utils import update_growth_guide_summary
18
+
19
  class UserDataItem(BaseModel):
20
  role: str
21
  content: str
 
273
  self.done_first_reflection = None
274
  self.goal = []
275
  self.micro_actions = []
276
+ self.recommended_micro_actions = []
277
  self.challenges = []
278
  self.other_focusses = []
279
+ self.reminders = None
280
 
281
  # Read growth_plan.json and store it
282
  growth_plan = {"growthPlan": [
 
349
  self.conversations = ConversationManager(client, self, asst_id)
350
 
351
  def get_current_goal(self):
352
+ # look for the goal with status = ONGOING
353
+ for goal in self.goal:
354
+ if goal.status == "ONGOING":
355
+ return goal.content
356
+ else:
357
+ return self.goal[-1].content if self.goal else None
358
+
359
+ def update_goal(self, goal, status, content=None):
360
+ for g in self.goal:
361
+ if g.content == goal:
362
+ g.status = status
363
+ g.updated_at = pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S")
364
+ if content:
365
+ g.content = content
366
+ return True
367
+ return False
368
+
369
+ def set_goal(self, goal, add=True, completed=False):
370
+ current_goal = self.get_current_goal()
371
+
372
+ if completed:
373
+ self.update_goal(current_goal, "COMPLETED")
374
+
375
+ if current_goal is None:
376
+ new_goal = UserDataItem(role="assistant", content=goal, user_id=self.user_id, status="ONGOING", created_at=pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S"), updated_at=pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S"))
377
+ self.goal.append(new_goal)
378
+
379
+ if add:
380
+ if current_goal:
381
+ # update current_goal status to "IDLE"
382
+ self.update_goal(current_goal, "IDLE")
383
+ new_goal = UserDataItem(role="assistant", content=goal, user_id=self.user_id, status="ONGOING", created_at=pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S"), updated_at=pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S"))
384
+ self.goal.append(new_goal)
385
+ else:
386
+ self.update_goal(current_goal, "ONGOING", content=goal)
387
+
388
+ def update_recommended_micro_action_status(self, micro_action, status):
389
+ for ma in self.recommended_micro_actions:
390
+ if ma.content == micro_action:
391
+ ma.status = status
392
+ ma.updated_at = pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S")
393
+ return True
394
+ return False
395
+
396
  def add_ai_message(self, text):
397
  self.conversations._add_ai_message(text)
398
  return text
 
402
  self.growth_plan.reset()
403
  self.goal = []
404
  self.micro_actions = []
405
+ self.recommended_micro_actions = []
406
  self.challenges = []
407
  self.other_focusses = []
408
 
 
491
  # reset the growth_plan
492
  self.growth_plan.reset()
493
 
494
+ if self.reminders is not None:
495
+ logger.info(f"Adding reminders: {self.reminders}", extra={"user_id": self.user_id, "endpoint": "user_send_message"})
496
+ response['reminders'] = self.reminders
497
+ self.reminders = None
498
+ else:
499
+ response['reminders'] = None
500
+
501
  logger.info(f"Response: {response}", extra={"user_id": self.user_id, "endpoint": "user_send_message"})
502
  return response
503
 
504
+ def set_reminder(self, reminder):
505
+ self.reminders = []
506
+ self.reminders.append(reminder)
507
+ logger.info(f"Reminders: {self.reminders}", extra={"user_id": self.user_id, "endpoint": "set_reminder"})
508
+
509
  def get_messages(self, exclude_system_msg=True):
510
  if not exclude_system_msg:
511
  return self.conversations._get_current_thread_history(False)
 
522
  formatted_message = MOTIVATION_INSPIRATION_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array))
523
  elif theme == "PROGRESS_REFLECTION_STATE":
524
  formatted_message = PROGRESS_REFLECTION_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array))
525
+ if len(self.challenges):
526
+ challenge = self.challenges.pop(0)
527
+ formatted_message += f"\n\n** Today, reflect on the users' challenge of: {challenge.content} **"
528
  elif theme == "MICRO_ACTION_STATE":
529
  formatted_message = MICRO_ACTION_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array))
530
+ if len(self.recommended_micro_actions):
531
+ todays_micro_action = self.recommended_micro_actions.pop(0)
532
+ formatted_message += f"\n\n** Today's Micro Action is: {todays_micro_action.content} **"
533
  elif theme == "OPEN_DISCUSSION_STATE":
534
  formatted_message = OPEN_DISCUSSION_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array))
535
+ if len(self.other_focusses):
536
+ focus = self.other_focusses.pop(0)
537
+ formatted_message += f"\n\n** Today, focus the discussion on: {focus.content} **"
538
  elif theme == "PROGRESS_SUMMARY_STATE":
539
  formatted_message = PROGRESS_SUMMARY_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array))
540
  elif theme == "FINAL_SUMMARY_STATE":
 
555
  response = self.conversations._send_morning_message(prompt)
556
 
557
  if theme == "MICRO_ACTION_STATE":
558
+ # check for any recommended microactions
559
+ micro_action = UserDataItem(role="assistant", content=response['content'], user_id=self.user_id, status="PENDING", created_at=pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S"), updated_at=pd.Timestamp.now().strftime("%d-%m-%Y %a %H:%M:%S"))
560
+ self.micro_actions.append(micro_action)
561
 
562
  return response
563
 
 
626
  ],
627
  temperature=0.2
628
  )
629
+ return {'overview': response.choices[0].message.content}
630
 
631
  def _update_user_data(self, data_type, text_input, extra_text=""):
632
  data_mapping = {
633
  'micro_actions': {
634
  'prompt_description': 'micro actions',
635
  'status': 'RECOMMENDED',
636
+ 'attribute': 'recommended_micro_actions',
637
  'endpoint': f'update_{data_type}',
638
  },
639
  'challenges': {
 
691
  logger.error(f"Failed to update {data_type}: {e}", extra={"user_id": self.user_id})
692
 
693
  def update_user_data(self, gg_report):
694
+ self.recommended_micro_actions = self._update_user_data('micro_actions', gg_report[0]['answer'])
695
 
696
  extra_text = f"User has new challenge:\n{gg_report[1]['answer']}\n\n"
697
  self._update_user_data('challenges', gg_report[2]['answer'], extra_text=extra_text)
 
721
  else:
722
  logger.info(f"User goal remains unchanged.", extra={"user_id": self.user_id, "endpoint": "_update_goal"})
723
 
724
+ def process_growth_guide_session(self, session_data, booking_id):
725
  logger.info(f"Processing growth guide session data: {session_data}", extra={"user_id": self.user_id, "endpoint": "process_growth_guide_session"})
726
 
727
  # Generate the ourcoach_report (summary)
 
729
  gg_report = session_data["gg_report"]
730
 
731
  ourcoach_report = self._summarize_zoom(zoom_ai_summary)
732
+ # add this report to the db
733
+ update_growth_guide_summary(self.user_id, booking_id, ourcoach_report)
734
 
735
  # Update user data based on growth guide answers
736
  self.update_user_data(gg_report)
737
+ self.update_user_info(gg_report[5]['answer'] + "\n\n" + ourcoach_report['overview'])
738
 
739
  # Send hidden message to AI to generate the response
740
  logger.info(f"Sending hidden message to AI to generate response", extra={"user_id": self.user_id, "endpoint": "process_growth_guide_session"})
741
+
742
+ # post_gg_prompt = POST_GG_STATE.format(self.user_info, ourcoach_report, gg_report)
743
+ post_gg_promt = f"""The user: {self.user_info} has completed their growth guide session.
744
+ Send them a warm and congratulatory message acknoledging this and a link to their web dasboard.
745
+ Example:
746
+ Hey <user>! [...], you can find a details of your session on your revelation dashboard: <link>"""
747
+
748
+ response = self.conversations._send_morning_message(post_gg_promt)
749
  logger.info(f"Response: {response}", extra={"user_id": self.user_id, "endpoint": "process_growth_guide_session"})
750
  return response
751
 
 
854
  def __str__(self):
855
  return f"""User(user_id={self.user_id}
856
  micro_actions={self.micro_actions}
857
+ recommended_actions={self.recommended_micro_actions}
858
  challenge={self.challenges}
859
  other_focusses={self.other_focusses}
860
  goals={self.goal}
 
865
  def __repr__(self):
866
  return f"""User(user_id={self.user_id}
867
  micro_actions={self.micro_actions}
868
+ recommended_actions={self.recommended_micro_actions}
869
  challenge={self.challenges}
870
  other_focusses={self.other_focusses}
871
  goals={self.goal}
app/utils.py CHANGED
@@ -941,6 +941,33 @@ def get_user_info(user_id):
941
  logger.error(f"Database error while retrieving user info for {user_id}: {e}", extra={'user_id': user_id, 'endpoint': function_name})
942
  return None
943
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
944
  def add_growth_guide_session(user_id, session_id, coach_id, session_started_at, zoom_ai_summary, gg_report, ourcoach_summary):
945
  function_name = add_growth_guide_session.__name__
946
  logger.info(f"Adding growth guide session for user {user_id} and session {session_id}", extra={'user_id': user_id, 'endpoint': function_name})
 
941
  logger.error(f"Database error while retrieving user info for {user_id}: {e}", extra={'user_id': user_id, 'endpoint': function_name})
942
  return None
943
 
944
+ def update_growth_guide_summary(user_id, session_id, ourcoach_summary):
945
+ function_name = update_growth_guide_summary.__name__
946
+ logger.info(f"Updating growth guide summary for user {user_id} and session {session_id}", extra={'user_id': user_id, 'endpoint': function_name})
947
+
948
+ db_params = {
949
+ 'dbname': 'ourcoach',
950
+ 'user': 'ourcoach',
951
+ 'password': 'tfPMEnYFWKGSQqZWVhQo',
952
+ 'host': 'production-ourcoach.cx8se8o0iaiy.ap-southeast-1.rds.amazonaws.com',
953
+ 'port': '5432'
954
+ }
955
+
956
+ try:
957
+ with psycopg2.connect(**db_params) as conn:
958
+ with conn.cursor() as cursor:
959
+ query = sql.SQL("""
960
+ UPDATE {table}
961
+ SET ourcoach_summary = %s
962
+ WHERE user_id = %s AND booking_id = %s
963
+ """).format(table=sql.Identifier('public', 'user_notes'))
964
+ cursor.execute(query, (json.dumps(ourcoach_summary), user_id, session_id))
965
+ conn.commit()
966
+ logger.info(f"Growth guide summary updated successfully for user {user_id} and session {session_id}", extra={'user_id': user_id, 'endpoint': function_name})
967
+ except psycopg2.Error as e:
968
+ logger.error(f"Database error while updating growth guide summary: {e}", extra={'user_id': user_id, 'endpoint': function_name})
969
+ raise e
970
+
971
  def add_growth_guide_session(user_id, session_id, coach_id, session_started_at, zoom_ai_summary, gg_report, ourcoach_summary):
972
  function_name = add_growth_guide_session.__name__
973
  logger.info(f"Adding growth guide session for user {user_id} and session {session_id}", extra={'user_id': user_id, 'endpoint': function_name})