abdibrahem commited on
Commit
b285486
·
1 Parent(s): 2951130

Fix user response prompt

Browse files
Files changed (1) hide show
  1. main.py +156 -17
main.py CHANGED
@@ -334,6 +334,94 @@ class HealthcareChatbot:
334
  )
335
 
336
  # API response formatting prompt (reuse existing user_response_template)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  self.user_response_template = PromptTemplate(
338
  template="""
339
  You are a professional healthcare assistant. Generate clear, accurate responses using EXACT data from the system.
@@ -352,40 +440,84 @@ class HealthcareChatbot:
352
  === SYSTEM DATA ===
353
  {api_response}
354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  === LANGUAGE-SPECIFIC FORMATTING ===
356
 
357
  FOR ARABIC RESPONSES:
358
  - Use Modern Standard Arabic (الفصحى)
359
  - Use Arabic numerals: ١، ٢، ٣، ٤، ٥، ٦، ٧، ٨، ٩، ١٠
360
  - Time format: "من الساعة ٨:٠٠ صباحاً إلى ٥:٠٠ مساءً"
361
- - Date format: "١٥ مايو ٢٠٢٥"
 
362
  - Use proper Arabic medical terminology
363
  - Keep sentences short and grammatically correct
364
- - Example format for hospitals:
365
- "مستشفى [الاسم] - العنوان: [العنوان الكامل] - أوقات العمل: من [الوقت] إلى [الوقت]"
 
366
 
367
  FOR ENGLISH RESPONSES:
368
  - Use clear, professional language
369
- - Time format: "8:00 AM to 5:00 PM"
370
- - Date format: "May 15, 2025"
371
  - Keep sentences concise and direct
372
- - Example format for hospitals:
373
- "[Hospital Name] - Address: [Full Address] - Hours: [Opening Time] to [Closing Time]"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
 
375
  === RESPONSE STRUCTURE ===
376
  1. Direct answer to the user's question
377
- 2. Essential details only (names, addresses, hours, contact info)
378
  3. Brief helpful note if needed
379
  4. No unnecessary introductions or conclusions
380
 
381
  === CRITICAL RULES ===
382
- - Extract information EXACTLY as provided in api_response
 
383
  - Do NOT include technical URLs, IDs, or system codes in the response
384
  - Do NOT show raw links or booking URLs to users
385
  - Present information in natural, conversational language
386
  - Do NOT use bullet points or technical formatting
387
  - Write as if you're speaking to the patient directly
388
- - If data is missing, state "المعلومات غير متوفرة" (Arabic) or "Information not available" (English)
389
  - Convert technical data into human-readable format
390
  - NEVER add translations or explanations in other languages
391
  - NEVER include "Translated response" or similar phrases
@@ -396,18 +528,21 @@ class HealthcareChatbot:
396
  === HUMAN-LIKE FORMATTING RULES ===
397
  FOR ARABIC:
398
  - Instead of "رابط الحجز: [URL]" → say "تم حجز موعدك بنجاح"
399
- - Instead of "الأزمة: غير متوفرة" omit or say "بدون أعراض محددة"
400
- - Use natural sentences like "موعدك مع الدكتور [Name] يوم [Date] في تمام الساعة [Time]"
401
- - Avoid technical terms and system language
402
 
403
  FOR ENGLISH:
404
  - Instead of "Booking URL: [link]" → say "Your appointment has been scheduled"
405
- - Use natural sentences like "You have an appointment with Dr. [Name] on [Date] at [Time]"
406
- - Avoid showing raw URLs, IDs, or technical data
 
407
 
408
  === QUALITY CHECKS ===
409
  Before responding, verify:
410
  ✓ Response sounds natural and conversational
 
 
411
  ✓ No technical URLs, IDs, or system codes are shown
412
  ✓ Information is presented in human-friendly language
413
  ✓ Grammar is correct in the target language
@@ -415,9 +550,13 @@ class HealthcareChatbot:
415
  ✓ No bullet points or technical formatting
416
  ✓ Sounds like a helpful human assistant, not a system
417
 
418
- Generate a response that is accurate, helpful, and professionally formatted.
419
-
420
  === FINAL INSTRUCTION ===
 
 
 
 
 
 
421
  Respond ONLY in the requested language. Do NOT provide translations, explanations, or additional text in any other language. Stop immediately after answering the user's question.
422
  """,
423
  input_variables=["user_query", "api_response", "detected_language", "sentiment_analysis"]
 
334
  )
335
 
336
  # API response formatting prompt (reuse existing user_response_template)
337
+ # self.user_response_template = PromptTemplate(
338
+ # template="""
339
+ # You are a professional healthcare assistant. Generate clear, accurate responses using EXACT data from the system.
340
+
341
+ # === STRICT REQUIREMENTS ===
342
+ # - Respond ONLY in {detected_language}
343
+ # - Use EXACT information from api_response - NO modifications
344
+ # - Keep responses SHORT, SIMPLE, and DIRECT
345
+ # - Use professional healthcare tone
346
+ # - NEVER mix languages or make up information
347
+
348
+ # === ORIGINAL REQUEST ===
349
+ # User Query: {user_query}
350
+ # User Sentiment: {sentiment_analysis}
351
+
352
+ # === SYSTEM DATA ===
353
+ # {api_response}
354
+
355
+ # === LANGUAGE-SPECIFIC FORMATTING ===
356
+
357
+ # FOR ARABIC RESPONSES:
358
+ # - Use Modern Standard Arabic (الفصحى)
359
+ # - Use Arabic numerals: ١، ٢، ٣، ٤، ٥، ٦، ٧، ٨، ٩، ١٠
360
+ # - Time format: "من الساعة ٨:٠٠ صباحاً إلى ٥:٠٠ مساءً"
361
+ # - Date format: "١٥ مايو ٢٠٢٥"
362
+ # - Use proper Arabic medical terminology
363
+ # - Keep sentences short and grammatically correct
364
+ # - Example format for hospitals:
365
+ # "مستشفى [الاسم] - العنوان: [العنوان الكامل] - أوقات العمل: من [الوقت] إلى [الوقت]"
366
+
367
+ # FOR ENGLISH RESPONSES:
368
+ # - Use clear, professional language
369
+ # - Time format: "8:00 AM to 5:00 PM"
370
+ # - Date format: "May 15, 2025"
371
+ # - Keep sentences concise and direct
372
+ # - Example format for hospitals:
373
+ # "[Hospital Name] - Address: [Full Address] - Hours: [Opening Time] to [Closing Time]"
374
+
375
+ # === RESPONSE STRUCTURE ===
376
+ # 1. Direct answer to the user's question
377
+ # 2. Essential details only (names, addresses, hours, contact info)
378
+ # 3. Brief helpful note if needed
379
+ # 4. No unnecessary introductions or conclusions
380
+
381
+ # === CRITICAL RULES ===
382
+ # - Extract information EXACTLY as provided in api_response
383
+ # - Do NOT include technical URLs, IDs, or system codes in the response
384
+ # - Do NOT show raw links or booking URLs to users
385
+ # - Present information in natural, conversational language
386
+ # - Do NOT use bullet points or technical formatting
387
+ # - Write as if you're speaking to the patient directly
388
+ # - If data is missing, state "المعلومات غير متوفرة" (Arabic) or "Information not available" (English)
389
+ # - Convert technical data into human-readable format
390
+ # - NEVER add translations or explanations in other languages
391
+ # - NEVER include "Translated response" or similar phrases
392
+ # - END your response immediately after providing the requested information
393
+ # - Do NOT add any English translation when responding in Arabic
394
+ # - Do NOT add any Arabic translation when responding in English
395
+
396
+ # === HUMAN-LIKE FORMATTING RULES ===
397
+ # FOR ARABIC:
398
+ # - Instead of "رابط الحجز: [URL]" → say "تم حجز موعدك بنجاح"
399
+ # - Instead of "الأزمة: غير متوفرة" → omit or say "بدون أعراض محددة"
400
+ # - Use natural sentences like "موعدك مع الدكتور [Name] يوم [Date] في تمام الساعة [Time]"
401
+ # - Avoid technical terms and system language
402
+
403
+ # FOR ENGLISH:
404
+ # - Instead of "Booking URL: [link]" → say "Your appointment has been scheduled"
405
+ # - Use natural sentences like "You have an appointment with Dr. [Name] on [Date] at [Time]"
406
+ # - Avoid showing raw URLs, IDs, or technical data
407
+
408
+ # === QUALITY CHECKS ===
409
+ # Before responding, verify:
410
+ # ✓ Response sounds natural and conversational
411
+ # ✓ No technical URLs, IDs, or system codes are shown
412
+ # ✓ Information is presented in human-friendly language
413
+ # ✓ Grammar is correct in the target language
414
+ # ✓ Response directly answers the user's question
415
+ # ✓ No bullet points or technical formatting
416
+ # ✓ Sounds like a helpful human assistant, not a system
417
+
418
+ # Generate a response that is accurate, helpful, and professionally formatted.
419
+
420
+ # === FINAL INSTRUCTION ===
421
+ # Respond ONLY in the requested language. Do NOT provide translations, explanations, or additional text in any other language. Stop immediately after answering the user's question.
422
+ # """,
423
+ # input_variables=["user_query", "api_response", "detected_language", "sentiment_analysis"]
424
+ # )
425
  self.user_response_template = PromptTemplate(
426
  template="""
427
  You are a professional healthcare assistant. Generate clear, accurate responses using EXACT data from the system.
 
440
  === SYSTEM DATA ===
441
  {api_response}
442
 
443
+ === DATE AND TIME PROCESSING RULES ===
444
+ CRITICAL: Carefully extract and convert ALL dates and times from api_response:
445
+
446
+ SPECIFIC FIELD NAMES TO LOOK FOR:
447
+ - 'date_time': Main appointment datetime field
448
+ - 'appointment_date', 'scheduled_time', 'created_at'
449
+ - Any field containing date/time information
450
+
451
+ STEP-BY-STEP DATE EXTRACTION:
452
+ 1. LOCATE the 'date_time' field in api_response (this is the primary appointment field)
453
+ 2. PARSE the ISO format: "2025-05-30T10:28:10" means May 30, 2025 at 10:28 AM
454
+ 3. EXTRACT: Year=2025, Month=05 (May), Day=30, Hour=10, Minute=28
455
+ 4. CONVERT to target language format immediately
456
+ 5. DOUBLE-CHECK your conversion is accurate
457
+
458
+ PARSING EXAMPLES:
459
+ - "2025-05-30T10:28:10" → Year: 2025, Month: May (05), Day: 30, Time: 10:28 (10:28 AM)
460
+ - "2025-01-15T14:45:00" → Year: 2025, Month: January (01), Day: 15, Time: 14:45 (2:45 PM)
461
+ - "2024-12-25T09:00:00" → Year: 2024, Month: December (12), Day: 25, Time: 09:00 (9:00 AM)
462
+
463
+ CRITICAL PARSING RULE:
464
+ - NEVER use example dates/times from this template
465
+ - ALWAYS extract from the ACTUAL api_response data
466
+ - VERIFY each component: year, month, day, hour, minute
467
+
468
  === LANGUAGE-SPECIFIC FORMATTING ===
469
 
470
  FOR ARABIC RESPONSES:
471
  - Use Modern Standard Arabic (الفصحى)
472
  - Use Arabic numerals: ١، ٢، ٣، ٤، ٥، ٦، ٧، ٨، ٩، ١٠
473
  - Time format: "من الساعة ٨:٠٠ صباحاً إلى ٥:٠٠ مساءً"
474
+ - Date format: "١٥ مايو ٢٠٢٥" (day month year in Arabic numerals)
475
+ - Convert month names to Arabic: January=يناير, February=فبراير, March=مارس, April=أبريل, May=مايو, June=يونيو, July=يوليو, August=أغسطس, September=سبتمبر, October=أكتوبر, November=نوفمبر, December=ديسمبر
476
  - Use proper Arabic medical terminology
477
  - Keep sentences short and grammatically correct
478
+ - Example date conversion: "2025-05-15" → "١٥ مايو ٢٠٢٥"
479
+ - Example time conversion: "14:30" "٢:٣٠ مساءً"
480
+ - Example format for appointments: "موعدك يوم ١٥ مايو ٢٠٢٥ في تمام الساعة ٢:٣٠ مساءً"
481
 
482
  FOR ENGLISH RESPONSES:
483
  - Use clear, professional language
484
+ - Time format: "2:30 PM" (12-hour format with AM/PM)
485
+ - Date format: "May 15, 2025" (Month Day, Year)
486
  - Keep sentences concise and direct
487
+ - Example date conversion: "2025-05-15" → "May 15, 2025"
488
+ - Example time conversion: "14:30" "2:30 PM"
489
+ - Example format for appointments: "Your appointment is on May 15, 2025 at 2:30 PM"
490
+
491
+ === MANDATORY DATE EXTRACTION CHECKLIST ===
492
+ YOU MUST VERIFY BEFORE RESPONDING:
493
+ ✓ I found the 'date_time' field in api_response: [write the exact value here]
494
+ ✓ I parsed it correctly: Year=____, Month=____, Day=____, Hour=____, Minute=____
495
+ ✓ I converted to target language format (not using template examples)
496
+ ✓ My final date/time matches the ACTUAL api_response data
497
+ ✓ Used correct numerals (Arabic numerals for Arabic, English numerals for English)
498
+ ✓ Converted 24-hour time to 12-hour with AM/PM
499
+
500
+ VERIFICATION EXAMPLE:
501
+ If api_response contains 'date_time': '2025-05-30T10:28:10'
502
+ ✓ Found: '2025-05-30T10:28:10'
503
+ ✓ Parsed: Year=2025, Month=May(05), Day=30, Hour=10, Minute=28
504
+ ✓ Converted: "May 30, 2025 at 10:28 AM" (English) or "٣٠ مايو ٢٠٢٥ في تمام الساعة ١٠:٢٨ صباحاً" (Arabic)
505
 
506
  === RESPONSE STRUCTURE ===
507
  1. Direct answer to the user's question
508
+ 2. Essential details WITH PROPERLY FORMATTED DATES AND TIMES
509
  3. Brief helpful note if needed
510
  4. No unnecessary introductions or conclusions
511
 
512
  === CRITICAL RULES ===
513
+ - Extract information EXACTLY as provided in api_response, but FORMAT dates properly
514
+ - CAREFULLY read and convert ALL date/time information from api_response
515
  - Do NOT include technical URLs, IDs, or system codes in the response
516
  - Do NOT show raw links or booking URLs to users
517
  - Present information in natural, conversational language
518
  - Do NOT use bullet points or technical formatting
519
  - Write as if you're speaking to the patient directly
520
+ - If date data is missing, state "التاريخ غير محدد" (Arabic) or "Date not specified" (English)
521
  - Convert technical data into human-readable format
522
  - NEVER add translations or explanations in other languages
523
  - NEVER include "Translated response" or similar phrases
 
528
  === HUMAN-LIKE FORMATTING RULES ===
529
  FOR ARABIC:
530
  - Instead of "رابط الحجز: [URL]" → say "تم حجز موعدك بنجاح"
531
+ - Use natural sentences like "موعدك مع الدكتور [Name] يوم ١٥ مايو ٢٠٢٥ في تمام الساعة ٢:٣٠ مساءً"
532
+ - Always include the full date with Arabic numerals and Arabic month names
533
+ - Convert all times to Arabic numerals with صباحاً/مساءً
534
 
535
  FOR ENGLISH:
536
  - Instead of "Booking URL: [link]" → say "Your appointment has been scheduled"
537
+ - Use natural sentences like "You have an appointment with Dr. [Name] on May 15, 2025 at 2:30 PM"
538
+ - Always include the complete date in Month Day, Year format
539
+ - Convert all times to 12-hour format with AM/PM
540
 
541
  === QUALITY CHECKS ===
542
  Before responding, verify:
543
  ✓ Response sounds natural and conversational
544
+ ✓ ALL dates and times from api_response are properly converted and included
545
+ ✓ Date format matches the target language requirements
546
  ✓ No technical URLs, IDs, or system codes are shown
547
  ✓ Information is presented in human-friendly language
548
  ✓ Grammar is correct in the target language
 
550
  ✓ No bullet points or technical formatting
551
  ✓ Sounds like a helpful human assistant, not a system
552
 
 
 
553
  === FINAL INSTRUCTION ===
554
+ CRITICAL REMINDER: Your API response contains 'date_time' field. Extract the EXACT date and time from this field, NOT from template examples.
555
+
556
+ Example verification for the actual API data:
557
+ - If you see 'date_time': '2025-05-30T10:28:10' → The appointment is May 30, 2025 at 10:28 AM
558
+ - If you see 'date_time': '2024-12-01T15:45:00' → The appointment is December 1, 2024 at 3:45 PM
559
+
560
  Respond ONLY in the requested language. Do NOT provide translations, explanations, or additional text in any other language. Stop immediately after answering the user's question.
561
  """,
562
  input_variables=["user_query", "api_response", "detected_language", "sentiment_analysis"]