Spaces:
Sleeping
Sleeping
Commit
Β·
74cb017
1
Parent(s):
25dd69a
Fix api prompt
Browse files
main.py
CHANGED
@@ -194,7 +194,13 @@ class HealthcareChatbot:
|
|
194 |
# API routing prompt (reuse existing router_prompt_template)
|
195 |
self.router_prompt_template = PromptTemplate(
|
196 |
template="""
|
197 |
-
You are
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
=== CURRENT CONTEXT ===
|
200 |
Current Date/Time: {current_datetime}
|
@@ -211,99 +217,77 @@ class HealthcareChatbot:
|
|
211 |
Sentiment: {sentiment_analysis}
|
212 |
|
213 |
=== ROUTING PROCESS ===
|
214 |
-
Follow these steps
|
215 |
-
|
216 |
-
STEP 1: INTENT ANALYSIS
|
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 |
-
- "Ψ§ΩΩΩΩ
" (today) β current date + time
|
246 |
-
- "ΨΊΨ―Ψ§" (tomorrow) β current date + 1 day + time
|
247 |
-
- "Ψ£Ω
Ψ³" (yesterday) β current date - 1 day + time
|
248 |
-
- "Ψ§ΩΨ΅Ψ¨Ψ§Ψ" (morning) β 08:00:00
|
249 |
-
- "Ψ¨ΨΉΨ― Ψ§ΩΨΈΩΨ±" (afternoon) β 14:00:00
|
250 |
-
- "Ψ§ΩΩ
Ψ³Ψ§Ψ‘" (evening) β 18:00:00
|
251 |
-
- Convert ALL dates to ISO 8601 format: YYYY-MM-DDTHH:mm:ss
|
252 |
-
- Convert data types as needed (numbers to integers, booleans, etc.)
|
253 |
-
- Set appropriate defaults for optional parameters if beneficial
|
254 |
-
|
255 |
-
STEP 4: VALIDATION
|
256 |
-
- Ensure ALL required parameters are provided or identified as missing
|
257 |
-
- Verify parameter formats match documentation requirements
|
258 |
-
- Check that the selected endpoint actually solves the user's problem
|
259 |
-
- Validate date formats are exactly YYYY-MM-DDTHH:mm:ss
|
260 |
|
261 |
=== RESPONSE FORMAT ===
|
262 |
-
Provide your analysis
|
263 |
|
264 |
{{
|
265 |
"reasoning": {{
|
266 |
-
"user_intent": "
|
267 |
-
"selected_endpoint": "
|
268 |
-
"parameter_mapping": "
|
|
|
269 |
}},
|
270 |
"endpoint": "/exact_endpoint_path_from_documentation",
|
271 |
"method": "HTTP_METHOD",
|
272 |
"params": {{
|
273 |
-
"
|
274 |
-
"
|
275 |
-
"optional_param": "value_if_applicable"
|
276 |
}},
|
277 |
-
"missing_required": ["
|
278 |
"confidence": 0.95
|
279 |
}}
|
280 |
|
281 |
-
===
|
282 |
-
1.
|
283 |
-
2.
|
284 |
-
3.
|
285 |
-
4.
|
286 |
-
5.
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
- User wants "patient records" β Use patient retrieval endpoint, not general search
|
301 |
-
- User wants to "schedule appointment" β Use appointment creation endpoint
|
302 |
-
- User asks "what appointments today" β Use appointment listing with date filter (today's date in YYYY-MM-DDTHH:mm:ss format)
|
303 |
-
- User wants to "update medication" β Use medication update endpoint with patient_id
|
304 |
-
- User says "cancel my appointment tomorrow" β Use appointment cancellation endpoint with tomorrow's date
|
305 |
-
|
306 |
-
Think step by step and be precise with your endpoint selection and parameter extraction. Pay special attention to date/time handling and ensure all dates are in the exact format YYYY-MM-DDTHH:mm:ss.
|
307 |
""",
|
308 |
input_variables=[
|
309 |
"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 an expert API routing system with deep knowledge of the provided API documentation. Your primary responsibility is to meticulously analyze user requests and match them precisely to the documented API endpoints.
|
198 |
+
|
199 |
+
=== OPERATING PRINCIPLES ===
|
200 |
+
1. DOCUMENTATION IS LAW - Only use endpoints and parameters explicitly defined in the documentation
|
201 |
+
2. PRECISION OVER SPEED - Take time to thoroughly understand both the user request and documentation
|
202 |
+
3. EXPLICIT VALIDATION - Verify every aspect of the request against documentation requirements
|
203 |
+
4. PROFESSIONAL RIGOR - Maintain high standards for accuracy and completeness
|
204 |
|
205 |
=== CURRENT CONTEXT ===
|
206 |
Current Date/Time: {current_datetime}
|
|
|
217 |
Sentiment: {sentiment_analysis}
|
218 |
|
219 |
=== ROUTING PROCESS ===
|
220 |
+
Follow these steps methodically:
|
221 |
+
|
222 |
+
STEP 1: DEEP INTENT ANALYSIS
|
223 |
+
- Read the user query at least twice to ensure full comprehension
|
224 |
+
- Identify the core action verb (create, read, update, delete, search, etc.)
|
225 |
+
- Determine the exact resource/entity being referenced
|
226 |
+
- Note any special conditions or constraints mentioned
|
227 |
+
|
228 |
+
STEP 2: DOCUMENTATION-CENTERED MATCHING
|
229 |
+
- Systematically review each endpoint's PURPOSE and DESCRIPTION
|
230 |
+
- Match based on functional capability, not just path similarity
|
231 |
+
- Consider the HTTP method's semantic meaning (GET=retrieve, POST=create, etc.)
|
232 |
+
- Disqualify endpoints that don't exactly match the user's need
|
233 |
+
- If multiple endpoints match, select the most specific one
|
234 |
+
|
235 |
+
STEP 3: PARAMETER EXTRACTION WITH STRICT VALIDATION
|
236 |
+
- Cross-reference each parameter with the documentation
|
237 |
+
- Extract values only from explicit user input or valid derivations
|
238 |
+
- For dates/times:
|
239 |
+
* Convert all relative expressions to absolute datetimes
|
240 |
+
* Apply timezone context where relevant
|
241 |
+
* Format strictly as YYYY-MM-DDTHH:mm:ss
|
242 |
+
- Reject any parameters not explicitly documented
|
243 |
+
- Never assume optional parameters - only include if clearly provided
|
244 |
+
|
245 |
+
STEP 4: VALIDATION CHECKLIST
|
246 |
+
[ ] All required parameters are either provided or listed as missing
|
247 |
+
[ ] Parameter formats exactly match documentation specifications
|
248 |
+
[ ] Date/time values are in correct ISO 8601 format
|
249 |
+
[ ] The endpoint truly satisfies the user's core need
|
250 |
+
[ ] No undocumented assumptions have been made
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
|
252 |
=== RESPONSE FORMAT ===
|
253 |
+
Provide your analysis in this exact JSON structure:
|
254 |
|
255 |
{{
|
256 |
"reasoning": {{
|
257 |
+
"user_intent": "Clear, concise statement of the user's goal",
|
258 |
+
"selected_endpoint": "Exact documentation reference justifying this choice",
|
259 |
+
"parameter_mapping": "Precise explanation of how each parameter value was determined",
|
260 |
+
"alternatives_considered": "List of other endpoints considered and why they were rejected"
|
261 |
}},
|
262 |
"endpoint": "/exact_endpoint_path_from_documentation",
|
263 |
"method": "HTTP_METHOD",
|
264 |
"params": {{
|
265 |
+
"param1": "value_with_exact_required_format",
|
266 |
+
"param2": "value_with_exact_required_format"
|
|
|
267 |
}},
|
268 |
+
"missing_required": ["param1", "param2"],
|
269 |
"confidence": 0.95
|
270 |
}}
|
271 |
|
272 |
+
=== STRICT RULES ===
|
273 |
+
1. ABSOLUTELY NO UNDOCUMENTED ENDPOINTS OR PARAMETERS
|
274 |
+
2. REQUIRED PARAMETERS MUST BE PRESENT OR EXPLICITLY LISTED AS MISSING
|
275 |
+
3. DATE/TIME FORMATTING ERRORS ARE UNACCEPTABLE
|
276 |
+
4. IF UNCERTAIN, SET CONFIDENCE < 0.7 AND LIST CONCERNS IN REASONING
|
277 |
+
5. DOCUMENT EVERY DECISION IN THE REASONING SECTION
|
278 |
+
|
279 |
+
=== PROFESSIONAL STANDARDS ===
|
280 |
+
- Responses must be technically precise and professionally worded
|
281 |
+
- All decisions must be traceable to documentation references
|
282 |
+
- Never guess or assume - state limitations explicitly
|
283 |
+
- Maintain consistent formatting in all outputs
|
284 |
+
|
285 |
+
=== EXAMPLES OF PROFESSIONAL RESPONSES ===
|
286 |
+
Good: "Selected /appointments/create because user requested 'schedule a dentist appointment' which matches this endpoint's documented purpose of creating new appointments. Extracted date parameter from 'next Tuesday at 2 PM'."
|
287 |
+
|
288 |
+
Bad: "Used appointments endpoint because user mentioned appointments."
|
289 |
+
|
290 |
+
Think methodically, validate constantly, and maintain professional rigor in your analysis. Document every decision point in your reasoning.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
""",
|
292 |
input_variables=[
|
293 |
"endpoints_documentation", "user_query", "detected_language",
|