KeenWoo commited on
Commit
0b37d8c
·
verified ·
1 Parent(s): 4853024

Update alz_companion/prompts.py

Browse files
Files changed (1) hide show
  1. alz_companion/prompts.py +56 -59
alz_companion/prompts.py CHANGED
@@ -48,51 +48,6 @@ def render_emotion_guidelines(emotion: str | None) -> str:
48
  bullet = "\n".join([f"- {x}" for x in style["playbook"]])
49
  return f"Emotion: {e}\nDesired tone: {style['tone']}\nWhen replying, follow:\n{bullet}"
50
 
51
- # ------------------------ NLU Classification (Dynamic Pipeline) ------------------------
52
- NLU_ROUTER_PROMPT = """You are an expert NLU router. Your task is to classify the user's primary goal into one of two categories:
53
- 1. `practical_planning`: The user is seeking a plan, strategy, "how-to" advice, or a solution to a problem.
54
- 2. `emotional_support`: The user is expressing feelings, seeking comfort, validation, or reassurance.
55
-
56
- User Query: "{query}"
57
-
58
- Respond with ONLY a single category name from the list above.
59
- Category: """
60
-
61
- # --- MODIFICATION 1: Use the new, corrected NLU prompt for multi-tag support ---
62
- SPECIALIST_CLASSIFIER_PROMPT = """You are an expert NLU engine for a dementia care assistant. Your goal is to classify the user's query by extracting relevant tags based on the provided examples and options. Your primary goal for this query is: {primary_goal}.
63
-
64
- --- RELEVANT EXAMPLES ---
65
- {examples}
66
- ---
67
-
68
- --- PROVIDED TAGS ---
69
- Behaviors: {behavior_options}
70
- Emotions: {emotion_options}
71
- Topics: {topic_options}
72
- Contexts: {context_options}
73
- ---
74
-
75
- --- INSTRUCTIONS ---
76
- 1. Carefully read the User Query below.
77
- 2. Consider the Primary Goal and the Relevant Examples.
78
- 3. **IMPORTANT EMOTION RULE:** If the user expresses memory loss (e.g., "I forgot," "can't remember," "don't recall"), you MUST analyze the tone and select an appropriate emotion like "confusion," "sadness," or "anxiety." Do not default to "None" in these cases.
79
- 4. First, think step-by-step in a <thinking> block using this EXACT structure:
80
- - **Emotion Analysis:** Analyze the user's primary emotional state. Is it fear, sadness, anger? Choose ONE from the Emotions list. (Remember the Important Emotion Rule above).
81
- - **Behavior Analysis:** Identify the most specific, concrete, observable behavior. What is the person doing or describing? If multiple behaviors seem to apply, choose the MOST specific one. For example, "not recognizing a daughter" is more specific than "confusion". Choose ONE OR MORE from the Behaviors list.
82
- - **Topic Analysis:** What is the underlying subject or intent of the query? Choose ONE OR MORE from the Topics list.
83
- - **Context Analysis:** What is the inferred setting, relationship, or disease stage? Choose ONE OR more from the Contexts list.
84
- - **Final JSON:** Based on your analysis above, construct the final JSON object.
85
- 5. Then, provide the single JSON object with your final classification.
86
- 6. The JSON object must contain four keys: "detected_behaviors", "detected_emotion", "detected_topics", "detected_contexts".
87
- 7. Values for behaviors, topics, and contexts must be LISTs of strings from the options provided. The value for emotion must be a SINGLE string.
88
- 8. **CRITICAL:** Use the exact canonical tag names from the lists (e.g., "repetitive_questioning"). Do not make up new ones.
89
- 9. If no tag from a category is relevant, use an empty list `[]` or the string "None".
90
-
91
- User Query: "{query}"
92
-
93
- <thinking>
94
- </thinking>
95
- """
96
 
97
  # ------------------------ Guardrails ------------------------
98
  SAFETY_GUARDRAILS = "You are a helpful assistant, not a medical professional. Do not provide medical advice, diagnoses, or treatment plans. If the user mentions safety concerns, self-harm, or urgent medical needs, advise them to contact a healthcare professional or emergency services immediately."
@@ -109,8 +64,6 @@ You must ALWAYS respond in {language}.
109
  """
110
 
111
  # ------------------------ Router & Specialized Templates ------------------------
112
- # In prompts.py
113
-
114
  ROUTER_PROMPT = """You are an expert NLU router. Classify the user’s query into ONE of:
115
 
116
  1) caregiving_scenario — The user describes a symptom, concern, emotional state, or plans for the future in a dementia/care context and implicitly/explicitly seeks help, validation, or a strategy. This includes reminiscence and 'how-to' questions about care.
@@ -130,16 +83,18 @@ User: "I forgot the address for John Black." → caregiving_scenario
130
  User: "I was remembering the music at our wedding." → caregiving_scenario
131
  User: "How do I choose the right songs for him?" → caregiving_scenario
132
  User: "I’d like to keep lecturing—if I can." → caregiving_scenario
 
133
  User: “What is my daughter’s name?” → factual_question
134
  User: "Who was my long-term partner I lived with in New York?" → factual_question
135
- --- START: DEFINITIVE FIX ---
136
  User: "What are my favorite movies?" → factual_question
137
- # --- END: DEFINITIVE FIX ---
138
  User: "Summarise yesterday’s notes into 5 bullets." → summarization
139
  User: “Tell me more about Anthony.” → summarization
 
140
  User: “Compare how Alice and Anthony showed confusion.” → multi_hop
141
  User: "Did my husband Danish live with us in Flushing where my daughter was born?" → multi_hop
142
  User: "I know I moved to New York. What does the journal say about my life before that?" → multi_hop
 
143
  User: "Who was the president of the United States back in 1970?" → general_knowledge_question
144
  User: “What is the capital of France?” → general_knowledge_question
145
  User: “Thanks for your help.” → general_conversation
@@ -151,20 +106,15 @@ User: "Put on something cheerful." → play_music_request
151
  User: "Let's have some music." → play_music_request
152
  User: "I am feeling worried, play some music to calm me down." → play_music_request # <-- ADD THIS EXAMPLE
153
  User: "What music do I like to listen to?" → list_music_request
154
- # --- START: DEFINITIVE FIX ---
155
  User: "What songs are in my library?" → list_music_request
156
- # --- END: DEFINITIVE FIX ---
157
-
158
 
159
  User Query: "{query}"
160
 
161
  Respond with ONLY one label from the list: caregiving_scenario | factual_question | multi_hop | summarization | general_knowledge_question | general_conversation | play_music_request
162
  Category: """
163
 
164
- # In prompts.py
165
 
166
- # Replace the old QUERY_EXPANSION_PROMPT with this improved version
167
- # QUERY_EXPANSION_PROMPT = """You are an expert query assistant. Your task is to rewrite a user's question into 3 semantically diverse variations to improve search results from a vector database. Focus on using synonyms, rephrasing the intent, and exploring different facets of the question.
168
  QUERY_EXPANSION_PROMPT = """You are an expert query assistant for a dementia care vector database. Your task is to rewrite a user's question into 3 semantically diverse variations to improve search results. Focus on using synonyms, rephrasing intent, and exploring different facets like the underlying symptom, the emotional state, and the implied caregiving need.
169
 
170
  Return ONLY a JSON list of strings. Do not include any other text or explanation.
@@ -189,12 +139,63 @@ Question: "what was my career about"
189
  Example 5:
190
  Question: "where is my husband"
191
  ["memories of my spouse", "information about my long-term partner", "journal entries about my husband"]
 
 
 
 
192
  ---
193
 
194
  Question: "{question}"
195
  """
196
 
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  # NEW
199
  MUSIC_PREAMBLE_PROMPT = """You are a warm and empathetic AI companion. The user has expressed a feeling and also asked for music. Your task is to provide a brief, single-sentence validation of their feeling before the music starts.
200
 
@@ -407,14 +408,10 @@ INSTRUCTIONS FOR THE AI:
407
  Your ONLY task is to create a concise summary that directly and exclusively answers the 'User's Request' using ONLY the provided 'Source excerpts'. Follow these steps precisely:
408
 
409
  1. **Identify Core Constraints:** First, analyze the 'User's Request' to identify all specific constraints. This includes topics (e.g., "word-finding difficulties"), timeframes (e.g., "yesterday," "last three days"), or people (e.g., "my wife's routine").
410
-
411
  2. **Filter Context Rigorously:** You MUST filter the 'Source excerpts' and use ONLY the information that strictly matches ALL identified constraints. Discard any and all irrelevant information.
412
-
413
  3. **Synthesize the Answer:** Construct a brief, natural-sounding summary using ONLY the filtered information. Address the user directly.
414
-
415
  4. **Handle Insufficient Data:** If, after filtering, no relevant information remains in the 'Source excerpts' to fulfill the request, you MUST respond with a gentle, helpful message stating that you could not find the specific information.
416
  - Example: "I looked through the journal, but I couldn't find any notes about that specific topic. Would you like me to search for something else?"
417
-
418
  5. **Strict Prohibition on Hallucination:** Under no circumstances are you to add, invent, or infer any information not explicitly present in the provided 'Source excerpts'. Your task is to summarize, not to create.
419
  """
420
 
 
48
  bullet = "\n".join([f"- {x}" for x in style["playbook"]])
49
  return f"Emotion: {e}\nDesired tone: {style['tone']}\nWhen replying, follow:\n{bullet}"
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  # ------------------------ Guardrails ------------------------
53
  SAFETY_GUARDRAILS = "You are a helpful assistant, not a medical professional. Do not provide medical advice, diagnoses, or treatment plans. If the user mentions safety concerns, self-harm, or urgent medical needs, advise them to contact a healthcare professional or emergency services immediately."
 
64
  """
65
 
66
  # ------------------------ Router & Specialized Templates ------------------------
 
 
67
  ROUTER_PROMPT = """You are an expert NLU router. Classify the user’s query into ONE of:
68
 
69
  1) caregiving_scenario — The user describes a symptom, concern, emotional state, or plans for the future in a dementia/care context and implicitly/explicitly seeks help, validation, or a strategy. This includes reminiscence and 'how-to' questions about care.
 
83
  User: "I was remembering the music at our wedding." → caregiving_scenario
84
  User: "How do I choose the right songs for him?" → caregiving_scenario
85
  User: "I’d like to keep lecturing—if I can." → caregiving_scenario
86
+
87
  User: “What is my daughter’s name?” → factual_question
88
  User: "Who was my long-term partner I lived with in New York?" → factual_question
 
89
  User: "What are my favorite movies?" → factual_question
90
+
91
  User: "Summarise yesterday’s notes into 5 bullets." → summarization
92
  User: “Tell me more about Anthony.” → summarization
93
+
94
  User: “Compare how Alice and Anthony showed confusion.” → multi_hop
95
  User: "Did my husband Danish live with us in Flushing where my daughter was born?" → multi_hop
96
  User: "I know I moved to New York. What does the journal say about my life before that?" → multi_hop
97
+
98
  User: "Who was the president of the United States back in 1970?" → general_knowledge_question
99
  User: “What is the capital of France?” → general_knowledge_question
100
  User: “Thanks for your help.” → general_conversation
 
106
  User: "Let's have some music." → play_music_request
107
  User: "I am feeling worried, play some music to calm me down." → play_music_request # <-- ADD THIS EXAMPLE
108
  User: "What music do I like to listen to?" → list_music_request
 
109
  User: "What songs are in my library?" → list_music_request
 
 
110
 
111
  User Query: "{query}"
112
 
113
  Respond with ONLY one label from the list: caregiving_scenario | factual_question | multi_hop | summarization | general_knowledge_question | general_conversation | play_music_request
114
  Category: """
115
 
 
116
 
117
+
 
118
  QUERY_EXPANSION_PROMPT = """You are an expert query assistant for a dementia care vector database. Your task is to rewrite a user's question into 3 semantically diverse variations to improve search results. Focus on using synonyms, rephrasing intent, and exploring different facets like the underlying symptom, the emotional state, and the implied caregiving need.
119
 
120
  Return ONLY a JSON list of strings. Do not include any other text or explanation.
 
139
  Example 5:
140
  Question: "where is my husband"
141
  ["memories of my spouse", "information about my long-term partner", "journal entries about my husband"]
142
+
143
+ Example 6:
144
+ Question: "what is my favorite video"
145
+ ["what are my favorite movies", "tell me about films I like", "what shows do I enjoy watching"]
146
  ---
147
 
148
  Question: "{question}"
149
  """
150
 
151
 
152
+ # ------------------------ NLU Classification (Dynamic Pipeline) ------------------------
153
+ NLU_ROUTER_PROMPT = """You are an expert NLU router. Your task is to classify the user's primary goal into one of two categories:
154
+ 1. `practical_planning`: The user is seeking a plan, strategy, "how-to" advice, or a solution to a problem.
155
+ 2. `emotional_support`: The user is expressing feelings, seeking comfort, validation, or reassurance.
156
+
157
+ User Query: "{query}"
158
+
159
+ Respond with ONLY a single category name from the list above.
160
+ Category: """
161
+
162
+ # --- MODIFICATION 1: Use the new, corrected NLU prompt for multi-tag support ---
163
+ SPECIALIST_CLASSIFIER_PROMPT = """You are an expert NLU engine for a dementia care assistant. Your goal is to classify the user's query by extracting relevant tags based on the provided examples and options. Your primary goal for this query is: {primary_goal}.
164
+
165
+ --- RELEVANT EXAMPLES ---
166
+ {examples}
167
+ ---
168
+
169
+ --- PROVIDED TAGS ---
170
+ Behaviors: {behavior_options}
171
+ Emotions: {emotion_options}
172
+ Topics: {topic_options}
173
+ Contexts: {context_options}
174
+ ---
175
+
176
+ --- INSTRUCTIONS ---
177
+ 1. Carefully read the User Query below.
178
+ 2. Consider the Primary Goal and the Relevant Examples.
179
+ 3. **IMPORTANT EMOTION RULE:** If the user expresses memory loss (e.g., "I forgot," "can't remember," "don't recall"), you MUST analyze the tone and select an appropriate emotion like "confusion," "sadness," or "anxiety." Do not default to "None" in these cases.
180
+ 4. First, think step-by-step in a <thinking> block using this EXACT structure:
181
+ - **Emotion Analysis:** Analyze the user's primary emotional state. Is it fear, sadness, anger? Choose ONE from the Emotions list. (Remember the Important Emotion Rule above).
182
+ - **Behavior Analysis:** Identify the most specific, concrete, observable behavior. What is the person doing or describing? If multiple behaviors seem to apply, choose the MOST specific one. For example, "not recognizing a daughter" is more specific than "confusion". Choose ONE OR MORE from the Behaviors list.
183
+ - **Topic Analysis:** What is the underlying subject or intent of the query? Choose ONE OR MORE from the Topics list.
184
+ - **Context Analysis:** What is the inferred setting, relationship, or disease stage? Choose ONE OR more from the Contexts list.
185
+ - **Final JSON:** Based on your analysis above, construct the final JSON object.
186
+ 5. Then, provide the single JSON object with your final classification.
187
+ 6. The JSON object must contain four keys: "detected_behaviors", "detected_emotion", "detected_topics", "detected_contexts".
188
+ 7. Values for behaviors, topics, and contexts must be LISTs of strings from the options provided. The value for emotion must be a SINGLE string.
189
+ 8. **CRITICAL:** Use the exact canonical tag names from the lists (e.g., "repetitive_questioning"). Do not make up new ones.
190
+ 9. If no tag from a category is relevant, use an empty list `[]` or the string "None".
191
+
192
+ User Query: "{query}"
193
+
194
+ <thinking>
195
+ </thinking>
196
+ """
197
+
198
+
199
  # NEW
200
  MUSIC_PREAMBLE_PROMPT = """You are a warm and empathetic AI companion. The user has expressed a feeling and also asked for music. Your task is to provide a brief, single-sentence validation of their feeling before the music starts.
201
 
 
408
  Your ONLY task is to create a concise summary that directly and exclusively answers the 'User's Request' using ONLY the provided 'Source excerpts'. Follow these steps precisely:
409
 
410
  1. **Identify Core Constraints:** First, analyze the 'User's Request' to identify all specific constraints. This includes topics (e.g., "word-finding difficulties"), timeframes (e.g., "yesterday," "last three days"), or people (e.g., "my wife's routine").
 
411
  2. **Filter Context Rigorously:** You MUST filter the 'Source excerpts' and use ONLY the information that strictly matches ALL identified constraints. Discard any and all irrelevant information.
 
412
  3. **Synthesize the Answer:** Construct a brief, natural-sounding summary using ONLY the filtered information. Address the user directly.
 
413
  4. **Handle Insufficient Data:** If, after filtering, no relevant information remains in the 'Source excerpts' to fulfill the request, you MUST respond with a gentle, helpful message stating that you could not find the specific information.
414
  - Example: "I looked through the journal, but I couldn't find any notes about that specific topic. Would you like me to search for something else?"
 
415
  5. **Strict Prohibition on Hallucination:** Under no circumstances are you to add, invent, or infer any information not explicitly present in the provided 'Source excerpts'. Your task is to summarize, not to create.
416
  """
417