mominah commited on
Commit
eef2ed0
·
verified ·
1 Parent(s): ea407f6

Update routes.py

Browse files
Files changed (1) hide show
  1. routes.py +3 -32
routes.py CHANGED
@@ -1,4 +1,3 @@
1
- # routes.py
2
  import os
3
  import shutil
4
  import tempfile
@@ -10,43 +9,16 @@ from prompt_templates import PromptTemplates
10
 
11
  router = APIRouter()
12
 
13
- def select_prompt(prompt_type: str):
14
- """Selects a prompt template based on the provided prompt_type."""
15
- if prompt_type == "university":
16
- return PromptTemplates.get_university_chatbot_prompt()
17
- elif prompt_type == "quiz_solving":
18
- return PromptTemplates.get_quiz_solving_prompt()
19
- elif prompt_type == "assignment_solving":
20
- return PromptTemplates.get_assignment_solving_prompt()
21
- elif prompt_type == "paper_solving":
22
- return PromptTemplates.get_paper_solving_prompt()
23
- elif prompt_type == "quiz_creation":
24
- return PromptTemplates.get_quiz_creation_prompt()
25
- elif prompt_type == "assignment_creation":
26
- return PromptTemplates.get_assignment_creation_prompt()
27
- elif prompt_type == "paper_creation":
28
- return PromptTemplates.get_paper_creation_prompt()
29
- elif prompt_type == "check_quiz":
30
- return PromptTemplates.get_check_quiz_prompt()
31
- elif prompt_type == "check_assignment":
32
- return PromptTemplates.get_check_assignment_prompt()
33
- elif prompt_type == "check_paper":
34
- return PromptTemplates.get_check_paper_prompt()
35
- else:
36
- # Fallback to a default prompt if no matching type is found
37
- return PromptTemplates.get_quiz_solving_prompt()
38
-
39
  @router.post("/initialize_bot", response_model=InitializeBotResponse)
40
- def initialize_bot(prompt_type: str = "quiz_solving"):
41
  """
42
  Initializes a new bot with a custom prompt template.
43
- The prompt_type query parameter determines which prompt to use.
44
  """
45
  trainer = get_trainer()
46
  try:
47
  bot_id = trainer.initialize_bot_id()
48
- selected_prompt = select_prompt(prompt_type)
49
- trainer.set_custom_prompt_template(bot_id, selected_prompt)
50
  return InitializeBotResponse(bot_id=bot_id)
51
  except Exception as e:
52
  raise HTTPException(status_code=500, detail=str(e))
@@ -120,4 +92,3 @@ def chat_history(chat_id: str, bot_id: str):
120
  return jsonable_encoder(history, custom_encoder={ObjectId: str})
121
  except Exception as e:
122
  raise HTTPException(status_code=500, detail=str(e))
123
-
 
 
1
  import os
2
  import shutil
3
  import tempfile
 
9
 
10
  router = APIRouter()
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  @router.post("/initialize_bot", response_model=InitializeBotResponse)
13
+ def initialize_bot(custom_prompt: str):
14
  """
15
  Initializes a new bot with a custom prompt template.
16
+ The custom_prompt parameter should be provided (e.g., via navigation) and is used as the bot's prompt template.
17
  """
18
  trainer = get_trainer()
19
  try:
20
  bot_id = trainer.initialize_bot_id()
21
+ trainer.set_custom_prompt_template(bot_id, custom_prompt)
 
22
  return InitializeBotResponse(bot_id=bot_id)
23
  except Exception as e:
24
  raise HTTPException(status_code=500, detail=str(e))
 
92
  return jsonable_encoder(history, custom_encoder={ObjectId: str})
93
  except Exception as e:
94
  raise HTTPException(status_code=500, detail=str(e))