Spaces:
Running
Running
Commit
·
12b7293
1
Parent(s):
74cb017
Fix api prompt
Browse files
main.py
CHANGED
@@ -194,100 +194,85 @@ class HealthcareChatbot:
|
|
194 |
# API routing prompt (reuse existing router_prompt_template)
|
195 |
self.router_prompt_template = PromptTemplate(
|
196 |
template="""
|
197 |
-
You are an
|
198 |
|
199 |
-
===
|
200 |
-
1.
|
201 |
-
2.
|
202 |
-
3.
|
203 |
-
4. PROFESSIONAL RIGOR - Maintain high standards for accuracy and completeness
|
204 |
|
205 |
-
===
|
206 |
-
Current
|
207 |
-
|
208 |
-
|
|
|
209 |
|
210 |
-
|
211 |
{endpoints_documentation}
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
Language: {detected_language}
|
216 |
-
Keywords: {extracted_keywords}
|
217 |
-
Sentiment: {sentiment_analysis}
|
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 |
-
[ ] 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": "
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
-
|
283 |
-
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
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",
|
|
|
194 |
# API routing prompt (reuse existing router_prompt_template)
|
195 |
self.router_prompt_template = PromptTemplate(
|
196 |
template="""
|
197 |
+
You are an API routing system that operates with strict adherence to documented specifications. Your sole purpose is to precisely match user requests to API endpoints based on the provided documentation.
|
198 |
|
199 |
+
=== ABSOLUTE REQUIREMENTS ===
|
200 |
+
1. ENDPOINT SELECTION MUST BE GROUNDED IN DOCUMENTATION
|
201 |
+
2. ALL REQUIRED PARAMETERS MUST BE ACCOUNTED FOR
|
202 |
+
3. RESPONSE STRUCTURE MUST REMAIN UNCHANGED
|
|
|
203 |
|
204 |
+
=== INPUT DATA ===
|
205 |
+
Current Context:
|
206 |
+
- DateTime: {current_datetime}
|
207 |
+
- Timezone: {timezone}
|
208 |
+
- User Locale: {user_locale}
|
209 |
|
210 |
+
API Documentation:
|
211 |
{endpoints_documentation}
|
212 |
|
213 |
+
User Request:
|
214 |
+
- Query: {user_query}
|
215 |
+
- Language: {detected_language}
|
216 |
+
- Keywords: {extracted_keywords}
|
217 |
+
- Sentiment: {sentiment_analysis}
|
218 |
+
|
219 |
+
=== PROCESSING INSTRUCTIONS ===
|
220 |
+
1. Analyze the user request to determine:
|
221 |
+
- Core intent (what they want to accomplish)
|
222 |
+
- Target entity/resource
|
223 |
+
- Required operation type (CRUD)
|
224 |
+
|
225 |
+
2. Examine the API documentation to:
|
226 |
+
- Identify all endpoints related to the target entity
|
227 |
+
- Verify the endpoint's purpose matches the user intent
|
228 |
+
- Confirm the HTTP method aligns with the operation type
|
229 |
+
|
230 |
+
3. For the selected endpoint:
|
231 |
+
- Extract ALL documented parameters
|
232 |
+
- Determine parameter sources (query, history, or defaults)
|
233 |
+
- Validate parameter formats against specifications
|
234 |
+
- Convert dates/times to ISO 8601 format (YYYY-MM-DDTHH:mm:ss)
|
235 |
+
|
236 |
+
4. Validate your selection:
|
237 |
+
- The endpoint must directly satisfy the user's primary need
|
238 |
+
- All required parameters must be present or explicitly listed as missing
|
239 |
+
- No undocumented parameters may be included
|
240 |
+
|
241 |
+
=== OUTPUT FORMAT ===
|
242 |
+
{
|
243 |
+
"reasoning": {
|
244 |
+
"user_intent": "[concise description]",
|
245 |
+
"endpoint_selection": "[exact documentation reference]",
|
246 |
+
"parameter_analysis": "[source and validation for each parameter]"
|
247 |
+
},
|
248 |
+
"endpoint": "/documented/endpoint/path",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
"method": "HTTP_METHOD",
|
250 |
+
"params": {
|
251 |
+
"param1": "value" // only if properly sourced
|
252 |
+
},
|
253 |
+
"missing_required": [
|
254 |
+
"param1" // if required but unavailable
|
255 |
+
],
|
256 |
+
"confidence": 0.95 // 1.0 when all parameters are validated
|
257 |
+
}
|
258 |
+
|
259 |
+
=== STRICT ENFORCEMENT ===
|
260 |
+
- Empty params objects are prohibited when documentation requires parameters
|
261 |
+
- All missing required parameters must be explicitly listed
|
262 |
+
- Confidence scores must reflect parameter completeness
|
263 |
+
- Date/time formatting must be exact
|
264 |
+
- Never assume undocumented functionality
|
265 |
+
|
266 |
+
=== ERROR CONDITIONS ===
|
267 |
+
1. If no endpoint matches:
|
268 |
+
- Set "endpoint" to null
|
269 |
+
- Explain in "reasoning"
|
270 |
+
|
271 |
+
2. If critical parameters are missing:
|
272 |
+
- List ALL in "missing_required"
|
273 |
+
- Reduce confidence score accordingly
|
274 |
+
|
275 |
+
Your response will be validated against these requirements before being accepted.
|
|
|
276 |
""",
|
277 |
input_variables=[
|
278 |
"endpoints_documentation", "user_query", "detected_language",
|