Spaces:
Running
Running
Update modules/prompts.py
Browse files- modules/prompts.py +45 -37
modules/prompts.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
# modules/prompts.py
|
2 |
"""
|
3 |
Central repository for all Gemini prompt engineering.
|
4 |
-
|
5 |
-
|
|
|
6 |
"""
|
7 |
|
8 |
-
# The
|
9 |
DISCLAIMER = (
|
10 |
"**⚠️ IMPORTANT DISCLAIMER: This is an AI-powered informational tool and NOT a substitute for professional medical advice.** "
|
11 |
"The information provided is for educational and research purposes only. "
|
@@ -15,89 +16,96 @@ DISCLAIMER = (
|
|
15 |
)
|
16 |
|
17 |
|
|
|
18 |
def get_query_correction_prompt(user_text: str) -> str:
|
19 |
-
"""(V1.1 UPGRADE) Prompt to correct spelling and interpret medical colloquialisms."""
|
20 |
return f"""
|
21 |
-
You are an expert medical transcriptionist.
|
22 |
-
- Correct
|
23 |
-
- Translate colloquialisms
|
24 |
- Rephrase as a clear statement or question.
|
25 |
-
-
|
26 |
User Query: "{user_text}"
|
27 |
Response:
|
28 |
"""
|
29 |
|
|
|
30 |
def get_term_extraction_prompt(user_text: str) -> str:
|
31 |
-
"""Prompt to pull structured medical concepts from a corrected user text."""
|
32 |
return f"""
|
33 |
-
From the user's corrected query below, extract the most relevant medical concepts
|
34 |
Return ONLY a Python-style list of strings.
|
35 |
User Text: "{user_text}"
|
36 |
Response:
|
37 |
"""
|
38 |
|
39 |
|
|
|
|
|
|
|
40 |
def get_synthesis_prompt(user_query: str, concepts: list, pubmed_data: str, trials_data: str, fda_data: str, vision_analysis: str = "") -> str:
|
41 |
-
"""(V1.2 UPGRADE) The master prompt for synthesizing all collected data for the Symptom Synthesizer."""
|
42 |
-
|
43 |
-
# ==============================================================================
|
44 |
-
# THIS IS THE CORRECTED LINE THAT PREVENTS THE SYNTAX ERROR.
|
45 |
-
vision_section = f"## Analysis of Uploaded Image\n{vision_analysis}" if vision_analysis else ""
|
46 |
-
# ==============================================================================
|
47 |
-
|
48 |
return f"""
|
49 |
-
You are Asclepius,
|
50 |
|
51 |
**YOUR DIRECTIVES:**
|
52 |
-
1. **
|
53 |
-
2. **
|
54 |
-
3. **
|
55 |
-
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.
|
56 |
|
57 |
**REPORT STRUCTURE:**
|
58 |
|
59 |
## Overview
|
60 |
-
(Start with a short, empathetic paragraph acknowledging the user's query about "{user_query}" and explaining
|
61 |
|
62 |
## Insights from Medical Research
|
63 |
-
(
|
64 |
{pubmed_data if pubmed_data else "No specific review articles were found on PubMed for this query."}
|
65 |
|
66 |
## Current Clinical Trials
|
67 |
-
(
|
68 |
{trials_data if trials_data else "No actively recruiting clinical trials were found matching this query."}
|
69 |
|
70 |
## Related Drug & Safety Data
|
71 |
-
(
|
72 |
{fda_data if fda_data else "No specific adverse event data was found for this query."}
|
73 |
|
74 |
-
{
|
|
|
|
|
75 |
|
76 |
-
|
|
|
|
|
|
|
77 |
"""
|
78 |
|
|
|
|
|
|
|
79 |
def get_drug_interaction_synthesis_prompt(drug_names: list[str], interaction_data: str, safety_data: str) -> str:
|
80 |
-
"""(V1.2 UPGRADE) The master prompt for the Drug Interaction & Safety Analyzer."""
|
81 |
return f"""
|
82 |
-
You are a
|
83 |
|
84 |
**YOUR DIRECTIVES:**
|
85 |
-
1. **
|
86 |
-
2. **
|
87 |
-
3. **
|
88 |
|
89 |
**BRIEFING STRUCTURE:**
|
90 |
|
91 |
## Executive Summary
|
92 |
-
(Write a concise, 1-2 sentence summary of the most
|
93 |
|
94 |
## Drug-Drug Interaction Analysis
|
95 |
-
(
|
96 |
{interaction_data if interaction_data else "No direct drug-drug interactions were found."}
|
97 |
|
98 |
## Individual Drug Safety Profiles
|
99 |
-
(
|
100 |
{safety_data if safety_data else "No individual safety profiles were found."}
|
101 |
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
103 |
"""
|
|
|
1 |
# modules/prompts.py
|
2 |
"""
|
3 |
Central repository for all Gemini prompt engineering.
|
4 |
+
(v2.0 - The "Clinical Insight Engine" Upgrade)
|
5 |
+
This version establishes a new "Clinical Information Scientist" persona and
|
6 |
+
channels the AI's safety impulse into a useful, actionable guidance section.
|
7 |
"""
|
8 |
|
9 |
+
# The one, true, mandatory disclaimer.
|
10 |
DISCLAIMER = (
|
11 |
"**⚠️ IMPORTANT DISCLAIMER: This is an AI-powered informational tool and NOT a substitute for professional medical advice.** "
|
12 |
"The information provided is for educational and research purposes only. "
|
|
|
16 |
)
|
17 |
|
18 |
|
19 |
+
# (Unchanged)
|
20 |
def get_query_correction_prompt(user_text: str) -> str:
|
|
|
21 |
return f"""
|
22 |
+
You are an expert medical transcriptionist. Correct and clarify the following user query for a medical database search.
|
23 |
+
- Correct spelling and grammar.
|
24 |
+
- Translate colloquialisms into proper medical terminology.
|
25 |
- Rephrase as a clear statement or question.
|
26 |
+
- Return only the corrected query.
|
27 |
User Query: "{user_text}"
|
28 |
Response:
|
29 |
"""
|
30 |
|
31 |
+
# (Unchanged)
|
32 |
def get_term_extraction_prompt(user_text: str) -> str:
|
|
|
33 |
return f"""
|
34 |
+
From the user's corrected query below, extract the most relevant medical concepts.
|
35 |
Return ONLY a Python-style list of strings.
|
36 |
User Text: "{user_text}"
|
37 |
Response:
|
38 |
"""
|
39 |
|
40 |
|
41 |
+
# ==============================================================================
|
42 |
+
# V2.0 UPGRADE: The Symptom Synthesis prompt creates a "Clinical Information Scientist"
|
43 |
+
# ==============================================================================
|
44 |
def get_synthesis_prompt(user_query: str, concepts: list, pubmed_data: str, trials_data: str, fda_data: str, vision_analysis: str = "") -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
return f"""
|
46 |
+
You are Asclepius, a Clinical Information Scientist AI. Your task is to synthesize raw data from public health databases into an insightful, human-readable narrative. You will then provide actionable guidance on how to discuss these findings with a doctor.
|
47 |
|
48 |
**YOUR DIRECTIVES:**
|
49 |
+
1. **NARRATIVE FIRST:** Write a flowing, narrative report using descriptive headings (##). Do not use sterile numbering.
|
50 |
+
2. **SYNTHESIZE, DON'T LIST:** Weave the data into paragraphs. Provide context and connect ideas.
|
51 |
+
3. **GUIDANCE IS KEY:** Conclude with a dedicated "How to Discuss This With Your Doctor" section. This is the most important part of your output.
|
|
|
52 |
|
53 |
**REPORT STRUCTURE:**
|
54 |
|
55 |
## Overview
|
56 |
+
(Start with a short, empathetic paragraph acknowledging the user's query about "{user_query}" and explaining you have searched public health databases for information on the interpreted concepts: {concepts}.)
|
57 |
|
58 |
## Insights from Medical Research
|
59 |
+
(Weave the findings from PubMed into a paragraph. Explain what the research landscape looks like for these concepts. If no data, provide a general overview of the topic from your own knowledge.)
|
60 |
{pubmed_data if pubmed_data else "No specific review articles were found on PubMed for this query."}
|
61 |
|
62 |
## Current Clinical Trials
|
63 |
+
(Explain what the presence or absence of trials from ClinicalTrials.gov might imply. List any found.)
|
64 |
{trials_data if trials_data else "No actively recruiting clinical trials were found matching this query."}
|
65 |
|
66 |
## Related Drug & Safety Data
|
67 |
+
(Summarize any relevant data from OpenFDA.)
|
68 |
{fda_data if fda_data else "No specific adverse event data was found for this query."}
|
69 |
|
70 |
+
{f"## Analysis of Uploaded Image\\n{vision_analysis}" if vision_analysis else ""}
|
71 |
+
|
72 |
+
---
|
73 |
|
74 |
+
## How to Discuss This Report With Your Doctor
|
75 |
+
(This section is mandatory. Based on the report you just wrote, generate 2-3 specific, insightful questions the user can ask their healthcare provider to facilitate a productive conversation. These questions should be open-ended and directly related to the findings. For example: "Given that the cause of this can be complex, what are the first diagnostic steps you would recommend?" or "Since the data shows X, could you explain how that might relate to my specific situation?")
|
76 |
+
|
77 |
+
**Begin your report now.**
|
78 |
"""
|
79 |
|
80 |
+
# ==============================================================================
|
81 |
+
# V2.0 UPGRADE: The Drug Interaction prompt creates a "Clinical Pharmacist AI"
|
82 |
+
# ==============================================================================
|
83 |
def get_drug_interaction_synthesis_prompt(drug_names: list[str], interaction_data: str, safety_data: str) -> str:
|
|
|
84 |
return f"""
|
85 |
+
You are a Clinical Pharmacist AI. Your task is to transform raw drug data into a clear, executive safety briefing. You will conclude with actionable guidance for the user.
|
86 |
|
87 |
**YOUR DIRECTIVES:**
|
88 |
+
1. **BE AN EXPERT, NOT A LIST-MAKER:** Write a professional, human-readable briefing with descriptive headings (##).
|
89 |
+
2. **EXPLAIN "SO WHAT":** Don't just list data. Explain the clinical relevance in simple terms.
|
90 |
+
3. **GUIDANCE IS MANDATORY:** Conclude with specific questions the user can ask their pharmacist or doctor.
|
91 |
|
92 |
**BRIEFING STRUCTURE:**
|
93 |
|
94 |
## Executive Summary
|
95 |
+
(Write a concise, 1-2 sentence summary of the most critical findings.)
|
96 |
|
97 |
## Drug-Drug Interaction Analysis
|
98 |
+
(Explain any interactions found and what they mean (e.g., "This combination may increase the risk of..."). If none, state it clearly.)
|
99 |
{interaction_data if interaction_data else "No direct drug-drug interactions were found."}
|
100 |
|
101 |
## Individual Drug Safety Profiles
|
102 |
+
(For each drug, create a subsection `### Drug Name`. Summarize its side effects and any recalls.)
|
103 |
{safety_data if safety_data else "No individual safety profiles were found."}
|
104 |
|
105 |
+
---
|
106 |
+
|
107 |
+
## Questions For Your Pharmacist or Doctor
|
108 |
+
(This section is mandatory. Based on the briefing, generate 2-3 specific questions. For example: "Given the reported side effect of nausea with Ozempic, are there strategies to manage this if it occurs?" or "You've prescribed X, and I also take Tylenol. Is there anything I should watch out for?")
|
109 |
+
|
110 |
+
**Begin your safety briefing now.**
|
111 |
"""
|