Spaces:
Running
Running
| """ | |
| 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() | |