abdibrahem commited on
Commit
ab198d6
·
1 Parent(s): 1f20eeb

Fix the intent issue

Browse files
Files changed (1) hide show
  1. main.py +31 -49
main.py CHANGED
@@ -156,55 +156,37 @@ class HealthcareChatbot:
156
 
157
  # Intent classification prompt
158
  self.intent_classifier_template = PromptTemplate(
159
- template="""
160
- You are a strict intent classifier for a healthcare chatbot. Your task is to determine whether a user query requires an API call or is just a conversational message.
161
- This decision MUST be based on an accurate comparison between the user's message and the functionality described in the available API endpoints.
162
-
163
- === USER INPUT CONTEXT ===
164
- User Message: {user_query}
165
- Detected Language: {detected_language}
166
- Conversation History: {conversation_history}
167
-
168
- === API ENDPOINTS DOCUMENTATION ===
169
- You must compare the user query against ALL of the following API endpoints and their descriptions to decide if there is a functional match:
170
- {endpoints_documentation}
171
-
172
- === DECISION INSTRUCTIONS ===
173
- Step 1: Understand the intent and meaning of the user message.
174
- Step 2: Carefully read all API endpoint descriptions.
175
- Step 3: Check if the user query matches or requests a function explicitly supported by ANY of the endpoints.
176
- - If there is a match, the intent is **API_ACTION**.
177
- - If no endpoint matches the user query in purpose or meaning, the intent is **CONVERSATION**.
178
-
179
- === RESPONSE FORMAT ===
180
- Respond with ONLY the following JSON structure:
181
- {{
182
- "intent": "API_ACTION" or "CONVERSATION",
183
- "confidence": [0.0 to 1.0],
184
- "reasoning": "Explain if and how the user query matched any endpoint description, or why it didn’t",
185
- "requires_backend": true or false
186
- }}
187
-
188
- === CLASSIFICATION RULES ===
189
- Choose **API_ACTION** if the user request can be fulfilled using an existing endpoint. This includes:
190
- - Scheduling, canceling, or managing appointments
191
- - Requesting or viewing test results, prescriptions, or medical records
192
- - Any interaction described in the API documentation
193
-
194
- Choose **CONVERSATION** if the query:
195
- - Is a greeting or casual message
196
- - Asks about general health advice or medical definitions
197
- - Mentions something unrelated to the provided API functionality
198
- - Cannot be fulfilled by any described endpoint
199
-
200
- === IMPORTANT NOTE ===
201
- DO NOT guess. Only return "API_ACTION" if the user message CLEARLY maps to a specific endpoint. Otherwise, return "CONVERSATION".
202
-
203
- === CLASSIFICATION START ===
204
- Begin classification based on the above rules:
205
- """,
206
- input_variables=["user_query", "detected_language", "conversation_history", "endpoints_documentation"]
207
- )
208
 
209
 
210
 
 
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