File size: 5,223 Bytes
0176a31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Script to export agent and validation prompts to a Word document.
"""
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 create_prompts_document():
    """Create a Word document with both prompts."""
    
    # Create a new Document
    doc = Document()
    
    # Add title
    title = doc.add_heading('Medical AI System Prompts', 0)
    title.alignment = WD_ALIGN_PARAGRAPH.CENTER
    
    # Add metadata
    metadata = doc.add_paragraph()
    metadata.add_run('Project: Medical Clinical Decision Support System\n').bold = True
    metadata.add_run('Generated: October 19, 2025\n')
    metadata.add_run('Description: This document contains the system prompts used by the medical AI assistant.')
    
    doc.add_page_break()
    
    # ==================== AGENT PROMPT ====================
    doc.add_heading('1. 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('2. 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 = 'Medical_AI_System_Prompts.docx'
    doc.save(output_path)
    print(f"✓ Document created successfully: {output_path}")
    print(f"✓ File location: {os.path.abspath(output_path)}")
    
    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()