File size: 3,056 Bytes
f91e0d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Prompt Loader - Loads system prompts from markdown files.

This module provides a centralized way to load prompts from external files
while maintaining backward compatibility with the Customize AI Prompts feature.
"""

import os
from pathlib import Path
from typing import Dict, Optional

# Base directory for prompt files
PROMPTS_DIR = Path(__file__).parent / "prompts"


def load_prompt_from_file(filename: str) -> str:
    """
    Load a prompt from a file.
    
    Args:
        filename: Name of the prompt file (e.g., "spiritual_monitor.txt")
        
    Returns:
        Content of the prompt file as a string
        
    Raises:
        FileNotFoundError: If the prompt file doesn't exist
    """
    filepath = PROMPTS_DIR / filename
    
    if not filepath.exists():
        raise FileNotFoundError(f"Prompt file not found: {filepath}")
    
    with open(filepath, 'r', encoding='utf-8') as f:
        return f.read()


def load_all_spiritual_prompts() -> Dict[str, str]:
    """
    Load all spiritual-related prompts.
    
    Returns:
        Dictionary mapping prompt names to their content
    """
    prompts = {}
    
    try:
        prompts['spiritual_monitor'] = load_prompt_from_file('spiritual_monitor.txt')
    except FileNotFoundError:
        prompts['spiritual_monitor'] = ""
    
    try:
        prompts['triage_question'] = load_prompt_from_file('triage_question.txt')
    except FileNotFoundError:
        prompts['triage_question'] = ""
    
    try:
        prompts['triage_evaluator'] = load_prompt_from_file('triage_evaluator.txt')
    except FileNotFoundError:
        prompts['triage_evaluator'] = ""
    
    return prompts


def load_all_medical_prompts() -> Dict[str, str]:
    """
    Load all medical-related prompts.
    
    Returns:
        Dictionary mapping prompt names to their content
    """
    prompts = {}
    
    try:
        prompts['medical_assistant'] = load_prompt_from_file('medical_assistant.txt')
    except FileNotFoundError:
        prompts['medical_assistant'] = ""
    
    try:
        prompts['soft_medical_triage'] = load_prompt_from_file('soft_medical_triage.txt')
    except FileNotFoundError:
        prompts['soft_medical_triage'] = ""
    
    return prompts


# Cache for loaded prompts to avoid repeated file I/O
_prompt_cache: Optional[Dict[str, str]] = None


def get_cached_prompts() -> Dict[str, str]:
    """
    Get cached prompts, loading them if necessary.
    
    Returns:
        Dictionary of all loaded prompts
    """
    global _prompt_cache
    
    if _prompt_cache is None:
        _prompt_cache = {}
        _prompt_cache.update(load_all_spiritual_prompts())
        _prompt_cache.update(load_all_medical_prompts())
    
    return _prompt_cache


def reload_prompts() -> Dict[str, str]:
    """
    Force reload of all prompts from files.
    
    Useful for development or when prompts are updated.
    
    Returns:
        Dictionary of all reloaded prompts
    """
    global _prompt_cache
    _prompt_cache = None
    return get_cached_prompts()