sniro23 commited on
Commit
27da814
Β·
1 Parent(s): 72e11ad

fix: enhance citation display in response formatting

Browse files

- Always show numbered citations with [1], [2] format
- Improve source section visibility and organization
- Add clear section headers and better metrics display
- Enhance medical disclaimer formatting

Files changed (1) hide show
  1. app.py +25 -22
app.py CHANGED
@@ -79,40 +79,43 @@ def format_enhanced_medical_response(response: EnhancedMedicalResponse) -> str:
79
  formatted_parts = []
80
 
81
  # Main response from the LLM
82
- # The new prompt instructs the LLM to include markdown citations like [1], [2]
83
- # The final response text is now the primary source of the answer.
84
- final_response_text = response.answer
85
  formatted_parts.append(final_response_text)
86
 
87
- # Always add the clinical sources section if sources exist
88
  if response.sources:
89
  formatted_parts.append("\n\n---\n")
90
- formatted_parts.append("### πŸ“‹ **Clinical Sources**")
 
91
  # Create a numbered list of all sources used for the response
92
  for i, source in enumerate(response.sources, 1):
93
- formatted_parts.append(f"{i}. {source}")
 
94
 
95
- # Enhanced information section
96
  formatted_parts.append("\n\n---\n")
97
- formatted_parts.append("### πŸ“Š **Enhanced Medical Analysis**")
98
 
99
- # Safety and verification info
100
  if response.verification_result:
101
- safety_emoji = "πŸ›‘οΈ" if response.safety_status == "SAFE" else "⚠️"
102
- formatted_parts.append(f"**{safety_emoji} Medical Safety**: {response.safety_status}")
103
- formatted_parts.append(f"**πŸ” Verification Score**: {response.verification_result.verification_score:.1%}")
104
- formatted_parts.append(f"**βœ… Verified Claims**: {response.verification_result.verified_claims}/{response.verification_result.total_claims}")
105
 
106
- # Enhanced retrieval info
107
- formatted_parts.append(f"**🧠 Medical Entities Extracted**: {response.medical_entities_count}")
108
- formatted_parts.append(f"**🎯 Context Adherence**: {response.context_adherence_score:.1%}")
109
- formatted_parts.append(f"**πŸ“š Sources Used**: {len(response.sources)}")
110
- if hasattr(response, 'query_time'): # Changed from processing_time to match the object attribute
111
- formatted_parts.append(f"**⚑ Processing Time**: {response.query_time:.2f}s")
112
 
113
- # Medical disclaimer
114
- formatted_parts.append("\n---\n")
115
- formatted_parts.append("*This information is for clinical reference based on Sri Lankan guidelines and does not replace professional medical judgment.*")
 
 
 
 
116
 
117
  return "\n".join(formatted_parts)
118
 
 
79
  formatted_parts = []
80
 
81
  # Main response from the LLM
82
+ final_response_text = response.answer.strip()
 
 
83
  formatted_parts.append(final_response_text)
84
 
85
+ # ALWAYS add the clinical sources section with clear numbering
86
  if response.sources:
87
  formatted_parts.append("\n\n---\n")
88
+ formatted_parts.append("### πŸ“‹ **Clinical Sources & Citations**")
89
+ formatted_parts.append("\nThis response is based on the following Sri Lankan clinical guidelines:")
90
  # Create a numbered list of all sources used for the response
91
  for i, source in enumerate(response.sources, 1):
92
+ # Make the citation number bold and add a clear label
93
+ formatted_parts.append(f"\n**[{i}]** Source: {source}")
94
 
95
+ # Enhanced information section with clear separation
96
  formatted_parts.append("\n\n---\n")
97
+ formatted_parts.append("### πŸ“Š **Response Analysis**")
98
 
99
+ # Safety and verification info with clearer formatting
100
  if response.verification_result:
101
+ safety_status = "βœ… SAFE" if response.safety_status == "SAFE" else "⚠️ CAUTION"
102
+ formatted_parts.append(f"\n**Medical Safety Status**: {safety_status}")
103
+ formatted_parts.append(f"**Verification Score**: {response.verification_result.verification_score:.1%}")
104
+ formatted_parts.append(f"**Verified Medical Claims**: {response.verification_result.verified_claims}/{response.verification_result.total_claims}")
105
 
106
+ # Enhanced retrieval metrics
107
+ formatted_parts.append(f"\n**Medical Information Coverage**:")
108
+ formatted_parts.append(f"- 🧠 Medical Entities: {response.medical_entities_count}")
109
+ formatted_parts.append(f"- 🎯 Context Adherence: {response.context_adherence_score:.1%}")
110
+ formatted_parts.append(f"- πŸ“š Guidelines Referenced: {len(response.sources)}")
 
111
 
112
+ # Always include processing time if available
113
+ if hasattr(response, 'query_time'):
114
+ formatted_parts.append(f"- ⚑ Processing Time: {response.query_time:.2f}s")
115
+
116
+ # Medical disclaimer with clear separation
117
+ formatted_parts.append("\n\n---\n")
118
+ formatted_parts.append("*βš•οΈ This information is derived from Sri Lankan clinical guidelines and is for reference only. Always consult with qualified healthcare professionals for patient care decisions.*")
119
 
120
  return "\n".join(formatted_parts)
121