Spaces:
Sleeping
Sleeping
File size: 11,487 Bytes
24214fc |
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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
#!/usr/bin/env python3
"""
Script to update triage_evaluator.txt to use shared components for consistency.
"""
import sys
import os
sys.path.append('src')
from config.prompt_management.prompt_integration import create_integrator
from config.prompt_loader import PROMPTS_DIR
def update_triage_evaluator():
"""Update triage_evaluator.txt to use shared components."""
print("Updating triage_evaluator.txt for consistency with shared components...")
# Create integrator
integrator = create_integrator()
# Validate current integration
print("\n1. Validating current integration...")
validation = integrator.validate_prompt_integration('triage_evaluator')
print(f" Current indicators: {validation['indicator_count']}")
print(f" Current rules: {validation['rule_count']}")
print(f" Current templates: {validation['template_count']}")
# Read current prompt file
print("\n2. Reading current prompt file...")
filepath = PROMPTS_DIR / "triage_evaluator.txt"
with open(filepath, 'r', encoding='utf-8') as f:
original_content = f.read()
print(f" Original file size: {len(original_content)} characters")
# Generate categories section from shared components
print("\n3. Generating consistent categories section...")
categories_section = integrator.generate_categories_section()
# Generate indicators section for RED category
print("\n4. Generating indicators section...")
indicators_section = integrator.generate_indicators_section()
# Create updated content with shared components
print("\n5. Creating updated content...")
# Build new content with shared components
updated_content = f"""<system_role>
You are evaluating a patient's response during a gentle wellness check. Based on the patient's response, determine the appropriate outcome to guide next steps.
IMPORTANT: You have access to the full classification definitions to make accurate decisions.
</system_role>
<shared_categories>
{categories_section}
</shared_categories>
<shared_indicators>
{indicators_section}
</shared_indicators>
<outcome_categories>
<outcome name="RESOLVED_GREEN" action="return_to_medical">
<description>Patient's response indicates NO spiritual/emotional distress - situation is due to external factors</description>
<indicators>
- External causes identified: time constraints, routine changes, medical symptoms without emotional component
- Patient mentions coping strategies or support from others
- Describes temporary stress that is manageable
- Reports feeling better or having resources
- Shows resilience or positive outlook
- Concern is logistical/practical, not emotional/spiritual
</indicators>
<examples>
"I'm just having a bad day, but I have my family to talk to"
"It's been tough, but I'm managing with my therapist's help"
"I haven't been sleeping well because of my medication schedule"
"I'm just busy with appointments, that's why I'm stressed"
"My routine changed because of the treatment, but I'm adjusting"
</examples>
</outcome>
<outcome name="ESCALATE_RED" action="generate_referral">
<description>Patient's response indicates CLEAR emotional/spiritual distress requiring support - not just normal stress or worry</description>
<indicators>
- EXPLICIT loss of meaning, purpose, or hope expressed
- Profound sadness, despair, grief that is affecting daily functioning
- Spiritual distress (anger at God, questioning faith with emotional pain)
- Identity disruption or loss of self ("I don't know who I am anymore")
- Persistent hopelessness without relief
- Complete isolation combined with distress (not just being alone)
- Inability to cope or function normally
- Worsening symptoms or deterioration over time
- Crisis language (wanting to give up, can't go on)
- Patient with EXPLICITLY MENTIONED mental health condition expressing emotional distress
- Anticipatory emotional response causing CLEAR suffering (not just normal concern about future)
</indicators>
<examples>
"I feel completely alone and nothing helps anymore"
"Every day is worse, I can't see a way forward"
"I don't know who I am anymore since the diagnosis"
"What's the point of any of this?"
"I feel like God has abandoned me"
"I'm so sad all the time, I can't enjoy anything"
"I'm terrified about what's going to happen and can't stop thinking about it"
"I've lost all hope"
"Nothing brings me joy anymore"
</examples>
<not_escalate_examples>
DO NOT escalate for these - they need clarification (CONTINUE):
- "I feel some stress" (ask: what's causing it?)
- "I'm worried" (ask: what about?)
- "Things are hard" (ask: in what way?)
- "I'm not sleeping well" (could be medical - ask more)
</not_escalate_examples>
</outcome>
<outcome name="CONTINUE" action="ask_another_question">
<description>Response is still ambiguous - need more information to determine if distress is present or what's causing it</description>
<indicators>
- Vague or unclear response that doesn't clarify cause
- Patient mentions stress/worry/difficulty without explaining the source
- Patient deflecting or avoiding the question
- Mixed signals that need exploration
- Cannot determine if external factors or emotional distress
- General statements about feeling stressed without context
</indicators>
<examples>
"I don't know, it's complicated"
"Maybe, I'm not sure"
"Things are just different now"
"I feel some stress" (need to ask: what's causing the stress?)
"I'm a bit worried" (need to ask: what are you worried about?)
"It's been difficult lately" (need to ask: what's making it difficult?)
"I'm not feeling great" (need to ask: can you tell me more?)
</examples>
</outcome>
</outcome_categories>
<yellow_flow_logic>
CRITICAL: The purpose of triage is to CLARIFY ambiguity - to determine if the situation is caused by or is causing emotional/spiritual distress, OR if it's due to external factors.
Apply these rules IN ORDER:
1. If patient's response indicates EXTERNAL CAUSES (time constraints, routine changes, medical symptoms, logistics, temporary circumstances) β RESOLVED_GREEN
Examples: "I'm stressed because of work deadlines", "It's just the medication schedule", "I'm busy with appointments"
2. If patient's response indicates CLEAR EMOTIONAL/SPIRITUAL DISTRESS (loss of meaning, profound sadness, despair, grief affecting functioning, spiritual pain, hopelessness) β ESCALATE_RED
Examples: "I feel completely alone", "Nothing has meaning anymore", "I can't see a way forward", "God has abandoned me"
3. If patient mentions stress/worry/difficulty WITHOUT specifying the cause β CONTINUE (ask what's causing it)
Examples: "I feel some stress", "Things are difficult", "I'm a bit worried" - these need clarification about the CAUSE
4. If patient with EXPLICITLY KNOWN mental health condition (mentioned in conversation) expresses emotional distress β ESCALATE_RED
5. If patient expresses anticipatory emotional response causing CLEAR suffering (not just normal concern) β ESCALATE_RED
6. If response is still ambiguous after clarification and you cannot determine if distress is present β CONTINUE (if questions remain)
IMPORTANT: Do NOT escalate to RED just because patient mentions "stress" or "worry" - these are normal human experiences. You MUST first clarify if the stress is:
- Due to external/temporary factors β GREEN
- Causing emotional/spiritual suffering β RED
</yellow_flow_logic>
<evaluation_process>
<step>Review the patient's response carefully</step>
<step>Identify if response indicates EXTERNAL causes (β GREEN) or EMOTIONAL/SPIRITUAL distress (β RED)</step>
<step>Apply the yellow_flow_logic rules</step>
<step>If still ambiguous and questions remain, choose CONTINUE</step>
<step>Assess confidence in your determination</step>
</evaluation_process>
<output_format>
Respond ONLY with valid JSON in this exact format:
{{
"outcome": "resolved_green" | "escalate_red" | "continue",
"indicators": ["indicator1", "indicator2"],
"reasoning": "Brief explanation of why you chose this outcome based on the classification definitions",
"confidence": 0.0-1.0
}}
Do not include any text before or after the JSON object.
</output_format>"""
print(f" Updated file size: {len(updated_content)} characters")
# Ask for confirmation
print("\n6. Ready to update the file.")
print(" This will:")
print(" - Create a backup of the original file")
print(" - Update the file with shared components")
print(" - Maintain all existing functionality")
print(" - Ensure consistency with spiritual_monitor.txt")
response = input("\nProceed with update? (y/N): ").strip().lower()
if response != 'y':
print("Update cancelled.")
return False
# Create backup
print("\n7. Creating backup and updating file...")
from datetime import datetime
backup_path = filepath.with_suffix(f".backup.{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt")
with open(backup_path, 'w', encoding='utf-8') as f:
f.write(original_content)
print(f" Backup created: {backup_path}")
# Write updated content
with open(filepath, 'w', encoding='utf-8') as f:
f.write(updated_content)
print(f" Updated file: {filepath}")
# Validate the update
print("\n8. Validating updated integration...")
new_validation = integrator.validate_prompt_integration('triage_evaluator')
print(f" Updated indicators: {new_validation['indicator_count']}")
print(f" Updated rules: {new_validation['rule_count']}")
print(f" Updated templates: {new_validation['template_count']}")
# Test that the prompt can be loaded
print("\n9. Testing prompt loading...")
try:
config = integrator.controller.get_prompt('triage_evaluator')
print(f" β Prompt loaded successfully")
print(f" β Base prompt: {len(config.base_prompt)} characters")
print(f" β Shared indicators: {len(config.shared_indicators)}")
print(f" β Shared rules: {len(config.shared_rules)}")
except Exception as e:
print(f" β Error loading prompt: {e}")
return False
# Test consistency with spiritual_monitor
print("\n10. Testing consistency with spiritual_monitor...")
spiritual_config = integrator.controller.get_prompt('spiritual_monitor')
# Check indicator consistency
evaluator_indicators = {ind.name for ind in config.shared_indicators}
spiritual_indicators = {ind.name for ind in spiritual_config.shared_indicators}
if evaluator_indicators == spiritual_indicators:
print(f" β Indicator consistency: {len(evaluator_indicators)} indicators")
else:
print(" β Indicator inconsistency detected")
return False
# Check rule consistency
evaluator_rules = {rule.rule_id for rule in config.shared_rules}
spiritual_rules = {rule.rule_id for rule in spiritual_config.shared_rules}
if evaluator_rules == spiritual_rules:
print(f" β Rule consistency: {len(evaluator_rules)} rules")
else:
print(" β Rule inconsistency detected")
return False
print("\nβ triage_evaluator.txt update completed successfully!")
print("β Consistency with spiritual_monitor.txt verified!")
return True
if __name__ == "__main__":
success = update_triage_evaluator()
sys.exit(0 if success else 1) |