abdibrahem commited on
Commit
af7e05e
·
1 Parent(s): f7a66e6

Update prompt

Browse files
Files changed (1) hide show
  1. main.py +78 -6
main.py CHANGED
@@ -158,8 +158,9 @@ class HealthcareChatbot:
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}
@@ -167,6 +168,9 @@ class HealthcareChatbot:
167
  ## User Query to Analyze
168
  Query: "{user_query}"
169
  Language: {detected_language}
 
 
 
170
 
171
  ## Step-by-Step Analysis
172
 
@@ -175,7 +179,22 @@ class HealthcareChatbot:
175
  - Identify the exact action or information the user is requesting
176
  - Focus on understanding their underlying need, not just the words
177
 
178
- **STEP 2: Find matching endpoint**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  - Read each endpoint description in the documentation
180
  - Check if any endpoint's purpose can fulfill what the user wants
181
  - Match based on functionality, not keywords
@@ -184,11 +203,16 @@ class HealthcareChatbot:
184
  - Found matching endpoint = "API_ACTION"
185
  - No matching endpoint = "CONVERSATION"
186
 
 
 
 
 
 
187
  ## Output Format
188
  {{
189
  "intent": "CONVERSATION|API_ACTION",
190
  "confidence": 0.8,
191
- "reasoning": "User wants: [what user actually needs]. Found endpoint: [endpoint path and why it matches] OR No endpoint matches this need",
192
  "endpoint": "/exact/endpoint/path",
193
  "method": "GET|POST|PUT|DELETE",
194
  "params": {{}},
@@ -198,8 +222,54 @@ class HealthcareChatbot:
198
  Now analyze the user query step by step and give me the JSON response.
199
  """,
200
  input_variables=["user_query", "detected_language", "extracted_keywords",
201
- "sentiment_analysis", "endpoints_documentation"]
202
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  # CONVERSATION CHAIN - Handles conversational responses
204
  self.conversation_template = PromptTemplate(
205
  template="""
@@ -666,7 +736,9 @@ class HealthcareChatbot:
666
  "extracted_keywords": json.dumps(keywords),
667
  "sentiment_analysis": json.dumps(sentiment_result),
668
  "conversation_history": self.get_conversation_context(),
669
- "endpoints_documentation": json.dumps(self.endpoints_documentation, indent=2)
 
 
670
  })
671
 
672
  # Parse router response
 
158
  template="""
159
  You are a routing system. Your job is simple:
160
  1. Understand what the user wants
161
+ 2. Handle any dates/times in their request
162
+ 3. Check if any endpoint can do what they want
163
+ 4. If yes = API_ACTION, if no = CONVERSATION
164
 
165
  ## Available API Endpoints Documentation
166
  {endpoints_documentation}
 
168
  ## User Query to Analyze
169
  Query: "{user_query}"
170
  Language: {detected_language}
171
+ Current Context:
172
+ - DateTime: {current_datetime}
173
+ - Timezone: {timezone}
174
 
175
  ## Step-by-Step Analysis
176
 
 
179
  - Identify the exact action or information the user is requesting
180
  - Focus on understanding their underlying need, not just the words
181
 
182
+ **STEP 2: Handle Date/Time Processing**
183
+ - Identify any temporal expressions in the user query
184
+ - Convert relative dates/times using the current context:
185
+ * "اليوم" (today) = current date
186
+ * "غدا" (tomorrow) = current date + 1 day
187
+ * "أمس" (yesterday) = current date - 1 day
188
+ * "الأسبوع القادم" (next week) = current date + 7 days
189
+ * "بعد ساعتين" (in 2 hours) = current time + 2 hours
190
+ * "صباحًا" (morning/AM), "مساءً" (evening/PM)
191
+ * "الشهر القادم" (next month) = current date + 1 month
192
+ * "الأسبوع الماضي" (last week) = current date - 7 days
193
+ - Handle different date formats and languages
194
+ - Account for timezone differences
195
+ - Convert to ISO 8601 format: YYYY-MM-DDTHH:MM:SS
196
+
197
+ **STEP 3: Find matching endpoint**
198
  - Read each endpoint description in the documentation
199
  - Check if any endpoint's purpose can fulfill what the user wants
200
  - Match based on functionality, not keywords
 
203
  - Found matching endpoint = "API_ACTION"
204
  - No matching endpoint = "CONVERSATION"
205
 
206
+ **STEP 4: Parameter Extraction (only if API_ACTION)**
207
+ - Extract parameter values from user query
208
+ - Convert dates/times to ISO 8601 format (YYYY-MM-DDTHH:MM:SS) using the context above
209
+ - List any missing required parameters
210
+
211
  ## Output Format
212
  {{
213
  "intent": "CONVERSATION|API_ACTION",
214
  "confidence": 0.8,
215
+ "reasoning": "User wants: [what user actually needs]. Date/time processing: [any date conversions made]. Found endpoint: [endpoint path and why it matches] OR No endpoint matches this need",
216
  "endpoint": "/exact/endpoint/path",
217
  "method": "GET|POST|PUT|DELETE",
218
  "params": {{}},
 
222
  Now analyze the user query step by step and give me the JSON response.
223
  """,
224
  input_variables=["user_query", "detected_language", "extracted_keywords",
225
+ "sentiment_analysis", "endpoints_documentation", "current_datetime", "timezone"]
226
  )
227
+ # self.router_prompt_template = PromptTemplate(
228
+ # template="""
229
+ # You are a routing system. Your job is simple:
230
+ # 1. Understand what the user wants
231
+ # 2. Check if any endpoint can do what they want
232
+ # 3. If yes = API_ACTION, if no = CONVERSATION
233
+
234
+ # ## Available API Endpoints Documentation
235
+ # {endpoints_documentation}
236
+
237
+ # ## User Query to Analyze
238
+ # Query: "{user_query}"
239
+ # Language: {detected_language}
240
+
241
+ # ## Step-by-Step Analysis
242
+
243
+ # **STEP 1: What does the user want?**
244
+ # - If query is in Arabic, translate it to English first
245
+ # - Identify the exact action or information the user is requesting
246
+ # - Focus on understanding their underlying need, not just the words
247
+
248
+ # **STEP 2: Find matching endpoint**
249
+ # - Read each endpoint description in the documentation
250
+ # - Check if any endpoint's purpose can fulfill what the user wants
251
+ # - Match based on functionality, not keywords
252
+
253
+ # **STEP 3: Decision**
254
+ # - Found matching endpoint = "API_ACTION"
255
+ # - No matching endpoint = "CONVERSATION"
256
+
257
+ # ## Output Format
258
+ # {{
259
+ # "intent": "CONVERSATION|API_ACTION",
260
+ # "confidence": 0.8,
261
+ # "reasoning": "User wants: [what user actually needs]. Found endpoint: [endpoint path and why it matches] OR No endpoint matches this need",
262
+ # "endpoint": "/exact/endpoint/path",
263
+ # "method": "GET|POST|PUT|DELETE",
264
+ # "params": {{}},
265
+ # "missing_required": []
266
+ # }}
267
+
268
+ # Now analyze the user query step by step and give me the JSON response.
269
+ # """,
270
+ # input_variables=["user_query", "detected_language", "extracted_keywords",
271
+ # "sentiment_analysis", "endpoints_documentation"]
272
+ # )
273
  # CONVERSATION CHAIN - Handles conversational responses
274
  self.conversation_template = PromptTemplate(
275
  template="""
 
736
  "extracted_keywords": json.dumps(keywords),
737
  "sentiment_analysis": json.dumps(sentiment_result),
738
  "conversation_history": self.get_conversation_context(),
739
+ "endpoints_documentation": json.dumps(self.endpoints_documentation, indent=2),
740
+ "current_datetime": datetime.now().strftime('%Y-%m-%dT%H:%M:%S'),
741
+ "timezone": "UTC",
742
  })
743
 
744
  # Parse router response