Ajey95 commited on
Commit
fcd9088
Β·
1 Parent(s): b8c4827

Fix: chat_history addition

Browse files
agents/drug_info_agent.py CHANGED
@@ -31,69 +31,103 @@ class DrugInfoAgent:
31
 
32
  # Clean up any extra whitespace
33
  return drug_name.strip().title() # Capitalize for better recognition
34
-
35
  def process_query(self, query: str, file_context: str = "", chat_history: list = None):
36
- """
37
- Processes a query to retrieve information about a specific drug.
38
-
39
- Args:
40
- query (str): The user's full query (e.g., "Tell me about Metformin").
41
- file_context (str): Optional context from uploaded files.
42
-
43
- Returns:
44
- dict: A dictionary containing the response message and agent metadata.
45
- """
46
- # Fallback response if the AI model is not configured
47
  if not self.model:
48
  return {
49
- 'message': "πŸ’Š **Drug Information Agent**\n\nThe pharmacy database is offline! The Gemini API key is missing, so I can't look up drug information. Please configure the API key to enable this feature.",
50
- 'agent_type': 'drug_info',
51
- 'status': 'error_no_api_key'
52
  }
53
 
54
  drug_name = self._extract_drug_name(query)
55
- if not drug_name:
56
- return {
57
- 'message': "Please tell me which drug you want to know about! For example, try 'info on Paracetamol'.",
58
- 'agent_type': 'drug_info',
59
- 'status': 'error_no_topic'
60
- }
61
-
62
- # Construct a specialized, safety-conscious prompt for the Gemini model
63
- prompt = f"""
64
- You are a highly knowledgeable and cautious AI Pharmacist Tutor. Your primary role is to provide accurate drug information for a B.Pharmacy student in India for EDUCATIONAL PURPOSES ONLY.
65
 
66
- **CRITICAL SAFETY INSTRUCTION:**
67
- START EVERY RESPONSE with the following disclaimer, exactly as written:
68
- "⚠️ **Disclaimer:** This information is for educational purposes ONLY and is not a substitute for professional medical advice. Always consult a qualified healthcare provider."
69
 
70
- **Task:**
71
- Provide a structured summary for the drug: **{drug_name}**
72
 
73
- **Information to Include:**
74
- 1. **Therapeutic Class:** What family of drugs does it belong to?
75
- 2. **Mechanism of Action (MOA):** How does it work in the body? Explain simply.
76
- 3. **Common Indications:** What is it typically used for?
77
- 4. **Common Side Effects:** List a few of the most common side effects.
78
- 5. **Important Contraindications/Warnings:** Who should not take this drug or be cautious?
79
- 6. **Common Dosage Forms:** What forms is it available in (e.g., Tablets, Syrup, Injection)? DO NOT provide specific dosages like mg or frequency.
80
 
81
- **Format:**
82
- Use clear headings (like "πŸ”¬ Mechanism of Action") and bullet points for readability. Use relevant emojis.
83
  """
84
-
85
  try:
86
- # Generate content using the AI model
87
- ai_response = self.model.generate_content(prompt, chat_history)
88
- return {
89
- 'message': ai_response.text,
90
- 'agent_used': 'drug_info',
91
- 'status': 'success'
92
- }
93
  except Exception as e:
94
  print(f"Drug Info Agent Error: {e}")
95
- return {
96
- 'message': f"I'm sorry, I couldn't access the drug database at the moment. An error occurred: {str(e)}",
97
- 'agent_type': 'drug_info',
98
- 'status': 'error_api_call'
99
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  # Clean up any extra whitespace
33
  return drug_name.strip().title() # Capitalize for better recognition
 
34
  def process_query(self, query: str, file_context: str = "", chat_history: list = None):
 
 
 
 
 
 
 
 
 
 
 
35
  if not self.model:
36
  return {
37
+ 'message': "πŸ’Š The pharmacy database is offline! The Gemini API key is missing.",
38
+ 'agent_used': 'drug_info', 'status': 'error_no_api_key'
 
39
  }
40
 
41
  drug_name = self._extract_drug_name(query)
42
+
43
+ history_for_prompt = ""
44
+ if chat_history:
45
+ for turn in chat_history:
46
+ role = "User" if turn['role'] == 'user' else "AI"
47
+ if turn.get('parts'):
48
+ history_for_prompt += f"{role}: {turn['parts'][0]}\n"
 
 
 
49
 
50
+ prompt = f"""You are a cautious AI Pharmacist Tutor providing educational information for a B.Pharmacy student.
 
 
51
 
52
+ **CRITICAL SAFETY INSTRUCTION:** START EVERY RESPONSE with this disclaimer: "⚠️ **Disclaimer:** This information is for educational purposes ONLY and is not a substitute for professional medical advice."
 
53
 
54
+ CONVERSATION HISTORY:
55
+ {history_for_prompt}
56
+ CURRENT QUESTION:
57
+ User: {query}
 
 
 
58
 
59
+ Based on the CURRENT QUESTION and conversation history, provide a structured summary for the drug mentioned. Include: Therapeutic Class, Mechanism of Action (MOA), Common Indications, Common Side Effects, and Important Warnings. DO NOT provide specific dosages.
 
60
  """
 
61
  try:
62
+ response = self.model.generate_content(prompt)
63
+ return {'message': response.text, 'agent_used': 'drug_info', 'status': 'success'}
 
 
 
 
 
64
  except Exception as e:
65
  print(f"Drug Info Agent Error: {e}")
66
+ return {'message': f"Sorry, I couldn't access the drug database. Error: {e}", 'agent_used': 'drug_info', 'status': 'error_api_call'}
67
+
68
+
69
+ # def process_query(self, query: str, file_context: str = "", chat_history: list = None):
70
+ # """
71
+ # Processes a query to retrieve information about a specific drug.
72
+
73
+ # Args:
74
+ # query (str): The user's full query (e.g., "Tell me about Metformin").
75
+ # file_context (str): Optional context from uploaded files.
76
+
77
+ # Returns:
78
+ # dict: A dictionary containing the response message and agent metadata.
79
+ # """
80
+ # # Fallback response if the AI model is not configured
81
+ # if not self.model:
82
+ # return {
83
+ # 'message': "πŸ’Š **Drug Information Agent**\n\nThe pharmacy database is offline! The Gemini API key is missing, so I can't look up drug information. Please configure the API key to enable this feature.",
84
+ # 'agent_type': 'drug_info',
85
+ # 'status': 'error_no_api_key'
86
+ # }
87
+
88
+ # drug_name = self._extract_drug_name(query)
89
+ # if not drug_name:
90
+ # return {
91
+ # 'message': "Please tell me which drug you want to know about! For example, try 'info on Paracetamol'.",
92
+ # 'agent_type': 'drug_info',
93
+ # 'status': 'error_no_topic'
94
+ # }
95
+
96
+ # # Construct a specialized, safety-conscious prompt for the Gemini model
97
+ # prompt = f"""
98
+ # You are a highly knowledgeable and cautious AI Pharmacist Tutor. Your primary role is to provide accurate drug information for a B.Pharmacy student in India for EDUCATIONAL PURPOSES ONLY.
99
+
100
+ # **CRITICAL SAFETY INSTRUCTION:**
101
+ # START EVERY RESPONSE with the following disclaimer, exactly as written:
102
+ # "⚠️ **Disclaimer:** This information is for educational purposes ONLY and is not a substitute for professional medical advice. Always consult a qualified healthcare provider."
103
+
104
+ # **Task:**
105
+ # Provide a structured summary for the drug: **{drug_name}**
106
+
107
+ # **Information to Include:**
108
+ # 1. **Therapeutic Class:** What family of drugs does it belong to?
109
+ # 2. **Mechanism of Action (MOA):** How does it work in the body? Explain simply.
110
+ # 3. **Common Indications:** What is it typically used for?
111
+ # 4. **Common Side Effects:** List a few of the most common side effects.
112
+ # 5. **Important Contraindications/Warnings:** Who should not take this drug or be cautious?
113
+ # 6. **Common Dosage Forms:** What forms is it available in (e.g., Tablets, Syrup, Injection)? DO NOT provide specific dosages like mg or frequency.
114
+
115
+ # **Format:**
116
+ # Use clear headings (like "πŸ”¬ Mechanism of Action") and bullet points for readability. Use relevant emojis.
117
+ # """
118
+
119
+ # try:
120
+ # # Generate content using the AI model
121
+ # ai_response = self.model.generate_content(prompt, chat_history)
122
+ # return {
123
+ # 'message': ai_response.text,
124
+ # 'agent_used': 'drug_info',
125
+ # 'status': 'success'
126
+ # }
127
+ # except Exception as e:
128
+ # print(f"Drug Info Agent Error: {e}")
129
+ # return {
130
+ # 'message': f"I'm sorry, I couldn't access the drug database at the moment. An error occurred: {str(e)}",
131
+ # 'agent_type': 'drug_info',
132
+ # 'status': 'error_api_call'
133
+ # }
agents/mnemonic_agent.py CHANGED
@@ -30,84 +30,110 @@ class MnemonicAgent:
30
 
31
  # Clean up any extra whitespace
32
  return topic.strip()
33
-
34
- def process_query(self, query: str, file_context: str = "",chat_history: list = None):
35
- """
36
- Processes a query to generate a mnemonic.
37
-
38
- Args:
39
- query (str): The user's full query (e.g., "Give me a mnemonic for glycolysis steps").
40
- file_context (str): Optional context from uploaded files (usually not needed for mnemonics).
41
-
42
- Returns:
43
- dict: A dictionary containing the response message and agent metadata.
44
- """
45
- # Fallback response if the AI model is not configured
46
  if not self.model:
47
- return {
48
- 'message': "🧠 **Mnemonic Master**\n\nMy creative circuits are offline! The Gemini API key is missing, so I can't generate mnemonics right now. Please configure the API key to enable this feature.",
49
- 'agent_type': 'mnemonic_creation',
50
- 'status': 'error_no_api_key'
51
- }
52
-
53
- topic = self._extract_topic(query)
54
- if not topic:
55
- return {
56
- 'message': "Please tell me what topic you need a mnemonic for! For example, try 'mnemonic for Krebs cycle intermediates'.",
57
- 'agent_type': 'mnemonic_creation',
58
- 'status': 'error_no_topic'
59
- }
60
- # --- NEW LOGIC ---
61
- task_description = f"Generate a clever mnemonic for the B.Pharmacy topic: **{topic.title()}**."
62
-
63
- if file_context:
64
- task_description += f"\n\nIf relevant, you can use the following text from the student's uploaded notes for context:\n---\n{file_context}\n---"
65
-
66
-
67
- # Construct a specialized prompt for the Gemini model
68
- prompt = f"""
69
- You are "Mnemonic Master," a creative and witty AI that excels at creating memorable mnemonics for B.Pharmacy students in India.
70
 
71
- **Your Task:**
72
- {task_description}
 
 
 
 
73
 
74
- **Topic:** "{topic}"
75
 
76
- **Instructions:**
77
- 1. **Analyze the Topic:** Identify the key items to be memorized (e.g., steps, drug names, classifications).
78
- 2. **Create the Mnemonic:** Design a creative acronym, rhyme, or short, vivid story.
79
- 3. **Explain It:** Clearly state the mnemonic and then explain how it maps to the concepts.
80
- 4. **Tone:** Be encouraging, fun, and use emojis! The language should be simple and relatable.
81
 
82
- **Example Output Format:**
83
-
84
- 🧠 **Mnemonic for [Topic Name]**
85
-
86
- Here's a fun way to remember it!
87
-
88
- **The Mnemonic:**
89
- "[The actual acronym or rhyme]"
90
-
91
- **How it works:**
92
- * **[Letter 1]** stands for [Concept 1]
93
- * **[Letter 2]** stands for [Concept 2]
94
- * ...and so on!
95
-
96
- Keep up the great work! You've got this! πŸ’ͺ
97
  """
98
-
99
  try:
100
- # Generate content using the AI model
101
- ai_response = self.model.generate_content(prompt,chat_history)
102
- return {
103
- 'message': ai_response.text,
104
- 'agent_used': 'mnemonic_creation',
105
- 'status': 'success'
106
- }
107
  except Exception as e:
108
  print(f"Mnemonic Agent Error: {e}")
109
- return {
110
- 'message': f"Oh no! My creative spark fizzled out. I ran into an error: {str(e)}",
111
- 'agent_type': 'mnemonic_creation',
112
- 'status': 'error_api_call'
113
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  # Clean up any extra whitespace
32
  return topic.strip()
33
+ def process_query(self, query: str, file_context: str = "", chat_history: list = None):
 
 
 
 
 
 
 
 
 
 
 
 
34
  if not self.model:
35
+ return {'message': "🧠 My creative circuits are offline! The Gemini API key is missing.", 'agent_used': 'mnemonic_creation', 'status': 'error_no_api_key'}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ history_for_prompt = ""
38
+ if chat_history:
39
+ for turn in chat_history:
40
+ role = "User" if turn['role'] == 'user' else "AI"
41
+ if turn.get('parts'):
42
+ history_for_prompt += f"{role}: {turn['parts'][0]}\n"
43
 
44
+ prompt = f"""You are "Mnemonic Master," a creative AI that creates memorable mnemonics for B.Pharmacy students.
45
 
46
+ CONVERSATION HISTORY:
47
+ {history_for_prompt}
48
+ CURRENT TASK:
49
+ User: {query}
 
50
 
51
+ Based on the CURRENT TASK and conversation history, generate a clever and easy-to-remember mnemonic (acronym, rhyme, or story). Explain how it works. Be encouraging and fun!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  """
 
53
  try:
54
+ response = self.model.generate_content(prompt)
55
+ return {'message': response.text, 'agent_used': 'mnemonic_creation', 'status': 'success'}
 
 
 
 
 
56
  except Exception as e:
57
  print(f"Mnemonic Agent Error: {e}")
58
+ return {'message': f"My creative spark fizzled out. Error: {e}", 'agent_used': 'mnemonic_creation', 'status': 'error_api_call'}
59
+
60
+ # def process_query(self, query: str, file_context: str = "",chat_history: list = None):
61
+ # """
62
+ # Processes a query to generate a mnemonic.
63
+
64
+ # Args:
65
+ # query (str): The user's full query (e.g., "Give me a mnemonic for glycolysis steps").
66
+ # file_context (str): Optional context from uploaded files (usually not needed for mnemonics).
67
+
68
+ # Returns:
69
+ # dict: A dictionary containing the response message and agent metadata.
70
+ # """
71
+ # # Fallback response if the AI model is not configured
72
+ # if not self.model:
73
+ # return {
74
+ # 'message': "🧠 **Mnemonic Master**\n\nMy creative circuits are offline! The Gemini API key is missing, so I can't generate mnemonics right now. Please configure the API key to enable this feature.",
75
+ # 'agent_type': 'mnemonic_creation',
76
+ # 'status': 'error_no_api_key'
77
+ # }
78
+
79
+ # topic = self._extract_topic(query)
80
+ # if not topic:
81
+ # return {
82
+ # 'message': "Please tell me what topic you need a mnemonic for! For example, try 'mnemonic for Krebs cycle intermediates'.",
83
+ # 'agent_type': 'mnemonic_creation',
84
+ # 'status': 'error_no_topic'
85
+ # }
86
+ # # --- NEW LOGIC ---
87
+ # task_description = f"Generate a clever mnemonic for the B.Pharmacy topic: **{topic.title()}**."
88
+
89
+ # if file_context:
90
+ # task_description += f"\n\nIf relevant, you can use the following text from the student's uploaded notes for context:\n---\n{file_context}\n---"
91
+
92
+
93
+ # # Construct a specialized prompt for the Gemini model
94
+ # prompt = f"""
95
+ # You are "Mnemonic Master," a creative and witty AI that excels at creating memorable mnemonics for B.Pharmacy students in India.
96
+
97
+ # **Your Task:**
98
+ # {task_description}
99
+
100
+ # **Topic:** "{topic}"
101
+
102
+ # **Instructions:**
103
+ # 1. **Analyze the Topic:** Identify the key items to be memorized (e.g., steps, drug names, classifications).
104
+ # 2. **Create the Mnemonic:** Design a creative acronym, rhyme, or short, vivid story.
105
+ # 3. **Explain It:** Clearly state the mnemonic and then explain how it maps to the concepts.
106
+ # 4. **Tone:** Be encouraging, fun, and use emojis! The language should be simple and relatable.
107
+
108
+ # **Example Output Format:**
109
+
110
+ # 🧠 **Mnemonic for [Topic Name]**
111
+
112
+ # Here's a fun way to remember it!
113
+
114
+ # **The Mnemonic:**
115
+ # "[The actual acronym or rhyme]"
116
+
117
+ # **How it works:**
118
+ # * **[Letter 1]** stands for [Concept 1]
119
+ # * **[Letter 2]** stands for [Concept 2]
120
+ # * ...and so on!
121
+
122
+ # Keep up the great work! You've got this! πŸ’ͺ
123
+ # """
124
+
125
+ # try:
126
+ # # Generate content using the AI model
127
+ # ai_response = self.model.generate_content(prompt,chat_history)
128
+ # return {
129
+ # 'message': ai_response.text,
130
+ # 'agent_used': 'mnemonic_creation',
131
+ # 'status': 'success'
132
+ # }
133
+ # except Exception as e:
134
+ # print(f"Mnemonic Agent Error: {e}")
135
+ # return {
136
+ # 'message': f"Oh no! My creative spark fizzled out. I ran into an error: {str(e)}",
137
+ # 'agent_type': 'mnemonic_creation',
138
+ # 'status': 'error_api_call'
139
+ # }
agents/quiz_agent.py CHANGED
@@ -31,88 +31,121 @@ class QuizAgent:
31
 
32
  # Clean up any extra whitespace
33
  return topic.strip()
34
-
35
- def process_query(self, query: str, file_context: str = "",chat_history: list = None):
36
- """
37
- Processes a query to generate a quiz. The agent prioritizes file_context if provided.
38
-
39
- Args:
40
- query (str): The user's full query (e.g., "Make a quiz on analgesics").
41
- file_context (str): Optional text content from an uploaded file.
42
-
43
- Returns:
44
- dict: A dictionary containing the quiz and agent metadata.
45
- """
46
  if not self.model:
47
- return {
48
- 'message': "❓ **Quiz Master**\n\nThe question bank is locked! The Gemini API key is missing, so I can't generate quizzes. Please configure the API key to enable this feature.",
49
- 'agent_type': 'quiz_generation',
50
- 'status': 'error_no_api_key'
51
- }
52
 
53
  topic = self._extract_topic(query)
54
- task_description = f"Generate a short quiz (3-5 questions) for a B.Pharmacy student on the topic: **{topic.title()}**."
55
 
 
 
 
 
 
 
 
 
56
  if file_context:
57
- task_description += f"\n\nIf relevant, use the following text from the student's uploaded notes for additional context:\n---\n{file_context}\n---"
58
-
59
- else:
60
- return {
61
- 'message': "Please tell me what to quiz you on! Either upload a file or ask for a quiz on a specific topic, like 'quiz on antibiotics'.",
62
- 'agent_type': 'quiz_generation',
63
- 'status': 'error_no_topic'
64
- }
65
-
66
- # Construct a specialized prompt for the Gemini model
67
- prompt = f"""
68
- You are "Quiz Master," an AI that creates engaging and effective study quizzes for B.Pharmacy students in India.
69
-
70
- **Your Task:**
71
- {task_description}
72
-
73
- **Instructions:**
74
- 1. **Question Variety:** Create a mix of question types:
75
- * Multiple Choice Questions (MCQs) with 4 options.
76
- * True/False questions.
77
- * Fill-in-the-Blank questions.
78
- 2. **Clarity:** Ensure questions are clear, concise, and relevant.
79
- 3. **Answer Key:** THIS IS ESSENTIAL. After all the questions, provide a clearly separated "πŸ”‘ Answer Key" section with the correct answers. For MCQs, also provide a brief (one-sentence) explanation for why the answer is correct.
80
- 4. **Formatting:** Use markdown for headings, bolding, and lists. Use emojis to make it fun and engaging.
81
- Good luck! 🌟
82
- **Example Output Structure:**
83
-
84
- πŸ“ **Quiz Time: [Topic Name]**
85
 
86
- **Q1. [MCQ Question]**
87
- A) Option 1
88
- B) Option 2
89
- ...
90
 
91
- **Q2. [True/False Question]**
92
-
93
- **Q3. [Fill-in-the-Blank Question]**
94
-
95
- ---
96
- πŸ”‘ **Answer Key**
97
- 1. **Answer:** B) Correct Option. *Explanation: [Brief reason why B is correct].*
98
- 2. **Answer:** True.
99
- 3. **Answer:** [Correct word(s)].
100
 
101
- Let's test your knowledge! Good luck! 🌟
102
  """
103
-
104
  try:
105
- # Generate content using the AI model
106
- ai_response = self.model.generate_content(prompt, chat_history)
107
- return {
108
- 'message': ai_response.text,
109
- 'agent_used': 'quiz_generation',
110
- 'status': 'success'
111
- }
112
  except Exception as e:
113
  print(f"Quiz Agent Error: {e}")
114
- return {
115
- 'message': f"I'm sorry, my question book seems to be stuck. I ran into an error: {str(e)}",
116
- 'agent_type': 'quiz_generation',
117
- 'status': 'error_api_call'
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  # Clean up any extra whitespace
33
  return topic.strip()
34
+ def process_query(self, query: str, file_context: str = "", chat_history: list = None):
 
 
 
 
 
 
 
 
 
 
 
35
  if not self.model:
36
+ return {'message': "❓ The question bank is locked! The Gemini API key is missing.", 'agent_used': 'quiz_generation', 'status': 'error_no_api_key'}
 
 
 
 
37
 
38
  topic = self._extract_topic(query)
 
39
 
40
+ history_for_prompt = ""
41
+ if chat_history:
42
+ for turn in chat_history:
43
+ role = "User" if turn['role'] == 'user' else "AI"
44
+ if turn.get('parts'):
45
+ history_for_prompt += f"{role}: {turn['parts'][0]}\n"
46
+
47
+ task_description = f"Generate a short quiz (3-5 questions) on the topic: **{topic.title()}**."
48
  if file_context:
49
+ task_description += f"\nIf relevant, use the following text from the student's notes for context:\n---\n{file_context}\n---"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
+ prompt = f"""You are "Quiz Master," an AI that creates educational quizzes.
 
 
 
52
 
53
+ CONVERSATION HISTORY:
54
+ {history_for_prompt}
55
+ CURRENT TASK:
56
+ {task_description}
 
 
 
 
 
57
 
58
+ Based on the CURRENT TASK and conversation history, create a quiz. Include a mix of MCQs, True/False, and Fill-in-the-Blank questions. CRITICAL: Provide a separate "Answer Key" section with answers and brief explanations.
59
  """
 
60
  try:
61
+ response = self.model.generate_content(prompt)
62
+ return {'message': response.text, 'agent_used': 'quiz_generation', 'status': 'success'}
 
 
 
 
 
63
  except Exception as e:
64
  print(f"Quiz Agent Error: {e}")
65
+ return {'message': f"My question book seems to be stuck. Error: {e}", 'agent_used': 'quiz_generation', 'status': 'error_api_call'}
66
+
67
+
68
+ # def process_query(self, query: str, file_context: str = "",chat_history: list = None):
69
+ # """
70
+ # Processes a query to generate a quiz. The agent prioritizes file_context if provided.
71
+
72
+ # Args:
73
+ # query (str): The user's full query (e.g., "Make a quiz on analgesics").
74
+ # file_context (str): Optional text content from an uploaded file.
75
+
76
+ # Returns:
77
+ # dict: A dictionary containing the quiz and agent metadata.
78
+ # """
79
+ # if not self.model:
80
+ # return {
81
+ # 'message': "❓ **Quiz Master**\n\nThe question bank is locked! The Gemini API key is missing, so I can't generate quizzes. Please configure the API key to enable this feature.",
82
+ # 'agent_type': 'quiz_generation',
83
+ # 'status': 'error_no_api_key'
84
+ # }
85
+
86
+ # topic = self._extract_topic(query)
87
+ # task_description = f"Generate a short quiz (3-5 questions) for a B.Pharmacy student on the topic: **{topic.title()}**."
88
+
89
+ # if file_context:
90
+ # task_description += f"\n\nIf relevant, use the following text from the student's uploaded notes for additional context:\n---\n{file_context}\n---"
91
+
92
+ # else:
93
+ # return {
94
+ # 'message': "Please tell me what to quiz you on! Either upload a file or ask for a quiz on a specific topic, like 'quiz on antibiotics'.",
95
+ # 'agent_type': 'quiz_generation',
96
+ # 'status': 'error_no_topic'
97
+ # }
98
+
99
+ # # Construct a specialized prompt for the Gemini model
100
+ # prompt = f"""
101
+ # You are "Quiz Master," an AI that creates engaging and effective study quizzes for B.Pharmacy students in India.
102
+
103
+ # **Your Task:**
104
+ # {task_description}
105
+
106
+ # **Instructions:**
107
+ # 1. **Question Variety:** Create a mix of question types:
108
+ # * Multiple Choice Questions (MCQs) with 4 options.
109
+ # * True/False questions.
110
+ # * Fill-in-the-Blank questions.
111
+ # 2. **Clarity:** Ensure questions are clear, concise, and relevant.
112
+ # 3. **Answer Key:** THIS IS ESSENTIAL. After all the questions, provide a clearly separated "πŸ”‘ Answer Key" section with the correct answers. For MCQs, also provide a brief (one-sentence) explanation for why the answer is correct.
113
+ # 4. **Formatting:** Use markdown for headings, bolding, and lists. Use emojis to make it fun and engaging.
114
+ # Good luck! 🌟
115
+ # **Example Output Structure:**
116
+
117
+ # πŸ“ **Quiz Time: [Topic Name]**
118
+
119
+ # **Q1. [MCQ Question]**
120
+ # A) Option 1
121
+ # B) Option 2
122
+ # ...
123
+
124
+ # **Q2. [True/False Question]**
125
+
126
+ # **Q3. [Fill-in-the-Blank Question]**
127
+
128
+ # ---
129
+ # πŸ”‘ **Answer Key**
130
+ # 1. **Answer:** B) Correct Option. *Explanation: [Brief reason why B is correct].*
131
+ # 2. **Answer:** True.
132
+ # 3. **Answer:** [Correct word(s)].
133
+
134
+ # Let's test your knowledge! Good luck! 🌟
135
+ # """
136
+
137
+ # try:
138
+ # # Generate content using the AI model
139
+ # ai_response = self.model.generate_content(prompt, chat_history)
140
+ # return {
141
+ # 'message': ai_response.text,
142
+ # 'agent_used': 'quiz_generation',
143
+ # 'status': 'success'
144
+ # }
145
+ # except Exception as e:
146
+ # print(f"Quiz Agent Error: {e}")
147
+ # return {
148
+ # 'message': f"I'm sorry, my question book seems to be stuck. I ran into an error: {str(e)}",
149
+ # 'agent_type': 'quiz_generation',
150
+ # 'status': 'error_api_call'
151
+ # }