Spaces:
Running
Running
YanBoChen
commited on
Commit
Β·
1d18d66
1
Parent(s):
9b1dc9a
refactor: enhance example queries and prompt structure for improved medical guidance clarity
Browse files- app.py +16 -5
- src/generation.py +20 -16
app.py
CHANGED
|
@@ -422,13 +422,24 @@ def create_oncall_interface():
|
|
| 422 |
|
| 423 |
submit_btn = gr.Button("π Get Medical Guidance", variant="primary", size="lg")
|
| 424 |
|
| 425 |
-
# Example queries
|
| 426 |
gr.Markdown("""
|
| 427 |
### π‘ Example Queries
|
| 428 |
-
|
| 429 |
-
-
|
| 430 |
-
- "
|
| 431 |
-
- "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
""")
|
| 433 |
|
| 434 |
# Output sections
|
|
|
|
| 422 |
|
| 423 |
submit_btn = gr.Button("π Get Medical Guidance", variant="primary", size="lg")
|
| 424 |
|
| 425 |
+
# Example queries with categorization
|
| 426 |
gr.Markdown("""
|
| 427 |
### π‘ Example Queries
|
| 428 |
+
|
| 429 |
+
**π¬ Diagnosis-Focused (Recommended - Faster Response):**
|
| 430 |
+
- "60-year-old patient with hypertension history, sudden chest pain. What are possible causes and how to assess?"
|
| 431 |
+
- "30-year-old presents with sudden severe headache and neck stiffness. Differential diagnosis?"
|
| 432 |
+
- "Patient with acute shortness of breath and leg swelling. What should I consider?"
|
| 433 |
+
|
| 434 |
+
**βοΈ Treatment-Focused (Recommended - Faster Response):**
|
| 435 |
+
- "Suspected acute hemorrhagic stroke. Tell me the next steps to take."
|
| 436 |
+
- "Confirmed STEMI patient in ED. What is the immediate management protocol?"
|
| 437 |
+
- "Patient with anaphylaxis reaction. What is the treatment approach?"
|
| 438 |
+
|
| 439 |
+
**π Combined Queries (Longer Response Time - Less Recommended):**
|
| 440 |
+
- "20-year-old female, no medical history, sudden seizure. What are possible causes and complete management workflow?"
|
| 441 |
+
|
| 442 |
+
*Note: For optimal query efficiency, it's recommended to separate diagnostic assessment and treatment management questions.*
|
| 443 |
""")
|
| 444 |
|
| 445 |
# Output sections
|
src/generation.py
CHANGED
|
@@ -252,8 +252,8 @@ class MedicalAdviceGenerator:
|
|
| 252 |
|
| 253 |
# Format each chunk with metadata
|
| 254 |
context_part = f"""
|
| 255 |
-
[Guideline {i}] (Source: {chunk_type.title()}, Relevance: {1-distance:.3f})
|
| 256 |
-
{chunk_text}
|
| 257 |
""".strip()
|
| 258 |
|
| 259 |
context_parts.append(context_part)
|
|
@@ -283,24 +283,28 @@ class MedicalAdviceGenerator:
|
|
| 283 |
else:
|
| 284 |
focus_guidance = "Provide comprehensive medical guidance covering both diagnostic and treatment aspects as appropriate."
|
| 285 |
|
| 286 |
-
prompt = f"""
|
|
|
|
| 287 |
|
| 288 |
-
Clinical Question:
|
| 289 |
-
{user_query}
|
| 290 |
|
| 291 |
-
Relevant Medical Guidelines:
|
| 292 |
-
{context_block}
|
| 293 |
|
| 294 |
-
Instructions:
|
| 295 |
-
{focus_guidance}
|
| 296 |
|
| 297 |
-
|
| 298 |
-
1.
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
|
|
|
| 302 |
|
| 303 |
-
|
|
|
|
|
|
|
| 304 |
|
| 305 |
return prompt
|
| 306 |
|
|
@@ -319,7 +323,7 @@ Your response should be concise but comprehensive, suitable for immediate clinic
|
|
| 319 |
|
| 320 |
result = self.llm_client.analyze_medical_query(
|
| 321 |
query=prompt,
|
| 322 |
-
max_tokens=
|
| 323 |
timeout=30.0 # Allow more time for complex medical advice
|
| 324 |
)
|
| 325 |
|
|
|
|
| 252 |
|
| 253 |
# Format each chunk with metadata
|
| 254 |
context_part = f"""
|
| 255 |
+
[Guideline {i}] (Source: {chunk_type.title()}, Relevance: {1-distance:.3f})
|
| 256 |
+
{chunk_text}
|
| 257 |
""".strip()
|
| 258 |
|
| 259 |
context_parts.append(context_part)
|
|
|
|
| 283 |
else:
|
| 284 |
focus_guidance = "Provide comprehensive medical guidance covering both diagnostic and treatment aspects as appropriate."
|
| 285 |
|
| 286 |
+
prompt = f"""
|
| 287 |
+
You are an experienced attending physician providing guidance to a junior clinician in an emergency setting. A colleague is asking for your expert medical opinion.
|
| 288 |
|
| 289 |
+
Clinical Question:
|
| 290 |
+
{user_query}
|
| 291 |
|
| 292 |
+
Relevant Medical Guidelines:
|
| 293 |
+
{context_block}
|
| 294 |
|
| 295 |
+
Instructions:
|
| 296 |
+
{focus_guidance}
|
| 297 |
|
| 298 |
+
Provide guidance with:
|
| 299 |
+
β’ Numbered points (1. 2. 3.) for key steps
|
| 300 |
+
β’ Line breaks between major sections
|
| 301 |
+
β’ Highlight medications with dosages and routes
|
| 302 |
+
β’ Reference evidence from above sources
|
| 303 |
+
β’ Emphasize clinical judgment
|
| 304 |
|
| 305 |
+
IMPORTANT: Keep response within 700 tokens. If approaching this limit, prioritize the most critical steps and conclude with a brief summary of remaining considerations.
|
| 306 |
+
|
| 307 |
+
Your response should be concise but comprehensive, suitable for immediate clinical application with appropriate medical caution."""
|
| 308 |
|
| 309 |
return prompt
|
| 310 |
|
|
|
|
| 323 |
|
| 324 |
result = self.llm_client.analyze_medical_query(
|
| 325 |
query=prompt,
|
| 326 |
+
max_tokens=800, # Adjust based on needs
|
| 327 |
timeout=30.0 # Allow more time for complex medical advice
|
| 328 |
)
|
| 329 |
|