Spaces:
Running
Running
Commit
·
5e0c36d
1
Parent(s):
e805531
prompt
Browse files
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
|
|
|
|
|
|
|
160 |
|
161 |
-
## Available API Endpoints
|
162 |
{endpoints_documentation}
|
163 |
|
164 |
-
## User Query
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
-
|
181 |
-
-
|
182 |
-
|
183 |
-
*
|
184 |
-
*
|
185 |
-
*
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
-
|
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.
|
200 |
-
"reasoning": "
|
201 |
-
"endpoint": "/endpoint/path
|
202 |
-
"method": "
|
203 |
"params": {{}},
|
204 |
"missing_required": []
|
205 |
}}
|
206 |
|
207 |
-
|
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="""
|