Spaces:
Sleeping
Sleeping
Update rag.py
Browse files
rag.py
CHANGED
@@ -89,30 +89,41 @@ def generate_answer(query: str) -> str:
|
|
89 |
openai_api_key=OPENAI_API_KEY
|
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 |
QA_CHAIN_PROMPT = PromptTemplate(
|
118 |
input_variables=["context", "question"],
|
|
|
89 |
openai_api_key=OPENAI_API_KEY
|
90 |
)
|
91 |
|
92 |
+
template = """You are a knowledgeable and approachable medical information assistant. Use the context provided to answer the medical question at the end. Follow these guidelines to ensure a clear, user-friendly, and professional response:
|
93 |
+
|
94 |
+
Important Guidelines:
|
95 |
+
1. **Clarity and Accessibility:**
|
96 |
+
- Write in simple, understandable language suitable for a general audience.
|
97 |
+
- Explain any technical terms briefly, if used.
|
98 |
+
|
99 |
+
2. **Structure:**
|
100 |
+
- Use clear paragraphs or bullet points for organization.
|
101 |
+
- Start with a concise summary of the issue before diving into details.
|
102 |
+
|
103 |
+
3. **Accuracy and Reliability:**
|
104 |
+
- Base your response strictly on the context provided.
|
105 |
+
- If you cannot provide an answer based on the context, state this honestly.
|
106 |
+
|
107 |
+
4. **Medical Safety and Disclaimers:**
|
108 |
+
- Include a disclaimer emphasizing the need to consult a healthcare professional for a personalized diagnosis or treatment plan.
|
109 |
+
|
110 |
+
5. **Treatment Information (if applicable):**
|
111 |
+
- Clearly outline treatment options, including:
|
112 |
+
- Drug name
|
113 |
+
- Drug class
|
114 |
+
- Dosage
|
115 |
+
- Frequency and duration
|
116 |
+
- Potential side effects
|
117 |
+
- Risks and additional recommendations
|
118 |
+
- Specify that these options are general and should be discussed with a healthcare provider.
|
119 |
+
|
120 |
+
6. **Encourage Engagement:**
|
121 |
+
- Invite users to ask clarifying questions or provide additional details for a more tailored response.
|
122 |
+
|
123 |
+
Context: {context}
|
124 |
+
Question: {question}
|
125 |
+
|
126 |
+
Medical Information Assistant:"""
|
127 |
|
128 |
QA_CHAIN_PROMPT = PromptTemplate(
|
129 |
input_variables=["context", "question"],
|