Spaces:
Sleeping
Sleeping
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
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 |
-
|
| 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 |
-
#
|
| 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 |
-
|
|
|
|
| 94 |
|
| 95 |
-
# Enhanced information section
|
| 96 |
formatted_parts.append("\n\n---\n")
|
| 97 |
-
formatted_parts.append("### π **
|
| 98 |
|
| 99 |
-
# Safety and verification info
|
| 100 |
if response.verification_result:
|
| 101 |
-
|
| 102 |
-
formatted_parts.append(f"**
|
| 103 |
-
formatted_parts.append(f"
|
| 104 |
-
formatted_parts.append(f"
|
| 105 |
|
| 106 |
-
# Enhanced retrieval
|
| 107 |
-
formatted_parts.append(f"
|
| 108 |
-
formatted_parts.append(f"
|
| 109 |
-
formatted_parts.append(f"
|
| 110 |
-
|
| 111 |
-
formatted_parts.append(f"**β‘ Processing Time**: {response.query_time:.2f}s")
|
| 112 |
|
| 113 |
-
#
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|