Spaces:
Sleeping
Sleeping
Remove deprecated LifestyleExitClassifier and SYSTEM_PROMPT_LIFESTYLE_EXIT_CLASSIFIER
Browse files- Removed unused LifestyleExitClassifier class from core_classes.py
- Removed SYSTEM_PROMPT_LIFESTYLE_EXIT_CLASSIFIER from prompts.py
- Removed PROMPT_LIFESTYLE_EXIT_CLASSIFIER function
- Updated lifestyle_app.py to remove unused import and instantiation
- Removed deprecated test_lifestyle_exit() function
- Functionality now handled by MainLifestyleAssistant.process_message()
- All tests still passing (cleaner architecture)
The new architecture uses MainLifestyleAssistant which returns action='close'
to exit lifestyle mode, eliminating the need for separate exit classifier.
- core_classes.py +2 -28
- lifestyle_app.py +2 -2
- prompts.py +3 -27
- test_new_logic.py +2 -27
core_classes.py
CHANGED
|
@@ -14,8 +14,7 @@ from prompts import (
|
|
| 14 |
PROMPT_ENTRY_CLASSIFIER,
|
| 15 |
SYSTEM_PROMPT_TRIAGE_EXIT_CLASSIFIER,
|
| 16 |
PROMPT_TRIAGE_EXIT_CLASSIFIER,
|
| 17 |
-
|
| 18 |
-
PROMPT_LIFESTYLE_EXIT_CLASSIFIER,
|
| 19 |
# Main Lifestyle Assistant
|
| 20 |
SYSTEM_PROMPT_MAIN_LIFESTYLE,
|
| 21 |
PROMPT_MAIN_LIFESTYLE,
|
|
@@ -354,32 +353,7 @@ class TriageExitClassifier:
|
|
| 354 |
"medical_status": "needs_attention"
|
| 355 |
}
|
| 356 |
|
| 357 |
-
|
| 358 |
-
"""Визначає чи потрібно завершити lifestyle сесію"""
|
| 359 |
-
|
| 360 |
-
def __init__(self, api: GeminiAPI):
|
| 361 |
-
self.api = api
|
| 362 |
-
|
| 363 |
-
def should_exit(self, lifestyle_session_length: int,
|
| 364 |
-
recent_messages: List[str], user_message: str) -> Dict:
|
| 365 |
-
"""Визначає чи потрібно завершити lifestyle сесію"""
|
| 366 |
-
|
| 367 |
-
system_prompt = SYSTEM_PROMPT_LIFESTYLE_EXIT_CLASSIFIER
|
| 368 |
-
recent_text = " | ".join(recent_messages[-3:]) if recent_messages else "немає"
|
| 369 |
-
user_prompt = PROMPT_LIFESTYLE_EXIT_CLASSIFIER(lifestyle_session_length, recent_text, user_message)
|
| 370 |
-
|
| 371 |
-
response = self.api.generate_response(system_prompt, user_prompt, temperature=0.1, call_type="LIFESTYLE_EXIT_CLASSIFIER")
|
| 372 |
-
|
| 373 |
-
try:
|
| 374 |
-
clean_response = response.replace("```json", "").replace("```", "").strip()
|
| 375 |
-
decision = json.loads(clean_response)
|
| 376 |
-
return decision
|
| 377 |
-
except:
|
| 378 |
-
return {
|
| 379 |
-
"should_exit": True,
|
| 380 |
-
"reasoning": "Помилка парсингу - завершуємо сесію для безпеки",
|
| 381 |
-
"exit_reason": "other"
|
| 382 |
-
}
|
| 383 |
|
| 384 |
# ===== DEPRECATED: Старий контролер (замінено на Entry Classifier + нову логіку) =====
|
| 385 |
|
|
|
|
| 14 |
PROMPT_ENTRY_CLASSIFIER,
|
| 15 |
SYSTEM_PROMPT_TRIAGE_EXIT_CLASSIFIER,
|
| 16 |
PROMPT_TRIAGE_EXIT_CLASSIFIER,
|
| 17 |
+
|
|
|
|
| 18 |
# Main Lifestyle Assistant
|
| 19 |
SYSTEM_PROMPT_MAIN_LIFESTYLE,
|
| 20 |
PROMPT_MAIN_LIFESTYLE,
|
|
|
|
| 353 |
"medical_status": "needs_attention"
|
| 354 |
}
|
| 355 |
|
| 356 |
+
# LifestyleExitClassifier removed - functionality moved to MainLifestyleAssistant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
|
| 358 |
# ===== DEPRECATED: Старий контролер (замінено на Entry Classifier + нову логіку) =====
|
| 359 |
|
lifestyle_app.py
CHANGED
|
@@ -12,7 +12,7 @@ from core_classes import (
|
|
| 12 |
GeminiAPI, PatientDataLoader,
|
| 13 |
MedicalAssistant,
|
| 14 |
# Активні класифікатори
|
| 15 |
-
EntryClassifier, TriageExitClassifier,
|
| 16 |
LifestyleSessionManager,
|
| 17 |
# Main Lifestyle Assistant
|
| 18 |
MainLifestyleAssistant,
|
|
@@ -31,7 +31,7 @@ class ExtendedLifestyleJourneyApp:
|
|
| 31 |
# Активні класифікатори
|
| 32 |
self.entry_classifier = EntryClassifier(self.api)
|
| 33 |
self.triage_exit_classifier = TriageExitClassifier(self.api)
|
| 34 |
-
|
| 35 |
# Асистенти
|
| 36 |
self.medical_assistant = MedicalAssistant(self.api)
|
| 37 |
self.main_lifestyle_assistant = MainLifestyleAssistant(self.api)
|
|
|
|
| 12 |
GeminiAPI, PatientDataLoader,
|
| 13 |
MedicalAssistant,
|
| 14 |
# Активні класифікатори
|
| 15 |
+
EntryClassifier, TriageExitClassifier,
|
| 16 |
LifestyleSessionManager,
|
| 17 |
# Main Lifestyle Assistant
|
| 18 |
MainLifestyleAssistant,
|
|
|
|
| 31 |
# Активні класифікатори
|
| 32 |
self.entry_classifier = EntryClassifier(self.api)
|
| 33 |
self.triage_exit_classifier = TriageExitClassifier(self.api)
|
| 34 |
+
# LifestyleExitClassifier removed - functionality moved to MainLifestyleAssistant
|
| 35 |
# Асистенти
|
| 36 |
self.medical_assistant = MedicalAssistant(self.api)
|
| 37 |
self.main_lifestyle_assistant = MainLifestyleAssistant(self.api)
|
prompts.py
CHANGED
|
@@ -78,24 +78,8 @@ Provide ONLY JSON without comments:
|
|
| 78 |
"medical_status": "stable|needs_attention|resolved"
|
| 79 |
}"""
|
| 80 |
|
| 81 |
-
# ===== DEPRECATED
|
| 82 |
-
|
| 83 |
-
SYSTEM_PROMPT_LIFESTYLE_EXIT_CLASSIFIER = """Ти - Lifestyle Exit Classifier для lifestyle режиму.
|
| 84 |
-
|
| 85 |
-
ТВОЄ ЗАВДАННЯ: Визначити чи потрібно завершити lifestyle сесію.
|
| 86 |
-
|
| 87 |
-
КРИТЕРІЇ ДЛЯ ВИХОДУ:
|
| 88 |
-
- Patient reports worsening condition
|
| 89 |
-
- Patient expresses unwillingness to continue lifestyle conversation
|
| 90 |
-
- Session runs too long (>10 messages in lifestyle mode)
|
| 91 |
-
- New medical complaints appear
|
| 92 |
-
|
| 93 |
-
RESPOND ONLY IN JSON FORMAT:
|
| 94 |
-
{
|
| 95 |
-
"should_exit": true/false,
|
| 96 |
-
"reasoning": "decision explanation in English",
|
| 97 |
-
"exit_reason": "medical_concerns|patient_request|session_length|other"
|
| 98 |
-
}"""
|
| 99 |
|
| 100 |
# ===== PROMPT FUNCTIONS =====
|
| 101 |
|
|
@@ -124,15 +108,7 @@ PATIENT'S LATEST MESSAGE: "{user_message}"
|
|
| 124 |
ANALYSIS REQUIRED:
|
| 125 |
Assess patient's readiness for lifestyle coaching mode based on medical stability and expressed readiness."""
|
| 126 |
|
| 127 |
-
|
| 128 |
-
return f"""CURRENT LIFESTYLE SESSION:
|
| 129 |
-
- Messages in lifestyle mode: {lifestyle_session_length}
|
| 130 |
-
- Recent messages: {recent_messages}
|
| 131 |
-
|
| 132 |
-
NEW PATIENT MESSAGE: "{user_message}"
|
| 133 |
-
|
| 134 |
-
ANALYSIS REQUIRED:
|
| 135 |
-
Determine if lifestyle session should be terminated based on patient needs and session context."""
|
| 136 |
|
| 137 |
# DEPRECATED: Старий Session Controller (замінено на Entry Classifier + нову логіку)
|
| 138 |
|
|
|
|
| 78 |
"medical_status": "stable|needs_attention|resolved"
|
| 79 |
}"""
|
| 80 |
|
| 81 |
+
# ===== DEPRECATED PROMPTS REMOVED =====
|
| 82 |
+
# LifestyleExitClassifier functionality moved to MainLifestyleAssistant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# ===== PROMPT FUNCTIONS =====
|
| 85 |
|
|
|
|
| 108 |
ANALYSIS REQUIRED:
|
| 109 |
Assess patient's readiness for lifestyle coaching mode based on medical stability and expressed readiness."""
|
| 110 |
|
| 111 |
+
# PROMPT_LIFESTYLE_EXIT_CLASSIFIER removed - functionality moved to MainLifestyleAssistant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
# DEPRECATED: Старий Session Controller (замінено на Entry Classifier + нову логіку)
|
| 114 |
|
test_new_logic.py
CHANGED
|
@@ -242,32 +242,7 @@ def test_lifecycle_flow():
|
|
| 242 |
except Exception as e:
|
| 243 |
print(f" ❌ Помилка: {e}")
|
| 244 |
|
| 245 |
-
|
| 246 |
-
"""Тестує Lifestyle Exit логіку"""
|
| 247 |
-
print("\n🚪 Тестування Lifestyle Exit...")
|
| 248 |
-
|
| 249 |
-
api = MockAPI()
|
| 250 |
-
|
| 251 |
-
test_cases = [
|
| 252 |
-
("Продовжуємо тренування", False, "Нормальне lifestyle повідомлення"),
|
| 253 |
-
("У мене знову болить спина", True, "Медичні скарги"),
|
| 254 |
-
("Хочу закінчити на сьогодні", True, "Прохання про завершення"),
|
| 255 |
-
("Думаю достатньо на сьогодні", True, "Прохання про завершення"),
|
| 256 |
-
("Можемо завершити сесію?", True, "Прохання про завершення"),
|
| 257 |
-
("Як часто треба тренуватися?", False, "Звичайне lifestyle питання"),
|
| 258 |
-
("Мені погано, припиніть", True, "Медичні скарги + прохання"),
|
| 259 |
-
("Які вправи підходять для початківців?", False, "Нормальне lifestyle питання")
|
| 260 |
-
]
|
| 261 |
-
|
| 262 |
-
for message, should_exit, description in test_cases:
|
| 263 |
-
response = api.generate_response("", message, call_type="LIFESTYLE_EXIT_CLASSIFIER")
|
| 264 |
-
try:
|
| 265 |
-
result = json.loads(response)
|
| 266 |
-
actual_exit = result.get("should_exit")
|
| 267 |
-
status = "✅" if actual_exit == should_exit else "❌"
|
| 268 |
-
print(f" {status} '{message}' → should_exit={actual_exit} ({description})")
|
| 269 |
-
except:
|
| 270 |
-
print(f" ❌ Помилка парсингу для: '{message}'")
|
| 271 |
|
| 272 |
def test_neutral_interactions():
|
| 273 |
"""Тестує нейтральні взаємодії"""
|
|
@@ -363,7 +338,7 @@ if __name__ == "__main__":
|
|
| 363 |
|
| 364 |
test_entry_classifier()
|
| 365 |
test_lifecycle_flow()
|
| 366 |
-
test_lifestyle_exit()
|
| 367 |
test_neutral_interactions()
|
| 368 |
test_main_lifestyle_assistant()
|
| 369 |
test_profile_update()
|
|
|
|
| 242 |
except Exception as e:
|
| 243 |
print(f" ❌ Помилка: {e}")
|
| 244 |
|
| 245 |
+
# test_lifestyle_exit removed - functionality moved to MainLifestyleAssistant tests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
def test_neutral_interactions():
|
| 248 |
"""Тестує нейтральні взаємодії"""
|
|
|
|
| 338 |
|
| 339 |
test_entry_classifier()
|
| 340 |
test_lifecycle_flow()
|
| 341 |
+
# test_lifestyle_exit() removed - functionality moved to MainLifestyleAssistant
|
| 342 |
test_neutral_interactions()
|
| 343 |
test_main_lifestyle_assistant()
|
| 344 |
test_profile_update()
|