abdibrahem commited on
Commit
a77efdb
·
1 Parent(s): 12b7293

Fix the intent prompt

Browse files
Files changed (1) hide show
  1. main.py +80 -31
main.py CHANGED
@@ -155,39 +155,88 @@ class HealthcareChatbot:
155
  self.json_parser = JsonOutputParser(pydantic_object=EndpointRequest)
156
 
157
  # Intent classification prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  self.intent_classifier_template = PromptTemplate(
159
- template="""
160
- You are an intent classifier. Your job is simple: understand what the user wants and check if any API endpoint can do that.
161
-
162
- User Message: {user_query}
163
- Language: {detected_language}
164
- API Endpoints: {endpoints_documentation}
165
-
166
- Think step by step:
167
-
168
- 1. What does the user want from this message?
169
- Read the user's message carefully. What is the user trying to say or accomplish? What would a human understand from this message?
170
-
171
- 2. Can any API endpoint fulfill what the user wants?
172
- Look at each API endpoint. Does any endpoint do what the user is asking for? Be very precise - only say yes if there's a clear match.
173
-
174
- Important rules:
175
- - Focus ONLY on the current message, ignore conversation history for classification
176
- - If the user is just talking, being social, or saying something casual, that's CONVERSATION
177
- - Only choose API_ACTION if the user is clearly asking for something an API endpoint can do
178
- - When you're not sure, choose CONVERSATION
179
-
180
- Answer in this format:
181
- {{
182
- "intent": "API_ACTION" or "CONVERSATION",
183
- "confidence": [0.0 to 1.0],
184
- "reasoning": "What does the user want? Can any API do this?",
185
- "requires_backend": true or false
186
- }}
187
- """,
188
- input_variables=["user_query", "detected_language", "conversation_history", "endpoints_documentation"]
189
- )
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
 
193
 
 
155
  self.json_parser = JsonOutputParser(pydantic_object=EndpointRequest)
156
 
157
  # Intent classification prompt
158
+ # self.intent_classifier_template = PromptTemplate(
159
+ # template="""
160
+ # You are an intent classifier. Your job is simple: understand what the user wants and check if any API endpoint can do that.
161
+
162
+ # User Message: {user_query}
163
+ # Language: {detected_language}
164
+ # API Endpoints: {endpoints_documentation}
165
+
166
+ # Think step by step:
167
+
168
+ # 1. What does the user want from this message?
169
+ # Read the user's message carefully. What is the user trying to say or accomplish? What would a human understand from this message?
170
+
171
+ # 2. Can any API endpoint fulfill what the user wants?
172
+ # Look at each API endpoint. Does any endpoint do what the user is asking for? Be very precise - only say yes if there's a clear match.
173
+
174
+ # Important rules:
175
+ # - Focus ONLY on the current message, ignore conversation history for classification
176
+ # - If the user is just talking, being social, or saying something casual, that's CONVERSATION
177
+ # - Only choose API_ACTION if the user is clearly asking for something an API endpoint can do
178
+ # - When you're not sure, choose CONVERSATION
179
+
180
+ # Answer in this format:
181
+ # {{
182
+ # "intent": "API_ACTION" or "CONVERSATION",
183
+ # "confidence": [0.0 to 1.0],
184
+ # "reasoning": "What does the user want? Can any API do this?",
185
+ # "requires_backend": true or false
186
+ # }}
187
+ # """,
188
+ # input_variables=["user_query", "detected_language", "conversation_history", "endpoints_documentation"]
189
+ # )
190
+
191
  self.intent_classifier_template = PromptTemplate(
192
+ template="""
193
+ You are a strict intent classification system. Your only task is to determine if the user message requires an API action or is general conversation.
194
+
195
+ === ABSOLUTE RULES ===
196
+ 1. OUTPUT FORMAT MUST BE EXACTLY:
197
+ {{
198
+ "intent": "API_ACTION" or "CONVERSATION",
199
+ "confidence": 0.0-1.0,
200
+ "reasoning": "clear justification",
201
+ "requires_backend": true or false
202
+ }}
203
+ 2. Never invent custom intent types
204
+ 3. Never output endpoint names in the intent field
205
+ 4. "requires_backend" must match the intent (true for API_ACTION)
206
+
207
+ === CLASSIFICATION CRITERIA ===
208
+ API_ACTION must meet ALL of:
209
+ - The message contains a clear, actionable request
210
+ - The request matches a documented API endpoint's purpose
211
+ - The request requires specific backend functionality
212
+
213
+ CONVERSATION applies when:
214
+ - The message is social/greeting/smalltalk
215
+ - The request is too vague for API action
216
+ - No API endpoint matches the request
 
 
 
 
 
 
217
 
218
+ === INPUT DATA ===
219
+ User Message: {user_query}
220
+ Detected Language: {detected_language}
221
+ API Endpoints: {endpoints_documentation}
222
+
223
+ === DECISION PROCESS ===
224
+ 1. Analyze the message literally - what is the explicit request?
225
+ 2. Check endpoints documentation - is there an exact functional match?
226
+ 3. If uncertain, default to CONVERSATION
227
+ 4. Validate against rules before responding
228
+
229
+ === OUTPUT VALIDATION ===
230
+ Before responding, verify:
231
+ - Intent is ONLY "API_ACTION" or "CONVERSATION"
232
+ - Confidence reflects certainty (1.0 = perfect match)
233
+ - Reasoning explains the endpoint match (for API_ACTION)
234
+ - requires_backend aligns with intent
235
+
236
+ Respond ONLY in the exact specified format.
237
+ """,
238
+ input_variables=["user_query", "detected_language", "conversation_history", "endpoints_documentation"]
239
+ )
240
 
241
 
242