XThomasBU commited on
Commit
2e04bc3
2 Parent(s): 1c84147 4d2326b

Merge pull request #9 from tools4ds/retargeting

Browse files
apps/ai_tutor/app.py CHANGED
@@ -277,6 +277,10 @@ async def post_signin(request: Request):
277
  user_details.metadata["tokens_left"] = (
278
  TOKENS_LEFT # set the number of tokens left for the new user
279
  )
 
 
 
 
280
  if "last_message_time" not in user_details.metadata:
281
  user_details.metadata["last_message_time"] = current_datetime
282
  if "all_time_tokens_allocated" not in user_details.metadata:
@@ -389,7 +393,7 @@ mount_chainlit(app=app, target="chainlit_app.py", path=CHAINLIT_PATH)
389
 
390
  if __name__ == "__main__":
391
  parser = argparse.ArgumentParser(description="Run the AI Tutor application")
392
- parser.add_argument("--host", default="0.0.0.0", help="Host to run the server on")
393
  parser.add_argument(
394
  "--port", type=int, default=7860, help="Port to run the server on"
395
  )
 
277
  user_details.metadata["tokens_left"] = (
278
  TOKENS_LEFT # set the number of tokens left for the new user
279
  )
280
+ if "role" not in user_details.metadata:
281
+ user_details.metadata["role"] = get_user_role(user_info["email"])
282
+ if "tokens_left" not in user_details.metadata:
283
+ user_details.metadata["tokens_left"] = TOKENS_LEFT
284
  if "last_message_time" not in user_details.metadata:
285
  user_details.metadata["last_message_time"] = current_datetime
286
  if "all_time_tokens_allocated" not in user_details.metadata:
 
393
 
394
  if __name__ == "__main__":
395
  parser = argparse.ArgumentParser(description="Run the AI Tutor application")
396
+ parser.add_argument("--host", default="localhost", help="Host to run the server on")
397
  parser.add_argument(
398
  "--port", type=int, default=7860, help="Port to run the server on"
399
  )
apps/ai_tutor/chainlit_app.py CHANGED
@@ -227,38 +227,28 @@ class Chatbot:
227
  """
228
  Set starter messages for the chatbot.
229
  """
230
- # Return Starters only if the chat is new
231
-
232
- try:
233
- thread = cl_data._data_layer.get_thread(
234
- cl.context.session.thread_id
235
- ) # see if the thread has any steps
236
- if thread.steps or len(thread.steps) > 0:
237
- return None
238
- except Exception as e:
239
- print(e)
240
- return [
241
- cl.Starter(
242
- label="What is this course about?",
243
- message="What is this course about? I'm not sure I'm in the right class.",
244
- icon="/public/assets/images/starter_icons/adv-screen-recorder-svgrepo-com.svg",
245
- ),
246
- cl.Starter(
247
- label="Where is the schedule?",
248
- message="When are the lectures? I can't find the schedule.",
249
- icon="/public/assets/images/starter_icons/alarmy-svgrepo-com.svg",
250
- ),
251
- cl.Starter(
252
- label="When are office hours?",
253
- message="When are the office hours for this course?",
254
- icon="/public/assets/images/starter_icons/calendar-samsung-17-svgrepo-com.svg",
255
- ),
256
- cl.Starter(
257
- label="Explain KMeans",
258
- message="I didn't understand the math behind KMeans, could you explain it?",
259
- icon="/public/assets/images/starter_icons/acastusphoton-svgrepo-com.svg",
260
- ),
261
- ]
262
 
263
  def rename(self, orig_author: str):
264
  """
@@ -505,7 +495,7 @@ class Chatbot:
505
  await self.start()
506
 
507
  @cl.header_auth_callback
508
- def header_auth_callback(headers: dict) -> Optional[cl.User]:
509
  # try: # TODO: Add try-except block after testing
510
  # TODO: Implement to get the user information from the headers (not the cookie)
511
  cookie = headers.get("cookie") # gets back a str
@@ -521,10 +511,14 @@ class Chatbot:
521
  ).decode()
522
  decoded_user_info = json.loads(decoded_user_info)
523
 
 
 
 
 
524
  return cl.User(
525
  id=decoded_user_info["literalai_info"]["id"],
526
  identifier=decoded_user_info["literalai_info"]["identifier"],
527
- metadata=decoded_user_info["literalai_info"]["metadata"],
528
  )
529
 
530
  async def on_follow_up(self, action: cl.Action):
 
227
  """
228
  Set starter messages for the chatbot.
229
  """
230
+ return [
231
+ cl.Starter(
232
+ label="What is this course about?",
233
+ message="What is this course about? I'm not sure I'm in the right class.",
234
+ icon="/public/assets/images/starter_icons/adv-screen-recorder-svgrepo-com.svg",
235
+ ),
236
+ cl.Starter(
237
+ label="Where is the schedule?",
238
+ message="When are the lectures? I can't find the schedule.",
239
+ icon="/public/assets/images/starter_icons/alarmy-svgrepo-com.svg",
240
+ ),
241
+ cl.Starter(
242
+ label="When are office hours?",
243
+ message="When are the office hours for this course?",
244
+ icon="/public/assets/images/starter_icons/calendar-samsung-17-svgrepo-com.svg",
245
+ ),
246
+ cl.Starter(
247
+ label="Explain KMeans",
248
+ message="I didn't understand the math behind KMeans, could you explain it?",
249
+ icon="/public/assets/images/starter_icons/acastusphoton-svgrepo-com.svg",
250
+ ),
251
+ ]
 
 
 
 
 
 
 
 
 
 
252
 
253
  def rename(self, orig_author: str):
254
  """
 
495
  await self.start()
496
 
497
  @cl.header_auth_callback
498
+ async def header_auth_callback(headers: dict) -> Optional[cl.User]:
499
  # try: # TODO: Add try-except block after testing
500
  # TODO: Implement to get the user information from the headers (not the cookie)
501
  cookie = headers.get("cookie") # gets back a str
 
511
  ).decode()
512
  decoded_user_info = json.loads(decoded_user_info)
513
 
514
+ user_id = decoded_user_info["literalai_info"]["identifier"]
515
+ user_info = await get_user_details(user_id)
516
+ metadata = user_info.metadata
517
+
518
  return cl.User(
519
  id=decoded_user_info["literalai_info"]["id"],
520
  identifier=decoded_user_info["literalai_info"]["identifier"],
521
+ metadata=metadata,
522
  )
523
 
524
  async def on_follow_up(self, action: cl.Action):
apps/ai_tutor/templates/dashboard.html CHANGED
@@ -148,7 +148,6 @@
148
  </div>
149
  <script>
150
  let token = "{{ jwt_token }}";
151
- console.log("Token: ", token);
152
  localStorage.setItem("token", token);
153
  </script>
154
  </body>
 
148
  </div>
149
  <script>
150
  let token = "{{ jwt_token }}";
 
151
  localStorage.setItem("token", token);
152
  </script>
153
  </body>