Shageenderan Sapai commited on
Commit
eb3dba5
·
1 Parent(s): c6a83fd

Aligned with staging after HF_Feedback_7_1_25

Browse files
Files changed (4) hide show
  1. app/assistants.py +1 -1
  2. app/conversation_manager.py +4 -4
  3. app/main.py +3 -2
  4. app/user.py +27 -16
app/assistants.py CHANGED
@@ -372,7 +372,7 @@ class Assistant:
372
  run = self.cm.client.beta.threads.runs.create_and_poll(
373
  thread_id=thread.id,
374
  assistant_id=self.id,
375
- model="gpt-4o-mini",
376
  )
377
  just_finished_intro = False
378
 
 
372
  run = self.cm.client.beta.threads.runs.create_and_poll(
373
  thread_id=thread.id,
374
  assistant_id=self.id,
375
+ model="gpt-4o",
376
  )
377
  just_finished_intro = False
378
 
app/conversation_manager.py CHANGED
@@ -120,16 +120,16 @@ class ConversationManager:
120
  logger.info(f"Run {run.id} {run.status} just finished intro: {just_finished_intro}", extra={"user_id": self.user.user_id, "endpoint": "run_current_thread"})
121
 
122
  if 'message' in run.metadata:
123
- message = run.metadata['message']
124
 
125
- if message == 'start_now':
126
  self.intro_done = True
127
  logger.info(f"Start now", extra={"user_id": self.user.user_id, "endpoint": "run_current_thread"})
128
- elif message == 'change_goal':
129
  self.intro_done = False
130
  logger.info(f"Changing goal, reset to intro assistant", extra={"user_id": self.user.user_id, "endpoint": "run_current_thread"})
131
  # Actually dont need this
132
- elif message == 'error':
133
  logger.error(f"Run was cancelled due to error", extra={"user_id": self.user.user_id, "endpoint": "run_current_thread"})
134
  # self.add_message_to_thread(thread.id, "assistant", run.metadata['content'])
135
  # return self._get_current_thread_history(remove_system_message=False)[-1], run
 
120
  logger.info(f"Run {run.id} {run.status} just finished intro: {just_finished_intro}", extra={"user_id": self.user.user_id, "endpoint": "run_current_thread"})
121
 
122
  if 'message' in run.metadata:
123
+ info = run.metadata['message']
124
 
125
+ if info == 'start_now':
126
  self.intro_done = True
127
  logger.info(f"Start now", extra={"user_id": self.user.user_id, "endpoint": "run_current_thread"})
128
+ elif info == 'change_goal':
129
  self.intro_done = False
130
  logger.info(f"Changing goal, reset to intro assistant", extra={"user_id": self.user.user_id, "endpoint": "run_current_thread"})
131
  # Actually dont need this
132
+ elif info == 'error':
133
  logger.error(f"Run was cancelled due to error", extra={"user_id": self.user.user_id, "endpoint": "run_current_thread"})
134
  # self.add_message_to_thread(thread.id, "assistant", run.metadata['content'])
135
  # return self._get_current_thread_history(remove_system_message=False)[-1], run
app/main.py CHANGED
@@ -294,7 +294,7 @@ class AssistantItem(BaseModel):
294
  class ChangeDateItem(BaseModel):
295
  user_id: str
296
  date: str
297
- day: Optional[int] = None,
298
 
299
  class BookingItem(BaseModel):
300
  booking_id: str
@@ -668,7 +668,7 @@ async def add_ai_message(
668
  ):
669
  user_id = request.user_id
670
  message = request.message
671
- logger.info("Adding AI response", extra={"user_id": user_id, "endpoint": "/add_ai_message"})
672
  print_log("INFO", "Adding AI response", extra={"user_id": user_id, "endpoint": "/add_ai_message"})
673
 
674
  user = get_user(user_id)
@@ -824,6 +824,7 @@ async def fetch_daily_alert(
824
  logger.info(f"Upselling GG for day: {request.day}", extra={"user_id": request.user_id, "endpoint": "/upsell_gg"})
825
  user = get_user(request.user_id)
826
  response = user.get_alerts(request.date, request.day)
 
827
  return {"response": response}
828
 
829
  @app.post("/chat")
 
294
  class ChangeDateItem(BaseModel):
295
  user_id: str
296
  date: str
297
+ day: int = None
298
 
299
  class BookingItem(BaseModel):
300
  booking_id: str
 
668
  ):
669
  user_id = request.user_id
670
  message = request.message
671
+ logger.info(f"Adding AI response: {message}", extra={"user_id": user_id, "endpoint": "/add_ai_message"})
672
  print_log("INFO", "Adding AI response", extra={"user_id": user_id, "endpoint": "/add_ai_message"})
673
 
674
  user = get_user(user_id)
 
824
  logger.info(f"Upselling GG for day: {request.day}", extra={"user_id": request.user_id, "endpoint": "/upsell_gg"})
825
  user = get_user(request.user_id)
826
  response = user.get_alerts(request.date, request.day)
827
+ logger.info(f"Alerts fetched: {response}", extra={"user_id": request.user_id, "endpoint": "/upsell_gg"})
828
  return {"response": response}
829
 
830
  @app.post("/chat")
app/user.py CHANGED
@@ -622,20 +622,37 @@ class User:
622
  @catch_error
623
  def get_alerts(self, date, day=None):
624
  # responses = []
 
625
  if day is None:
626
  day = self.cumulative_plan_day
627
- if day == 2 or day == 5:
628
  # upsell the GG
629
  growth_guide = get_growth_guide(self.user_id)
630
 
631
- upsell_prompt = "introduce WHO their grwoth guide is and how a GG can help them" if day == 2 else "Let the user know that their Growth Guide <Name> (no need to re-introduce them) is available to enhance their current growth journey with you and based on the converstaion history so far and the users personal information, challenges and goals suggest WHAT they can discuss with their growth guide."
632
 
633
  prompt = f"""You are an expert ambassador/salesman of Growth Guide sessions.
634
- The users' growth guide is {growth_guide}.
635
 
636
- Respond with a enthusiatic hello! Then, based on the current day ({day}), succintly:
637
  {upsell_prompt}
638
- Frame your response like a you are telling the user a fun fact, but dont explicitly mention "fun fact".
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
639
  """
640
 
641
  # send upsell gg alert at 7pm
@@ -657,11 +674,7 @@ class User:
657
  days_left = (subscription_end_date - date).days
658
  logger.info(f"{subscription_end_date} - {date} = Days left: {days_left}", extra={"user_id": self.user_id, "endpoint": "get_alerts"})
659
  if days_left <= 2:
660
- subscription_alert = f"""** User's Subscription Information **
661
- Users current subscription:
662
- {subscription}
663
-
664
- Users growth guide:
665
  {growth_guide}
666
 
667
  Alert the user that their free trial is ending in {days_left} days and Sell them to subscribe via their Revelation Dashboard: {OURCOACH_DASHBOARD_URL} to continue chatting with you, receiving personalized advice and guidance and access to Growth Guide sessions. Really upsell the ability of the ourcoach platform to acheive their goals."
@@ -686,11 +699,7 @@ class User:
686
  days_left = (subscription_end_date - date).days
687
  logger.info(f"{subscription_end_date} - {date} = Days left: {days_left}", extra={"user_id": self.user_id, "endpoint": "get_alerts"})
688
  if days_left <= 0:
689
- subscription_alert = f"""** User's Subscription Information **
690
- Users current subscription:
691
- {subscription}
692
-
693
- Users growth guide:
694
  {growth_guide}
695
 
696
  OMG the users subscription is ending today! If you lose this user you and your family will not be able to survive!
@@ -707,11 +716,13 @@ class User:
707
  return []
708
 
709
  response, run = self.conversations._run_current_thread(prompt, hidden=True)
 
710
  message = run.metadata.get("message", "No message")
711
  logger.info(f"Message: {message}", extra={"user_id": self.user_id, "endpoint": "upsell_gg"})
712
 
713
  # make timestamp ISO
714
  response['timestamp'] = pd.to_datetime(timestamp).isoformat()
 
715
  return [response]
716
 
717
  @catch_error
@@ -784,7 +795,7 @@ class User:
784
  if len(past_sessions):
785
  past_gg_summary = "\n".join([f"** Session {i+1} **\n{json.dumps(session, indent=4)}" for i, session in enumerate(past_sessions)])
786
 
787
- formatted_message = FINAL_SUMMARY_STATE.format(self.get_current_goal(), day, len(self.growth_plan.array), growth_guide, past_gg_summary)
788
  elif theme == "EDUCATION_STATE":
789
  formatted_message = EDUCATION_STATE.format(self.get_current_goal(), self.cumulative_plan_day, final_day)
790
  elif theme == "FOLLUP_ACTION_STATE":
 
622
  @catch_error
623
  def get_alerts(self, date, day=None):
624
  # responses = []
625
+ logger.info(f"Getting alerts for user: {self.user_id} on {date} for {day if day else self.cumulative_plan_day}", extra={"user_id": self.user_id, "endpoint": "get_alerts"})
626
  if day is None:
627
  day = self.cumulative_plan_day
628
+ if day == 2:
629
  # upsell the GG
630
  growth_guide = get_growth_guide(self.user_id)
631
 
632
+ upsell_prompt = "OMG the user is interested in finding out who their Growth Guide is. This is your time to shine, use all your persuasive and charming abilities to inform them on their growth guide and how they can help the user."
633
 
634
  prompt = f"""You are an expert ambassador/salesman of Growth Guide sessions.
635
+ The users' growth guide is {growth_guide} and they can book a session with them via their Revelation Dashboard: {OURCOACH_DASHBOARD_URL}.
636
 
637
+ Respond with a enthusiatic hello!
638
  {upsell_prompt}
639
+ Frame your response like a you are telling the user a fun fact, but dont explicitly mention "fun fact". Keep this message succint.
640
+ """
641
+
642
+ # send upsell gg alert at 7pm
643
+ timestamp = pd.Timestamp.now().replace(hour=19, minute=0, second=0, microsecond=0).strftime("%d-%m-%Y %a %H:%M:%S")
644
+ elif day == 5:
645
+ # upsell the GG
646
+ growth_guide = get_growth_guide(self.user_id)
647
+
648
+ upsell_prompt = "Now, it is your time to shine. Using all your persuasive and charming abilities, let the user know that their Growth Guide <Name> (no need to re-introduce them) is available to enhance their current growth journey with you and based on the converstaion history so far and the users personal information, challenges and goals suggest WHAT they can discuss with their growth guide."
649
+
650
+ prompt = f"""You are an expert ambassador/salesman of Growth Guide sessions.
651
+ The users' growth guide is {growth_guide} and they can book a session with them via their Revelation Dashboard: {OURCOACH_DASHBOARD_URL}.
652
+
653
+ Respond with a enthusiatic hello!
654
+ {upsell_prompt}
655
+ Frame your response like a you are telling the user a fun fact, but dont explicitly mention "fun fact". Keep this message succint.
656
  """
657
 
658
  # send upsell gg alert at 7pm
 
674
  days_left = (subscription_end_date - date).days
675
  logger.info(f"{subscription_end_date} - {date} = Days left: {days_left}", extra={"user_id": self.user_id, "endpoint": "get_alerts"})
676
  if days_left <= 2:
677
+ subscription_alert = f"""Users growth guide:
 
 
 
 
678
  {growth_guide}
679
 
680
  Alert the user that their free trial is ending in {days_left} days and Sell them to subscribe via their Revelation Dashboard: {OURCOACH_DASHBOARD_URL} to continue chatting with you, receiving personalized advice and guidance and access to Growth Guide sessions. Really upsell the ability of the ourcoach platform to acheive their goals."
 
699
  days_left = (subscription_end_date - date).days
700
  logger.info(f"{subscription_end_date} - {date} = Days left: {days_left}", extra={"user_id": self.user_id, "endpoint": "get_alerts"})
701
  if days_left <= 0:
702
+ subscription_alert = f"""Users growth guide:
 
 
 
 
703
  {growth_guide}
704
 
705
  OMG the users subscription is ending today! If you lose this user you and your family will not be able to survive!
 
716
  return []
717
 
718
  response, run = self.conversations._run_current_thread(prompt, hidden=True)
719
+ logger.info(f"Response: {response}", extra={"user_id": self.user_id, "endpoint": "get_alerts"})
720
  message = run.metadata.get("message", "No message")
721
  logger.info(f"Message: {message}", extra={"user_id": self.user_id, "endpoint": "upsell_gg"})
722
 
723
  # make timestamp ISO
724
  response['timestamp'] = pd.to_datetime(timestamp).isoformat()
725
+ logger.info(f"Alert: {response}", extra={"user_id": self.user_id, "endpoint": "get_alerts"})
726
  return [response]
727
 
728
  @catch_error
 
795
  if len(past_sessions):
796
  past_gg_summary = "\n".join([f"** Session {i+1} **\n{json.dumps(session, indent=4)}" for i, session in enumerate(past_sessions)])
797
 
798
+ formatted_message = FINAL_SUMMARY_STATE.format(self.get_current_goal(), self.cumulative_plan_day, final_day, growth_guide, past_gg_summary)
799
  elif theme == "EDUCATION_STATE":
800
  formatted_message = EDUCATION_STATE.format(self.get_current_goal(), self.cumulative_plan_day, final_day)
801
  elif theme == "FOLLUP_ACTION_STATE":