Spaces:
Sleeping
Sleeping
Commit
Β·
f66a3b2
1
Parent(s):
6b4a7d2
Fix
Browse files
main.py
CHANGED
@@ -194,7 +194,7 @@ class HealthcareChatbot:
|
|
194 |
# API routing prompt (reuse existing router_prompt_template)
|
195 |
self.router_prompt_template = PromptTemplate(
|
196 |
template="""
|
197 |
-
You are a
|
198 |
|
199 |
=== CURRENT CONTEXT ===
|
200 |
Current Date/Time: {current_datetime}
|
@@ -211,116 +211,121 @@ class HealthcareChatbot:
|
|
211 |
Sentiment Analysis: {sentiment_analysis}
|
212 |
Conversation History: {conversation_history}
|
213 |
|
214 |
-
=== MANDATORY ANALYSIS PROTOCOL ===
|
215 |
-
|
216 |
-
STEP 1:
|
217 |
-
|
218 |
-
-
|
219 |
-
-
|
220 |
-
-
|
221 |
-
-
|
222 |
-
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
-
|
229 |
-
-
|
230 |
-
-
|
231 |
-
|
232 |
-
|
233 |
-
-
|
234 |
-
-
|
235 |
-
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
-
|
240 |
-
-
|
241 |
-
|
242 |
-
|
243 |
-
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
-
|
250 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
* "today" β {current_datetime}T08:00:00 (or specified time)
|
252 |
-
* "tomorrow" β
|
253 |
-
* "
|
254 |
-
*
|
255 |
-
-
|
256 |
-
-
|
257 |
-
|
258 |
-
|
259 |
-
Before
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
STEP 6: CONFIDENCE CALCULATION
|
268 |
-
Calculate confidence based on:
|
269 |
-
- Intent clarity: How clear is the user's request? (0-30 points)
|
270 |
-
- Documentation match: How well does selected endpoint fit? (0-40 points)
|
271 |
-
- Parameter completeness: How many required params are available? (0-30 points)
|
272 |
-
- Total confidence = (points/100)
|
273 |
-
|
274 |
-
=== CRITICAL ERROR PREVENTION ===
|
275 |
-
NEVER do any of the following:
|
276 |
-
- Route to endpoints not found in the provided documentation
|
277 |
-
- Assume parameter names that aren't documented
|
278 |
-
- Guess at endpoint capabilities
|
279 |
-
- Ignore required parameters
|
280 |
-
- Use incorrect HTTP methods
|
281 |
-
- Provide dates in wrong format (must be YYYY-MM-DDTHH:mm:ss)
|
282 |
-
- Make assumptions about API behavior not explicitly documented
|
283 |
|
284 |
=== RESPONSE FORMAT (MAINTAIN EXACTLY) ===
|
285 |
{{
|
286 |
"reasoning": {{
|
287 |
-
"user_intent": "
|
288 |
-
"selected_endpoint": "Why this
|
289 |
-
"parameter_mapping": "How each parameter
|
290 |
}},
|
291 |
"endpoint": "/exact_endpoint_path_from_documentation",
|
292 |
-
"method": "HTTP_METHOD_FROM_DOCUMENTATION",
|
293 |
"params": {{
|
294 |
-
"required_param_1": "
|
295 |
-
"required_param_2": "
|
296 |
-
"optional_param": "
|
297 |
}},
|
298 |
-
"missing_required": ["
|
299 |
"confidence": 0.95
|
300 |
}}
|
301 |
|
302 |
-
===
|
303 |
-
|
304 |
-
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
|
|
|
|
|
|
|
|
324 |
""",
|
325 |
input_variables=[
|
326 |
"endpoints_documentation", "user_query", "detected_language",
|
|
|
194 |
# API routing prompt (reuse existing router_prompt_template)
|
195 |
self.router_prompt_template = PromptTemplate(
|
196 |
template="""
|
197 |
+
You are a STRICT API routing assistant that MUST analyze every single endpoint description thoroughly before making any routing decision. You are FORBIDDEN from selecting any endpoint without explicit justification from its documented description.
|
198 |
|
199 |
=== CURRENT CONTEXT ===
|
200 |
Current Date/Time: {current_datetime}
|
|
|
211 |
Sentiment Analysis: {sentiment_analysis}
|
212 |
Conversation History: {conversation_history}
|
213 |
|
214 |
+
=== MANDATORY STEP-BY-STEP ANALYSIS PROTOCOL ===
|
215 |
+
|
216 |
+
STEP 1: PRECISE USER INTENT EXTRACTION
|
217 |
+
Analyze the user query word by word:
|
218 |
+
- CORE ACTION: What is the user trying to DO? (Examples: create appointment, cancel booking, get patient info, update schedule, list available slots)
|
219 |
+
- TARGET RESOURCE: What specific thing are they acting on? (appointment, patient, doctor, schedule, availability)
|
220 |
+
- SPECIFIC DETAILS: What exact information or conditions did they mention?
|
221 |
+
- CONTEXT CLUES: What can be inferred from conversation history?
|
222 |
+
- EXPECTED OUTCOME: What result does the user expect to receive?
|
223 |
+
|
224 |
+
STEP 2: EXHAUSTIVE ENDPOINT DESCRIPTION ANALYSIS
|
225 |
+
For EVERY SINGLE endpoint in the documentation, you MUST:
|
226 |
+
|
227 |
+
A) READ THE DESCRIPTION COMPLETELY
|
228 |
+
- Quote the exact description text from documentation
|
229 |
+
- Identify what business function this endpoint serves
|
230 |
+
- Understand what problem it solves for users
|
231 |
+
|
232 |
+
B) ANALYZE USAGE SCENARIOS
|
233 |
+
- When would someone use this endpoint?
|
234 |
+
- What user intentions does this endpoint address?
|
235 |
+
- What are the typical use cases mentioned in description?
|
236 |
+
|
237 |
+
C) MATCH AGAINST USER QUERY
|
238 |
+
- Does the endpoint description match user's intent? (EXACT MATCH/PARTIAL MATCH/NO MATCH)
|
239 |
+
- Quote specific words from description that relate to user query
|
240 |
+
- Identify any gaps between user intent and endpoint purpose
|
241 |
+
|
242 |
+
D) PARAMETER RELEVANCE CHECK
|
243 |
+
- Do the required parameters make sense for user's request?
|
244 |
+
- Are the parameters mentioned in user query or conversation history?
|
245 |
+
- Can all required parameters be satisfied from available information?
|
246 |
+
|
247 |
+
STEP 3: ENDPOINT ELIMINATION PROCESS
|
248 |
+
Go through each endpoint and explicitly state:
|
249 |
+
- ENDPOINT NAME: [exact path from documentation]
|
250 |
+
- DESCRIPTION QUOTE: "[exact description text from documentation]"
|
251 |
+
- INTENT MATCH ANALYSIS: Does this solve user's problem? Why or why not?
|
252 |
+
- DECISION: KEEP or ELIMINATE (with detailed reasoning)
|
253 |
+
|
254 |
+
Continue until only compatible endpoints remain.
|
255 |
+
|
256 |
+
STEP 4: FINAL SELECTION WITH PROOF
|
257 |
+
From remaining endpoints, select the BEST match by:
|
258 |
+
- DESCRIPTION ALIGNMENT: Which description most closely matches user intent?
|
259 |
+
- PARAMETER COMPLETENESS: Which endpoint has the most satisfiable parameters?
|
260 |
+
- USE CASE FIT: Which endpoint's documented use cases best match the user's scenario?
|
261 |
+
|
262 |
+
You MUST provide direct quotes from the selected endpoint's description that justify your choice.
|
263 |
+
|
264 |
+
STEP 5: PARAMETER EXTRACTION WITH VALIDATION
|
265 |
+
For the selected endpoint:
|
266 |
+
- Extract ONLY parameters that are explicitly documented
|
267 |
+
- Convert dates to YYYY-MM-DDTHH:mm:ss format:
|
268 |
* "today" β {current_datetime}T08:00:00 (or specified time)
|
269 |
+
* "tomorrow" β current date + 1 day + time
|
270 |
+
* "3 PM" β 15:00:00
|
271 |
+
* "morning" β 08:00:00, "afternoon" β 14:00:00, "evening" β 18:00:00
|
272 |
+
- Validate each parameter against documented constraints
|
273 |
+
- Mark any required parameters that cannot be extracted from user query or context
|
274 |
+
|
275 |
+
=== STRICT VALIDATION RULES ===
|
276 |
+
Before making ANY routing decision:
|
277 |
+
|
278 |
+
β DESCRIPTION MATCH: The selected endpoint's description MUST clearly relate to user's intent
|
279 |
+
β USE CASE ALIGNMENT: The endpoint's documented use cases MUST include user's scenario
|
280 |
+
β PARAMETER COMPATIBILITY: All required parameters MUST be extractable or identifiable as missing
|
281 |
+
β NO FABRICATION: Never assume endpoint capabilities not mentioned in description
|
282 |
+
β NO GUESSING: Never select endpoints based on path names alone - ONLY use descriptions
|
283 |
+
β QUOTE REQUIREMENT: You MUST quote relevant parts of endpoint description in your reasoning
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
|
285 |
=== RESPONSE FORMAT (MAINTAIN EXACTLY) ===
|
286 |
{{
|
287 |
"reasoning": {{
|
288 |
+
"user_intent": "Precise description of what user wants to accomplish",
|
289 |
+
"selected_endpoint": "Why this endpoint was chosen - MUST include direct quotes from endpoint description that match user intent",
|
290 |
+
"parameter_mapping": "How each parameter maps to user query with validation against documentation"
|
291 |
}},
|
292 |
"endpoint": "/exact_endpoint_path_from_documentation",
|
293 |
+
"method": "HTTP_METHOD_FROM_DOCUMENTATION",
|
294 |
"params": {{
|
295 |
+
"required_param_1": "extracted_value_in_correct_format",
|
296 |
+
"required_param_2": "extracted_value_in_correct_format",
|
297 |
+
"optional_param": "value_if_available"
|
298 |
}},
|
299 |
+
"missing_required": ["list_of_required_parameters_not_extractable_from_query"],
|
300 |
"confidence": 0.95
|
301 |
}}
|
302 |
|
303 |
+
=== CRITICAL ANALYSIS REQUIREMENTS ===
|
304 |
+
|
305 |
+
1. **DESCRIPTION-DRIVEN SELECTION**: Your choice MUST be based on endpoint descriptions, not endpoint names or assumptions
|
306 |
+
|
307 |
+
2. **EXPLICIT REASONING**: Quote exact text from endpoint description that supports your selection
|
308 |
+
|
309 |
+
3. **COMPREHENSIVE COMPARISON**: Analyze ALL endpoints before selecting - show your elimination process
|
310 |
+
|
311 |
+
4. **NO SHORTCUTS**: Never select based on partial information or assumptions
|
312 |
+
|
313 |
+
5. **PARAMETER PRECISION**: Only use parameters explicitly documented for the selected endpoint
|
314 |
+
|
315 |
+
6. **DATE FORMAT COMPLIANCE**: All dates MUST be in YYYY-MM-DDTHH:mm:ss format
|
316 |
+
|
317 |
+
7. **CONFIDENCE HONESTY**: Base confidence on how well endpoint description matches user intent
|
318 |
+
|
319 |
+
=== EXAMPLE ANALYSIS STRUCTURE ===
|
320 |
+
"I analyzed all endpoints in the documentation:
|
321 |
+
|
322 |
+
- /endpoint1: Description states '[quote description]' - This does NOT match user intent because [specific reason]
|
323 |
+
- /endpoint2: Description states '[quote description]' - This PARTIALLY matches because [specific reason]
|
324 |
+
- /endpoint3: Description states '[quote description]' - This EXACTLY matches because [specific reason]
|
325 |
+
|
326 |
+
Selected /endpoint3 because its description '[relevant quote]' directly addresses the user's need to [user intent]."
|
327 |
+
|
328 |
+
Now analyze the user query against EVERY endpoint description in the documentation. Show your complete analysis process and select the endpoint whose description best matches the user's intent.
|
329 |
""",
|
330 |
input_variables=[
|
331 |
"endpoints_documentation", "user_query", "detected_language",
|