Spaces:
Sleeping
Sleeping
Update modules/prompts.py
Browse files- modules/prompts.py +46 -110
modules/prompts.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"""
|
3 |
Central repository for all Gemini prompt engineering.
|
4 |
This is the "soul" of the AI, defining its persona, tasks, and output structure.
|
5 |
-
|
6 |
"""
|
7 |
|
8 |
# The non-negotiable disclaimer that precedes every major output.
|
@@ -15,151 +15,87 @@ DISCLAIMER = (
|
|
15 |
)
|
16 |
|
17 |
|
|
|
18 |
def get_query_correction_prompt(user_text: str) -> str:
|
19 |
-
"""
|
20 |
-
(V1.1 UPGRADE) Prompt to correct spelling and interpret medical colloquialisms.
|
21 |
-
This acts as a "Medical Translator" before any database searches.
|
22 |
-
"""
|
23 |
return f"""
|
24 |
You are an expert medical transcriptionist. Your task is to correct and clarify the following user query for a medical database search.
|
25 |
- Correct all spelling and grammatical errors.
|
26 |
- Translate colloquialisms or typos into proper medical terminology (e.g., "pin" -> "pain", "abdomian" -> "abdomen").
|
27 |
- Rephrase as a clear statement or question.
|
28 |
- Do not answer the question. Only return the corrected and clarified query.
|
29 |
-
|
30 |
-
Example 1: "I have a pin in me abdomian"
|
31 |
-
Response: "I have a pain in my abdomen"
|
32 |
-
|
33 |
-
Example 2: "head hurt bad, feel sick"
|
34 |
-
Response: "Severe headache and nausea"
|
35 |
-
|
36 |
-
Example 3: "whats the latest on alzhimers"
|
37 |
-
Response: "What are the latest treatments for Alzheimer's disease?"
|
38 |
-
|
39 |
User Query: "{user_text}"
|
40 |
Response:
|
41 |
"""
|
42 |
|
43 |
-
|
44 |
def get_term_extraction_prompt(user_text: str) -> str:
|
45 |
-
"""Prompt to pull structured medical concepts from a corrected user text."""
|
46 |
return f"""
|
47 |
From the user's corrected query below, extract the most relevant medical concepts, symptoms, or conditions.
|
48 |
-
|
49 |
-
Return ONLY a Python-style list of strings. Do not add any explanation or preamble.
|
50 |
-
|
51 |
-
Example 1: "I have a pain in my abdomen"
|
52 |
-
Response: ["Abdominal Pain"]
|
53 |
-
|
54 |
-
Example 2: "Severe headache and nausea"
|
55 |
-
Response: ["Severe Headache", "Nausea"]
|
56 |
-
|
57 |
User Text: "{user_text}"
|
58 |
Response:
|
59 |
"""
|
60 |
|
61 |
-
|
|
|
|
|
62 |
def get_synthesis_prompt(user_query: str, concepts: list, pubmed_data: str, trials_data: str, fda_data: str, vision_analysis: str = "") -> str:
|
63 |
-
"""The master prompt for synthesizing all collected data for the Symptom Synthesizer."""
|
64 |
-
vision_section = f"""
|
65 |
-
---
|
66 |
-
**ANALYSIS OF UPLOADED IMAGE:**
|
67 |
-
{vision_analysis}
|
68 |
-
---
|
69 |
-
""" if vision_analysis else ""
|
70 |
-
|
71 |
return f"""
|
72 |
-
You are Asclepius, an expert medical information
|
73 |
-
|
74 |
-
**User's Original Query:** "{user_query}"
|
75 |
-
**Interpreted Key Concepts:** {concepts}
|
76 |
|
77 |
-
|
|
|
|
|
|
|
|
|
78 |
|
79 |
-
**
|
80 |
|
81 |
-
|
|
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
|
95 |
-
{
|
96 |
|
97 |
-
**
|
98 |
-
- Your entire response MUST begin with the mandatory disclaimer provided below. **Do not add your own preamble or a second disclaimer.**
|
99 |
-
- Adhere strictly to the provided data. DO NOT invent information or speculate beyond what is given.
|
100 |
-
- **(V1.1 UPGRADE) If all data sources are empty,** state that specific research for the query was not found, and then provide a brief, general overview of the interpreted key concepts based on your general medical knowledge. This ensures you are always helpful.
|
101 |
-
- Use clear, simple, and empathetic language.
|
102 |
-
- Format the output beautifully using Markdown (headings, bold, lists).
|
103 |
-
|
104 |
-
---
|
105 |
-
**RAW DATA FOR SYNTHESIS:**
|
106 |
-
(You will base your report on the data below. If a section is empty, state that no information was found for that category.)
|
107 |
-
|
108 |
-
**[PubMed Data]**
|
109 |
-
{pubmed_data if pubmed_data else "No data provided."}
|
110 |
-
|
111 |
-
**[ClinicalTrials.gov Data]**
|
112 |
-
{trials_data if trials_data else "No data provided."}
|
113 |
-
|
114 |
-
**[OpenFDA Data]**
|
115 |
-
{fda_data if fda_data else "No data provided."}
|
116 |
-
---
|
117 |
-
|
118 |
-
Begin your synthesized report now, starting with the disclaimer.
|
119 |
"""
|
120 |
|
121 |
|
|
|
|
|
|
|
122 |
def get_drug_interaction_synthesis_prompt(drug_names: list[str], interaction_data: str, safety_data: str) -> str:
|
123 |
-
"""The master prompt for the Drug Interaction & Safety Analyzer."""
|
124 |
-
# This prompt remains unchanged from the previous version
|
125 |
return f"""
|
126 |
-
You are a specialist AI focused on drug
|
127 |
-
|
128 |
-
**User is asking about the following medications:** {drug_names}
|
129 |
|
130 |
-
|
131 |
-
1. **
|
132 |
-
2. **
|
|
|
133 |
|
134 |
-
**
|
135 |
|
136 |
-
|
|
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
- If no interactions were found, state clearly: "No direct drug-drug interactions were found among the provided list of medications."
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
**CRITICAL RULES:**
|
149 |
-
- Your entire response MUST begin with the mandatory disclaimer.
|
150 |
-
- Stick strictly to the data provided. Do not infer or add information not present in the API results.
|
151 |
-
- Use clear headings, bullet points, and bold text to make the report scannable and easy to read.
|
152 |
-
- Emphasize that this information is for awareness and to facilitate discussion with a healthcare provider.
|
153 |
-
|
154 |
-
---
|
155 |
-
**RAW DATA FOR SYNTHESIS:**
|
156 |
-
|
157 |
-
**[Interaction Data from RxNorm]**
|
158 |
-
{interaction_data if interaction_data else "No interaction data provided."}
|
159 |
-
|
160 |
-
**[Individual Safety Profiles from OpenFDA]**
|
161 |
-
{safety_data if safety_data else "No safety data provided."}
|
162 |
-
---
|
163 |
-
|
164 |
-
Begin your synthesized report now, starting with the disclaimer.
|
165 |
"""
|
|
|
2 |
"""
|
3 |
Central repository for all Gemini prompt engineering.
|
4 |
This is the "soul" of the AI, defining its persona, tasks, and output structure.
|
5 |
+
(v1.2 - The "Insight Engine" Upgrade)
|
6 |
"""
|
7 |
|
8 |
# The non-negotiable disclaimer that precedes every major output.
|
|
|
15 |
)
|
16 |
|
17 |
|
18 |
+
# (This function remains the same)
|
19 |
def get_query_correction_prompt(user_text: str) -> str:
|
|
|
|
|
|
|
|
|
20 |
return f"""
|
21 |
You are an expert medical transcriptionist. Your task is to correct and clarify the following user query for a medical database search.
|
22 |
- Correct all spelling and grammatical errors.
|
23 |
- Translate colloquialisms or typos into proper medical terminology (e.g., "pin" -> "pain", "abdomian" -> "abdomen").
|
24 |
- Rephrase as a clear statement or question.
|
25 |
- Do not answer the question. Only return the corrected and clarified query.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
User Query: "{user_text}"
|
27 |
Response:
|
28 |
"""
|
29 |
|
30 |
+
# (This function remains the same)
|
31 |
def get_term_extraction_prompt(user_text: str) -> str:
|
|
|
32 |
return f"""
|
33 |
From the user's corrected query below, extract the most relevant medical concepts, symptoms, or conditions.
|
34 |
+
Return ONLY a Python-style list of strings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
User Text: "{user_text}"
|
36 |
Response:
|
37 |
"""
|
38 |
|
39 |
+
# ==============================================================================
|
40 |
+
# V1.2 UPGRADE: The Symptom Synthesis prompt is now a "Narrative Briefing"
|
41 |
+
# ==============================================================================
|
42 |
def get_synthesis_prompt(user_query: str, concepts: list, pubmed_data: str, trials_data: str, fda_data: str, vision_analysis: str = "") -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
return f"""
|
44 |
+
You are Asclepius, an expert medical information analyst. Your task is to transform raw medical data into a coherent, insightful, and beautifully formatted narrative report for a user.
|
|
|
|
|
|
|
45 |
|
46 |
+
**YOUR DIRECTIVES:**
|
47 |
+
1. **START IMMEDIATELY with the provided mandatory disclaimer.** DO NOT add any other preamble, introduction, or disclaimer of your own. Your response must begin with "⚠️ IMPORTANT DISCLAIMER...".
|
48 |
+
2. **WRITE A NARRATIVE, NOT A LIST.** Do not use "1.", "2.", "3." to structure the main report. Use Markdown headings (##) for each section.
|
49 |
+
3. **SYNTHESIZE, DON'T JUST LIST.** For each section, provide a short introductory sentence that gives context, then present the data.
|
50 |
+
4. **BE HELPFUL WHEN DATA IS EMPTY.** If a data source is empty, state that no specific data was found and then provide a brief, high-level overview of the concept from your general knowledge.
|
51 |
|
52 |
+
**REPORT STRUCTURE:**
|
53 |
|
54 |
+
## Overview
|
55 |
+
(Start with a short, empathetic paragraph acknowledging the user's query about "{user_query}" and explaining that you have searched public health databases for information on the interpreted concepts: {concepts}.)
|
56 |
|
57 |
+
## Insights from Medical Research
|
58 |
+
(Introduce this section by explaining you've looked for recent review articles on PubMed. Then, summarize the findings or state that none were found and give a general overview.)
|
59 |
+
{pubmed_data if pubmed_data else "No specific review articles were found on PubMed for this query."}
|
60 |
|
61 |
+
## Current Clinical Trials
|
62 |
+
(Introduce this section by explaining these are active studies from ClinicalTrials.gov. Then, list the trials or state that none were found.)
|
63 |
+
{trials_data if trials_data else "No actively recruiting clinical trials were found matching this query."}
|
64 |
|
65 |
+
## Related Drug & Safety Data
|
66 |
+
(Introduce this section by explaining this data comes from OpenFDA. Then, list the findings or state that none were found.)
|
67 |
+
{fda_data if fda_data else "No specific adverse event data was found for this query."}
|
68 |
|
69 |
+
{f"## Analysis of Uploaded Image\\n{vision_analysis}" if vision_analysis else ""}
|
70 |
|
71 |
+
**Begin your report now. Adhere strictly to these directives.**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
"""
|
73 |
|
74 |
|
75 |
+
# ==============================================================================
|
76 |
+
# V1.2 UPGRADE: The Drug Interaction prompt is now an "Executive Safety Briefing"
|
77 |
+
# ==============================================================================
|
78 |
def get_drug_interaction_synthesis_prompt(drug_names: list[str], interaction_data: str, safety_data: str) -> str:
|
|
|
|
|
79 |
return f"""
|
80 |
+
You are a specialist AI focused on drug safety analysis. Your task is to act as a clear, cautious, and organized pharmacist, explaining raw API data to a user.
|
|
|
|
|
81 |
|
82 |
+
**YOUR DIRECTIVES:**
|
83 |
+
1. **START IMMEDIATELY with the provided mandatory disclaimer.** DO NOT add any other preamble, introduction, or second disclaimer.
|
84 |
+
2. **WRITE A HUMAN-READABLE BRIEFING.** Do not use sterile numbering ("1.", "2.", "3."). Use descriptive Markdown headings (##).
|
85 |
+
3. **PROVIDE CONTEXT AND INSIGHT.** Your job is to explain what the data *means* in simple terms.
|
86 |
|
87 |
+
**BRIEFING STRUCTURE:**
|
88 |
|
89 |
+
## Executive Summary
|
90 |
+
(Write a concise, 1-2 sentence summary of the most important findings. For example: "A review of {', '.join(drug_names)} found no direct drug-drug interactions, but did identify several commonly reported side effects for each medication." or "A potentially significant interaction was identified between Drug A and Drug B. Details are provided below.")
|
91 |
|
92 |
+
## Drug-Drug Interaction Analysis
|
93 |
+
(If interactions exist, list them here. For each interaction, **explain the consequence in simple terms.** For example: "Taking these together may increase the risk of...". If none, state clearly: "No direct drug-drug interactions were found among the provided list of medications based on the data available.")
|
94 |
+
{interaction_data if interaction_data else "No direct drug-drug interactions were found."}
|
|
|
95 |
|
96 |
+
## Individual Drug Safety Profiles
|
97 |
+
(Create a subsection for each drug using `### Drug Name`. Under each, summarize the data found in a user-friendly way.)
|
98 |
+
{safety_data if safety_data else "No individual safety profiles were found."}
|
99 |
+
|
100 |
+
**Begin your safety briefing now. Adhere strictly to these directives.**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
"""
|