DocUA commited on
Commit
7fbff0e
·
1 Parent(s): 96e7507

fix: Fix Claude model name and add dynamic spiritual dialog response

Browse files

- Fixed Claude Sonnet 4.5 model name: claude-sonnet-4-5-20250929
- Added SYSTEM_PROMPT_SPIRITUAL_DIALOG and PROMPT_SPIRITUAL_DIALOG for natural responses
- SpiritualAssistant now generates LLM-based responses for no-flag cases
- Responses are now in patient's language (Ukrainian, English, etc.)
- Removed static English-only response template for no-flag cases

src/config/ai_providers_config.py CHANGED
@@ -24,7 +24,7 @@ class AIModel(Enum):
24
  GEMINI_1_5_PRO = "gemini-1.5-pro"
25
 
26
  # Anthropic models
27
- CLAUDE_SONNET_4_5 = "claude-sonnet-4.5-20250514"
28
  CLAUDE_SONNET_4 = "claude-sonnet-4-20250514"
29
  CLAUDE_SONNET_3_7 = "claude-3-7-sonnet-20250219"
30
  CLAUDE_SONNET_3_5 = "claude-3-5-sonnet-20241022"
 
24
  GEMINI_1_5_PRO = "gemini-1.5-pro"
25
 
26
  # Anthropic models
27
+ CLAUDE_SONNET_4_5 = "claude-sonnet-4-5-20250929"
28
  CLAUDE_SONNET_4 = "claude-sonnet-4-20250514"
29
  CLAUDE_SONNET_3_7 = "claude-3-7-sonnet-20250219"
30
  CLAUDE_SONNET_3_5 = "claude-3-5-sonnet-20241022"
src/core/spiritual_analyzer.py CHANGED
@@ -29,7 +29,9 @@ from src.prompts.spiritual_prompts import (
29
  SYSTEM_PROMPT_CLARIFYING_QUESTIONS,
30
  PROMPT_CLARIFYING_QUESTIONS,
31
  SYSTEM_PROMPT_REEVALUATION,
32
- PROMPT_REEVALUATION
 
 
33
  )
34
 
35
 
 
29
  SYSTEM_PROMPT_CLARIFYING_QUESTIONS,
30
  PROMPT_CLARIFYING_QUESTIONS,
31
  SYSTEM_PROMPT_REEVALUATION,
32
+ PROMPT_REEVALUATION,
33
+ SYSTEM_PROMPT_SPIRITUAL_DIALOG,
34
+ PROMPT_SPIRITUAL_DIALOG
35
  )
36
 
37
 
src/core/spiritual_assistant.py CHANGED
@@ -205,14 +205,14 @@ class SpiritualAssistant:
205
  """
206
  Handle no flag case - no significant spiritual distress.
207
 
208
- Generates supportive response.
209
 
210
  Requirements: 5.5
211
  """
212
- logger.info("Handling NO FLAG - generating supportive response")
213
 
214
- # Format supportive response
215
- response_message = self._format_no_flag_response(classification)
216
 
217
  return {
218
  "message": response_message,
@@ -223,6 +223,39 @@ class SpiritualAssistant:
223
  "reasoning": "No significant spiritual distress indicators detected"
224
  }
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  def _format_red_flag_response(
227
  self,
228
  classification: DistressClassification,
 
205
  """
206
  Handle no flag case - no significant spiritual distress.
207
 
208
+ Generates natural conversational response via LLM.
209
 
210
  Requirements: 5.5
211
  """
212
+ logger.info("Handling NO FLAG - generating conversational response")
213
 
214
+ # Generate natural response via LLM
215
+ response_message = self._generate_dialog_response(patient_input)
216
 
217
  return {
218
  "message": response_message,
 
223
  "reasoning": "No significant spiritual distress indicators detected"
224
  }
225
 
226
+ def _generate_dialog_response(self, patient_input: PatientInput) -> str:
227
+ """
228
+ Generate natural dialog response for no-flag cases.
229
+
230
+ Uses LLM to create a conversational response in the patient's language.
231
+ """
232
+ from src.prompts.spiritual_prompts import (
233
+ SYSTEM_PROMPT_SPIRITUAL_DIALOG,
234
+ PROMPT_SPIRITUAL_DIALOG
235
+ )
236
+
237
+ try:
238
+ system_prompt = SYSTEM_PROMPT_SPIRITUAL_DIALOG()
239
+ user_prompt = PROMPT_SPIRITUAL_DIALOG(
240
+ patient_input.message,
241
+ patient_input.conversation_history
242
+ )
243
+
244
+ response = self.api.generate_response(
245
+ system_prompt=system_prompt,
246
+ user_prompt=user_prompt,
247
+ temperature=0.4,
248
+ call_type="SPIRITUAL_DIALOG",
249
+ agent_name="SpiritualDistressAnalyzer"
250
+ )
251
+
252
+ return response.strip()
253
+
254
+ except Exception as e:
255
+ logger.error(f"Error generating dialog response: {e}")
256
+ # Fallback to static response
257
+ return self._format_no_flag_response(classification=None)
258
+
259
  def _format_red_flag_response(
260
  self,
261
  classification: DistressClassification,
src/prompts/spiritual_prompts.py CHANGED
@@ -472,3 +472,75 @@ CRITICAL RULES:
472
  4. Provide clear reasoning based on how the follow-up information resolved the ambiguity
473
 
474
  Analyze the complete conversation and respond with JSON only."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
472
  4. Provide clear reasoning based on how the follow-up information resolved the ambiguity
473
 
474
  Analyze the complete conversation and respond with JSON only."""
475
+
476
+
477
+ def SYSTEM_PROMPT_SPIRITUAL_DIALOG() -> str:
478
+ """
479
+ System prompt for spiritual dialog response generation.
480
+ Used when no distress is detected to generate a natural, supportive response.
481
+ """
482
+ return """You are a compassionate spiritual care assistant who provides supportive, empathetic responses to patients.
483
+
484
+ Your role is to:
485
+ 1. Engage naturally with patients about spiritual and emotional topics
486
+ 2. Provide warm, supportive responses without being preachy or assumptive
487
+ 3. Respect diverse spiritual backgrounds and beliefs
488
+ 4. Offer to discuss spiritual topics if the patient is interested
489
+
490
+ RESPONSE GUIDELINES:
491
+
492
+ TONE:
493
+ - Warm, friendly, and conversational
494
+ - Non-judgmental and accepting
495
+ - Supportive without being intrusive
496
+ - Natural and human-like
497
+
498
+ MULTI-FAITH SENSITIVITY:
499
+ - Do NOT assume any particular religious beliefs
500
+ - Use inclusive language (spiritual, meaningful, values, beliefs)
501
+ - Respect all backgrounds: religious, secular, atheist, agnostic
502
+ - Let the patient lead the conversation about their beliefs
503
+
504
+ CONTENT:
505
+ - Respond directly to what the patient said
506
+ - Ask open-ended questions to understand their interests
507
+ - Offer support without pushing spiritual care services
508
+ - Keep responses concise and natural
509
+
510
+ IMPORTANT: Always respond in the same language as the patient's message (English, Ukrainian, etc.)."""
511
+
512
+
513
+ def PROMPT_SPIRITUAL_DIALOG(
514
+ patient_message: str,
515
+ conversation_history: List[str] = None
516
+ ) -> str:
517
+ """
518
+ User prompt for generating natural spiritual dialog response.
519
+
520
+ Args:
521
+ patient_message: The patient's message
522
+ conversation_history: Optional conversation history
523
+
524
+ Returns:
525
+ Formatted prompt string
526
+ """
527
+ history_text = ""
528
+ if conversation_history and len(conversation_history) > 0:
529
+ recent_history = conversation_history[-3:]
530
+ history_text = "\nRECENT CONVERSATION:\n" + "\n".join([f"- {msg}" for msg in recent_history])
531
+
532
+ return f"""PATIENT MESSAGE:
533
+ "{patient_message}"
534
+ {history_text}
535
+
536
+ TASK:
537
+ Generate a natural, supportive response to the patient's message. The patient has not shown signs of spiritual distress, so this is a normal conversational exchange about spiritual or emotional topics.
538
+
539
+ Your response should:
540
+ 1. Directly address what the patient said
541
+ 2. Be warm and conversational
542
+ 3. Show genuine interest in their perspective
543
+ 4. Offer to continue the conversation if they'd like
544
+ 5. Be in the same language as the patient's message
545
+
546
+ Keep your response concise (2-4 sentences) and natural."""