Spaces:
Sleeping
Sleeping
File size: 8,262 Bytes
73c6377 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
"""
Script to export all prompts used in the HBV AI Assistant project to a Word document.
Includes: Agent System Prompt, Validation Prompt, and HBV Assessment Prompt.
"""
from docx import Document
from docx.shared import Pt, RGBColor, Inches
from docx.enum.text import WD_ALIGN_PARAGRAPH
import sys
import os
import re
# Add the project root to the path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def extract_system_message_from_agent():
"""Extract SYSTEM_MESSAGE from core/agent.py without importing it."""
agent_path = os.path.join(os.path.dirname(__file__), 'core', 'agent.py')
with open(agent_path, 'r', encoding='utf-8') as f:
content = f.read()
# Extract SYSTEM_MESSAGE using regex
match = re.search(r'SYSTEM_MESSAGE = """(.*?)"""', content, re.DOTALL)
if match:
return match.group(1).strip()
else:
raise ValueError("Could not extract SYSTEM_MESSAGE from core/agent.py")
def extract_validation_prompt():
"""Extract validation prompt from core/validation.py without importing it."""
validation_path = os.path.join(os.path.dirname(__file__), 'core', 'validation.py')
with open(validation_path, 'r', encoding='utf-8') as f:
content = f.read()
# Find the _create_validation_system_prompt method and extract the return string
match = re.search(r'def _create_validation_system_prompt\(self\) -> str:.*?return """(.*?)"""', content, re.DOTALL)
if match:
return match.group(1).strip()
else:
raise ValueError("Could not extract validation prompt from core/validation.py")
def extract_hbv_assessment_prompt():
"""Extract HBV assessment prompt from core/hbv_assessment.py without importing it."""
assessment_path = os.path.join(os.path.dirname(__file__), 'core', 'hbv_assessment.py')
with open(assessment_path, 'r', encoding='utf-8') as f:
content = f.read()
# Find the analysis_prompt in assess_hbv_eligibility function
match = re.search(r'analysis_prompt = f"""(.*?)"""', content, re.DOTALL)
if match:
# Extract the prompt template (without f-string variables)
prompt_template = match.group(1).strip()
return prompt_template
else:
raise ValueError("Could not extract HBV assessment prompt from core/hbv_assessment.py")
def create_prompts_document():
"""Create a Word document with both prompts."""
# Create a new Document
doc = Document()
# Add title
title = doc.add_heading('HBV AI Assistant - System Prompts', 0)
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
# Add metadata
metadata = doc.add_paragraph()
metadata.add_run('Project: HBV Clinical Decision Support System\n').bold = True
metadata.add_run('Generated: October 30, 2025\n')
metadata.add_run('Description: This document contains all system prompts used by the HBV AI Assistant, including the main agent prompt, validation prompt, and HBV assessment prompt.')
doc.add_page_break()
# ==================== HBV ASSESSMENT PROMPT ====================
doc.add_heading('1. HBV Assessment System Prompt', 1)
# Add description
desc3 = doc.add_paragraph()
desc3.add_run('Purpose: ').bold = True
desc3.add_run('Evaluates patient eligibility for HBV treatment based on SASLT 2021 guidelines\n')
desc3.add_run('Location: ').bold = True
desc3.add_run('core/hbv_assessment.py\n')
desc3.add_run('Model: ').bold = True
desc3.add_run('GPT-4 (configurable)\n')
desc3.add_run('Function: ').bold = True
desc3.add_run('assess_hbv_eligibility()')
doc.add_paragraph() # Spacing
# Add assessment overview
doc.add_heading('Assessment Process:', 2)
process = doc.add_paragraph()
process.add_run('The HBV assessment prompt analyzes patient data against SASLT 2021 guidelines:\n')
process_list = [
'Evaluates patient parameters (HBV DNA, ALT, fibrosis stage, etc.)',
'Compares against treatment eligibility criteria from SASLT 2021',
'Determines eligibility status (Eligible/Not Eligible/Borderline)',
'Recommends first-line antiviral agents (ETV, TDF, TAF) if eligible',
'Provides comprehensive assessment with inline citations',
'Includes special considerations (pregnancy, immunosuppression, coinfections)'
]
for item in process_list:
doc.add_paragraph(item, style='List Bullet')
doc.add_paragraph() # Spacing
# Add the actual HBV assessment prompt
doc.add_heading('Prompt Content:', 2)
hbv_assessment_prompt = extract_hbv_assessment_prompt()
assessment_para = doc.add_paragraph(hbv_assessment_prompt)
assessment_para.style = 'Normal'
# Format the assessment prompt text
for run in assessment_para.runs:
run.font.size = Pt(10)
run.font.name = 'Courier New'
doc.add_page_break()
# ==================== AGENT PROMPT ====================
doc.add_heading('2. Agent System Prompt', 1)
# Add description
desc1 = doc.add_paragraph()
desc1.add_run('Purpose: ').bold = True
desc1.add_run('Main conversational AI agent for clinical decision support\n')
desc1.add_run('Location: ').bold = True
desc1.add_run('core/agent.py\n')
desc1.add_run('Model: ').bold = True
desc1.add_run('GPT-4 (configurable)')
doc.add_paragraph() # Spacing
# Add the actual prompt
doc.add_heading('Prompt Content:', 2)
system_message = extract_system_message_from_agent()
prompt_para = doc.add_paragraph(system_message)
prompt_para.style = 'Normal'
# Format the prompt text
for run in prompt_para.runs:
run.font.size = Pt(10)
run.font.name = 'Courier New'
doc.add_page_break()
# ==================== VALIDATION PROMPT ====================
doc.add_heading('3. Validation System Prompt', 1)
# Add description
desc2 = doc.add_paragraph()
desc2.add_run('Purpose: ').bold = True
desc2.add_run('Validates generated medical answers for quality assurance\n')
desc2.add_run('Location: ').bold = True
desc2.add_run('core/validation.py\n')
desc2.add_run('Model: ').bold = True
desc2.add_run('GPT-4o')
doc.add_paragraph() # Spacing
# Add validation criteria overview
doc.add_heading('Validation Criteria:', 2)
criteria = doc.add_paragraph()
criteria.add_run('The validation prompt evaluates answers on 6 dimensions:\n')
criteria_list = [
'Accuracy (0-100%): Factual correctness based on provided documents',
'Coherence (0-100%): Logical structure, clarity, and readability',
'Relevance (0-100%): Addresses user\'s question without off-topic information',
'Completeness (0-100%): Includes all necessary information from documents',
'Citations/Attribution (0-100%): Proper citation of all claims',
'Length (0-100%): Appropriate detail without being too brief or verbose'
]
for criterion in criteria_list:
doc.add_paragraph(criterion, style='List Bullet')
doc.add_paragraph() # Spacing
# Add the actual validation prompt
doc.add_heading('Prompt Content:', 2)
validation_prompt = extract_validation_prompt()
validation_para = doc.add_paragraph(validation_prompt)
validation_para.style = 'Normal'
# Format the validation prompt text
for run in validation_para.runs:
run.font.size = Pt(10)
run.font.name = 'Courier New'
# Save the document
output_path = 'HBV_AI_Assistant_System_Prompts.docx'
doc.save(output_path)
print(f"β Document created successfully: {output_path}")
print(f"β File location: {os.path.abspath(output_path)}")
print(f"\nπ Exported Prompts:")
print(f" 1. HBV Assessment Prompt (core/hbv_assessment.py)")
print(f" 2. Agent System Prompt (core/agent.py)")
print(f" 3. Validation System Prompt (core/validation.py)")
return output_path
if __name__ == "__main__":
try:
create_prompts_document()
except Exception as e:
print(f"β Error creating document: {str(e)}")
import traceback
traceback.print_exc()
|