Farid Karimli commited on
Commit
25e5db8
·
unverified ·
2 Parent(s): e868cef 0a47b7e

Merge pull request #6 from tools4ds/retargeting

Browse files
apps/ai_tutor/helpers.py CHANGED
@@ -19,9 +19,13 @@ async def check_user_cooldown(
19
  last_message_time_str = user_info["metadata"].get("last_message_time")
20
 
21
  # Convert from ISO format string to datetime object and ensure UTC timezone
22
- last_message_time = datetime.fromisoformat(last_message_time_str).replace(
23
- tzinfo=timezone.utc
24
- )
 
 
 
 
25
  current_time = datetime.fromisoformat(current_time).replace(tzinfo=timezone.utc)
26
 
27
  # Calculate the elapsed time
@@ -47,9 +51,13 @@ async def reset_tokens_for_user(user_info, TOKENS_LEFT, REGEN_TIME):
47
  user_info = convert_to_dict(user_info)
48
  last_message_time_str = user_info["metadata"].get("last_message_time")
49
 
50
- last_message_time = datetime.fromisoformat(last_message_time_str).replace(
51
- tzinfo=timezone.utc
52
- )
 
 
 
 
53
  current_time = datetime.fromisoformat(get_time()).replace(tzinfo=timezone.utc)
54
 
55
  # Calculate the elapsed time since the last message
 
19
  last_message_time_str = user_info["metadata"].get("last_message_time")
20
 
21
  # Convert from ISO format string to datetime object and ensure UTC timezone
22
+ try:
23
+ last_message_time = datetime.fromisoformat(last_message_time_str).replace(
24
+ tzinfo=timezone.utc
25
+ )
26
+ except Exception: # this probably means the user has never sent a message before
27
+ return False, None
28
+
29
  current_time = datetime.fromisoformat(current_time).replace(tzinfo=timezone.utc)
30
 
31
  # Calculate the elapsed time
 
51
  user_info = convert_to_dict(user_info)
52
  last_message_time_str = user_info["metadata"].get("last_message_time")
53
 
54
+ try:
55
+ last_message_time = datetime.fromisoformat(last_message_time_str).replace(
56
+ tzinfo=timezone.utc
57
+ )
58
+ except Exception: # this probably means the user has never sent a message before
59
+ last_message_time = datetime.min.replace(tzinfo=timezone.utc)
60
+
61
  current_time = datetime.fromisoformat(get_time()).replace(tzinfo=timezone.utc)
62
 
63
  # Calculate the elapsed time since the last message
apps/ai_tutor/templates/login.html CHANGED
@@ -114,7 +114,7 @@
114
  class="avatar"
115
  />
116
  <h1>Terrier Tutor</h1>
117
- <p>Welcome to the DS598 AI Tutor. Please sign in to continue.</p>
118
  <form action="/login/google" method="get">
119
  <button type="submit" class="button">Sign in with Google</button>
120
  </form>
 
114
  class="avatar"
115
  />
116
  <h1>Terrier Tutor</h1>
117
+ <p>Welcome to the DS701 AI Tutor. Please sign in to continue.</p>
118
  <form action="/login/google" method="get">
119
  <button type="submit" class="button">Sign in with Google</button>
120
  </form>