abdibrahem commited on
Commit
5e0c36d
·
1 Parent(s): e805531
Files changed (1) hide show
  1. main.py +38 -38
main.py CHANGED
@@ -156,59 +156,59 @@ class HealthcareChatbot:
156
  # UNIFIED ROUTER CHAIN - Handles both intent classification AND API routing
157
  self.router_prompt_template = PromptTemplate(
158
  template="""
159
- You are a routing system that determines if a user query matches any available API endpoint.
 
 
 
160
 
161
- ## Available API Endpoints
162
  {endpoints_documentation}
163
 
164
- ## User Query Analysis
165
- - Original Query: "{user_query}"
166
- - Language: {detected_language}
167
- - Keywords: {extracted_keywords}
168
- - Sentiment: {sentiment_analysis}
169
-
170
- ## Simple Decision Process
171
-
172
- **Step 1: Understand User Need**
173
- - What is the user trying to accomplish?
174
- - What specific action or information do they need?
175
- - Consider the query in any language (Arabic, English, etc.)
176
-
177
- **Step 2: Match Need to Endpoint Functionality**
178
- - Read each endpoint description carefully
179
- - Check if ANY endpoint is designed to fulfill the user's specific need
180
- - Focus on WHAT the endpoint does, not HOW the user asked
181
- - Examples of common needs:
182
- * Getting reservations/appointments Look for GET endpoints about appointments/bookings
183
- * Booking appointments → Look for POST endpoints for appointments
184
- * Updating profile → Look for PUT/PATCH endpoints for user data
185
- * Getting medical records → Look for GET endpoints about records/history
186
-
187
- **Step 3: Make Decision**
188
- - If ANY endpoint can fulfill the user's need → intent = "API_ACTION"
189
- - If NO endpoint can fulfill the user's need → intent = "CONVERSATION"
190
-
191
- **Step 2: Extract Details (only if API_ACTION)**
192
- - Select the matching endpoint
193
- - Extract parameters from user query
194
- - List missing required parameters
195
 
196
  ## Output Format
197
  {{
198
  "intent": "CONVERSATION|API_ACTION",
199
- "confidence": 0.0-1.0,
200
- "reasoning": "1) User's need: [what user wants] 2) Endpoint match: [which endpoint can fulfill this need or why none can]",
201
- "endpoint": "/endpoint/path/or/null",
202
- "method": "HTTP_METHOD/or/null",
203
  "params": {{}},
204
  "missing_required": []
205
  }}
206
 
207
- Analyze what the user needs, find the matching endpoint functionality, and respond with the JSON format.
208
  """,
209
  input_variables=["user_query", "detected_language", "extracted_keywords",
210
  "sentiment_analysis", "endpoints_documentation"]
211
  )
 
212
  # CONVERSATION CHAIN - Handles conversational responses
213
  self.conversation_template = PromptTemplate(
214
  template="""
 
156
  # UNIFIED ROUTER CHAIN - Handles both intent classification AND API routing
157
  self.router_prompt_template = PromptTemplate(
158
  template="""
159
+ You are a routing system. Your job is simple:
160
+ 1. Understand what the user wants
161
+ 2. Check if any endpoint can do what they want
162
+ 3. If yes = API_ACTION, if no = CONVERSATION
163
 
164
+ ## Available API Endpoints Documentation
165
  {endpoints_documentation}
166
 
167
+ ## User Query to Analyze
168
+ Query: "{user_query}"
169
+ Language: {detected_language}
170
+
171
+ ## Step-by-Step Analysis
172
+
173
+ **STEP 1: What does the user want?**
174
+ - If query is in Arabic, translate it to English first
175
+ - Identify the main action/request
176
+ - Examples:
177
+ * "قولي حجوزاتي" = "Tell me my appointments" = User wants to VIEW/GET their appointments
178
+ * "احجز موعد" = "Book an appointment" = User wants to CREATE/POST a new appointment
179
+ * "Hello" = Just greeting = User wants to chat
180
+ * "Cancel my appointment" = User wants to DELETE/CANCEL an appointment
181
+
182
+ **STEP 2: Can any endpoint fulfill this want?**
183
+ - Look at each endpoint in the documentation
184
+ - Check if the endpoint's purpose matches what the user wants
185
+ - Match the action type:
186
+ * User wants to VIEW/GET something → Look for GET endpoints
187
+ * User wants to CREATE/BOOK → Look for POST endpoints
188
+ * User wants to UPDATE/CHANGE → Look for PUT/PATCH endpoints
189
+ * User wants to DELETE/CANCEL → Look for DELETE endpoints
190
+
191
+ **STEP 3: Decision**
192
+ - Found matching endpoint = "API_ACTION"
193
+ - No matching endpoint = "CONVERSATION"
 
 
 
 
194
 
195
  ## Output Format
196
  {{
197
  "intent": "CONVERSATION|API_ACTION",
198
+ "confidence": 0.8,
199
+ "reasoning": "User wants: [translated request]. Matching endpoint: [endpoint name] OR No matching endpoint found",
200
+ "endpoint": "/exact/endpoint/path",
201
+ "method": "GET|POST|PUT|DELETE",
202
  "params": {{}},
203
  "missing_required": []
204
  }}
205
 
206
+ Now analyze the user query step by step and give me the JSON response.
207
  """,
208
  input_variables=["user_query", "detected_language", "extracted_keywords",
209
  "sentiment_analysis", "endpoints_documentation"]
210
  )
211
+
212
  # CONVERSATION CHAIN - Handles conversational responses
213
  self.conversation_template = PromptTemplate(
214
  template="""