File size: 5,747 Bytes
c1bc991
 
 
 
 
1f1f2eb
c1bc991
 
 
 
 
 
 
 
 
 
1f1f2eb
 
 
 
 
 
 
 
 
 
 
 
c1bc991
1f1f2eb
c1bc991
1f1f2eb
fcd9088
fe26eab
c1bc991
fcd9088
c1bc991
1f1f2eb
 
 
 
fcd9088
 
 
 
c1bc991
1f1f2eb
c1bc991
 
fcd9088
 
c1bc991
 
fcd9088
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# agents/drug_info_agent.py
"""
Drug Information Agent - Handles drug-related queries using Generative AI.
"""
import re
from .agent_helpers import format_history_for_prompt
class DrugInfoAgent:
    def __init__(self, gemini_model=None):
        """
        Initializes the agent with the Gemini model.

        Args:
            gemini_model: An instance of the Gemini model client.
        """
        self.model = gemini_model

def process_query(self, query: str, file_context: str = "", chat_history: list = None):
        """
        Processes a query to retrieve information about a specific drug.

        Args:
            query (str): The user's full query (e.g., "Tell me about Metformin").
            file_context (str): Optional context from uploaded files.
            chat_history (list): The history of the conversation.

        Returns:
            dict: A dictionary containing the response message and agent metadata.
        """
        if not self.model:
            return {'message': "πŸ’Š The pharmacy database is offline! The Gemini API key is missing.", 'agent_used': 'drug_info', 'status': 'error_no_api_key'}

        history_for_prompt = format_history_for_prompt(chat_history)
        
        prompt = f"""You are a cautious AI Pharmacist Tutor like Chanakya  providing educational information.

**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."

Your reasoning process must be:
1. Analyze the CONVERSATION HISTORY and the CURRENT QUESTION to identify the drug being discussed.
2. Provide a structured summary for that drug. If the user asks a follow-up (e.g., "what about its side effects?"), answer that specific question in the context of the drug already being discussed.

CONVERSATION HISTORY:
{history_for_prompt}
CURRENT QUESTION:
User: {query}

Provide a structured summary including: Therapeutic Class, MOA, Indications, Side Effects, and Warnings. DO NOT provide specific dosages.
"""
        try:
            response = self.model.generate_content(prompt)
            return {'message': response.text, 'agent_used': 'drug_info', 'status': 'success'}
        except Exception as e:
            print(f"Drug Info Agent Error: {e}")
            return {'message': f"Sorry, I couldn't access the drug database. Error: {e}", 'agent_used': 'drug_info', 'status': 'error_api_call'}

#     def process_query(self, query: str, file_context: str = "", chat_history: list = None):
#         """
#         Processes a query to retrieve information about a specific drug.

#         Args:
#             query (str): The user's full query (e.g., "Tell me about Metformin").
#             file_context (str): Optional context from uploaded files.
        
#         Returns:
#             dict: A dictionary containing the response message and agent metadata.
#         """
#         # Fallback response if the AI model is not configured
#         if not self.model:
#             return {
#                 '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.",
#                 'agent_type': 'drug_info',
#                 'status': 'error_no_api_key'
#             }

#         drug_name = self._extract_drug_name(query)
#         if not drug_name:
#             return {
#                 'message': "Please tell me which drug you want to know about! For example, try 'info on Paracetamol'.",
#                 'agent_type': 'drug_info',
#                 'status': 'error_no_topic'
#             }

#         # Construct a specialized, safety-conscious prompt for the Gemini model
#         prompt = f"""
# 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.

# **CRITICAL SAFETY INSTRUCTION:**
# START EVERY RESPONSE with the following disclaimer, exactly as written:
# "⚠️ **Disclaimer:** This information is for educational purposes ONLY and is not a substitute for professional medical advice. Always consult a qualified healthcare provider."

# **Task:**
# Provide a structured summary for the drug: **{drug_name}**

# **Information to Include:**
# 1.  **Therapeutic Class:** What family of drugs does it belong to?
# 2.  **Mechanism of Action (MOA):** How does it work in the body? Explain simply.
# 3.  **Common Indications:** What is it typically used for?
# 4.  **Common Side Effects:** List a few of the most common side effects.
# 5.  **Important Contraindications/Warnings:** Who should not take this drug or be cautious?
# 6.  **Common Dosage Forms:** What forms is it available in (e.g., Tablets, Syrup, Injection)? DO NOT provide specific dosages like mg or frequency.

# **Format:**
# Use clear headings (like "πŸ”¬ Mechanism of Action") and bullet points for readability. Use relevant emojis.
# """

#         try:
#             # Generate content using the AI model
#             ai_response = self.model.generate_content(prompt, chat_history)
#             return {
#                 'message': ai_response.text,
#                 'agent_used': 'drug_info',
#                 'status': 'success'
#             }
#         except Exception as e:
#             print(f"Drug Info Agent Error: {e}")
#             return {
#                 'message': f"I'm sorry, I couldn't access the drug database at the moment. An error occurred: {str(e)}",
#                 'agent_type': 'drug_info',
#                 'status': 'error_api_call'
#             }