Spaces:
Running
Running
Commit
·
dda2e5f
1
Parent(s):
3214945
rollback
Browse files
main.py
CHANGED
@@ -446,135 +446,135 @@ class HealthcareChatbot:
|
|
446 |
)
|
447 |
|
448 |
# API response formatting prompt (reuse existing user_response_template)
|
449 |
-
# self.user_response_template = PromptTemplate(
|
450 |
-
# template="""
|
451 |
-
# You are a professional healthcare assistant. Answer the user's question using the provided API data.
|
452 |
-
|
453 |
-
# User Query: {user_query}
|
454 |
-
# User Sentiment: {sentiment_analysis}
|
455 |
-
# Response Language: {detected_language}
|
456 |
-
|
457 |
-
# API Response Data:
|
458 |
-
# {api_response}
|
459 |
-
|
460 |
-
# === INSTRUCTIONS ===
|
461 |
-
|
462 |
-
# 1. Read and understand the API response data above
|
463 |
-
# 2. Use ONLY the actual data from the API response - never make up information
|
464 |
-
# 3. Respond in {detected_language} language only
|
465 |
-
# 4. Write like you're talking to a friend or family member - warm, friendly, and caring
|
466 |
-
# 5. Make it sound natural and conversational, not like a system message
|
467 |
-
# 6. Convert technical data to simple, everyday language
|
468 |
-
|
469 |
-
# === DATE AND TIME FORMATTING ===
|
470 |
-
|
471 |
-
# When you see date_time fields like '2025-05-30T10:28:10':
|
472 |
-
# - For English: Convert to "May 30, 2025 at 10:28 AM"
|
473 |
-
# - For Arabic: Convert to "٣٠ مايو ٢٠٢٥ في الساعة ١٠:٢٨ صباحاً"
|
474 |
-
|
475 |
-
# === RESPONSE EXAMPLES ===
|
476 |
-
|
477 |
-
# For appointment confirmations:
|
478 |
-
# - English: "Great! I've got your appointment set up for May 30, 2025 at 10:28 AM. Everything looks good!"
|
479 |
-
# - Arabic: "ممتاز! موعدك محجوز يوم ٣٠ مايو ٢٠٢٥ الساعة ١٠:٢٨ صباحاً. كل شيء جاهز!"
|
480 |
-
|
481 |
-
# For appointment info:
|
482 |
-
# - English: "Your next appointment is on May 30, 2025 at 10:28 AM. See you then!"
|
483 |
-
# - Arabic: "موعدك القادم يوم ٣٠ مايو ٢٠٢٥ الساعة ١٠:٢٨ صباحاً. نراك قريباً!"
|
484 |
-
|
485 |
-
# === TONE GUIDELINES ===
|
486 |
-
# - Use friendly words like: "Great!", "Perfect!", "All set!", "ممتاز!", "رائع!", "تمام!"
|
487 |
-
# - Add reassuring phrases: "Everything looks good", "You're all set", "كل شيء جاهز", "تم بنجاح"
|
488 |
-
# - Sound helpful and caring, not robotic or formal
|
489 |
-
|
490 |
-
# === LANGUAGE FORMATTING ===
|
491 |
-
|
492 |
-
# For Arabic responses:
|
493 |
-
# - Use Arabic numerals: ٠١٢٣٤٥٦٧٨٩
|
494 |
-
# - Use Arabic month names: يناير، فبراير، مارس، أبريل، مايو، يونيو، يوليو، أغسطس، سبتمبر، أكتوبر، نوفمبر، ديسمبر
|
495 |
-
# - Friendly, warm Arabic tone
|
496 |
-
|
497 |
-
# For English responses:
|
498 |
-
# - Use standard English numerals
|
499 |
-
# - 12-hour time format with AM/PM
|
500 |
-
# - Friendly, conversational English tone
|
501 |
-
|
502 |
-
# === CRITICAL RULES ===
|
503 |
-
# - Extract dates and times exactly as they appear in the API response
|
504 |
-
# - Never use example dates or placeholder information
|
505 |
-
# - Respond only in the specified language
|
506 |
-
# - Make your response sound like a helpful friend, not a computer
|
507 |
-
# - Focus on answering the user's specific question with warmth and care
|
508 |
-
|
509 |
-
# Generate a friendly, helpful response using the API data provided above.
|
510 |
-
# """,
|
511 |
-
# input_variables=["user_query", "api_response", "detected_language", "sentiment_analysis"]
|
512 |
-
# )
|
513 |
self.user_response_template = PromptTemplate(
|
514 |
-
|
515 |
-
|
516 |
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
|
521 |
-
|
522 |
-
|
523 |
|
524 |
-
|
525 |
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
|
533 |
-
|
534 |
|
535 |
-
|
536 |
-
|
|
|
537 |
|
538 |
-
|
539 |
-
- Convert 'YYYY-MM-DDTHH:MM:SS' to readable format
|
540 |
-
- Example: '2025-06-01T08:00:00' becomes "June 1, 2025 at 8:00 AM"
|
541 |
-
- Use 12-hour format with AM/PM
|
542 |
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
- Arabic months: يناير، فبراير، مارس، أبريل، مايو، يونيو، يوليو، أغسطس، سبتمبر، أكتوبر، نوفمبر، ديسمبر
|
547 |
-
- Arabic numerals: ٠١٢٣٤٥٦٧٨٩
|
548 |
|
549 |
-
|
|
|
|
|
550 |
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
5. Respond warmly and helpfully
|
556 |
|
557 |
-
|
558 |
|
559 |
-
|
560 |
-
|
561 |
-
|
|
|
562 |
|
563 |
-
|
564 |
-
|
565 |
-
|
|
|
566 |
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
578 |
|
579 |
# Create chains
|
580 |
self.intent_chain = LLMChain(llm=self.llm, prompt=self.intent_classifier_template)
|
|
|
446 |
)
|
447 |
|
448 |
# API response formatting prompt (reuse existing user_response_template)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
self.user_response_template = PromptTemplate(
|
450 |
+
template="""
|
451 |
+
You are a professional healthcare assistant. Answer the user's question using the provided API data.
|
452 |
|
453 |
+
User Query: {user_query}
|
454 |
+
User Sentiment: {sentiment_analysis}
|
455 |
+
Response Language: {detected_language}
|
456 |
|
457 |
+
API Response Data:
|
458 |
+
{api_response}
|
459 |
|
460 |
+
=== INSTRUCTIONS ===
|
461 |
|
462 |
+
1. Read and understand the API response data above
|
463 |
+
2. Use ONLY the actual data from the API response - never make up information
|
464 |
+
3. Respond in {detected_language} language only
|
465 |
+
4. Write like you're talking to a friend or family member - warm, friendly, and caring
|
466 |
+
5. Make it sound natural and conversational, not like a system message
|
467 |
+
6. Convert technical data to simple, everyday language
|
468 |
|
469 |
+
=== DATE AND TIME FORMATTING ===
|
470 |
|
471 |
+
When you see date_time fields like '2025-05-30T10:28:10':
|
472 |
+
- For English: Convert to "May 30, 2025 at 10:28 AM"
|
473 |
+
- For Arabic: Convert to "٣٠ مايو ٢٠٢٥ في الساعة ١٠:٢٨ صباحاً"
|
474 |
|
475 |
+
=== RESPONSE EXAMPLES ===
|
|
|
|
|
|
|
476 |
|
477 |
+
For appointment confirmations:
|
478 |
+
- English: "Great! I've got your appointment set up for May 30, 2025 at 10:28 AM. Everything looks good!"
|
479 |
+
- Arabic: "ممتاز! موعدك محجوز يوم ٣٠ مايو ٢٠٢٥ الساعة ١٠:٢٨ صباحاً. كل شيء جاهز!"
|
|
|
|
|
480 |
|
481 |
+
For appointment info:
|
482 |
+
- English: "Your next appointment is on May 30, 2025 at 10:28 AM. See you then!"
|
483 |
+
- Arabic: "موعدك القادم يوم ٣٠ مايو ٢٠٢٥ الساعة ١٠:٢٨ صباحاً. نراك قريباً!"
|
484 |
|
485 |
+
=== TONE GUIDELINES ===
|
486 |
+
- Use friendly words like: "Great!", "Perfect!", "All set!", "ممتاز!", "رائع!", "تمام!"
|
487 |
+
- Add reassuring phrases: "Everything looks good", "You're all set", "كل شيء جاهز", "تم بنجاح"
|
488 |
+
- Sound helpful and caring, not robotic or formal
|
|
|
489 |
|
490 |
+
=== LANGUAGE FORMATTING ===
|
491 |
|
492 |
+
For Arabic responses:
|
493 |
+
- Use Arabic numerals: ٠١٢٣٤٥٦٧٨٩
|
494 |
+
- Use Arabic month names: يناير، فبراير، مارس، أبريل، مايو، يونيو، يوليو، أغسطس، سبتمبر، أكتوبر، نوفمبر، ديسمبر
|
495 |
+
- Friendly, warm Arabic tone
|
496 |
|
497 |
+
For English responses:
|
498 |
+
- Use standard English numerals
|
499 |
+
- 12-hour time format with AM/PM
|
500 |
+
- Friendly, conversational English tone
|
501 |
|
502 |
+
=== CRITICAL RULES ===
|
503 |
+
- Extract dates and times exactly as they appear in the API response
|
504 |
+
- Never use example dates or placeholder information
|
505 |
+
- Respond only in the specified language
|
506 |
+
- Make your response sound like a helpful friend, not a computer
|
507 |
+
- Focus on answering the user's specific question with warmth and care
|
508 |
|
509 |
+
Generate a friendly, helpful response using the API data provided above.
|
510 |
+
""",
|
511 |
+
input_variables=["user_query", "api_response", "detected_language", "sentiment_analysis"]
|
512 |
+
)
|
513 |
+
# self.user_response_template = PromptTemplate(
|
514 |
+
# template="""
|
515 |
+
# You are a professional healthcare assistant. Your task is to carefully analyze the API data and respond to the user's question accurately.
|
516 |
+
|
517 |
+
# User Query: {user_query}
|
518 |
+
# User Sentiment: {sentiment_analysis}
|
519 |
+
# Response Language: {detected_language}
|
520 |
+
|
521 |
+
# API Response Data:
|
522 |
+
# {api_response}
|
523 |
+
|
524 |
+
# === CRITICAL INSTRUCTIONS ===
|
525 |
+
|
526 |
+
# 1. FIRST: Carefully read and analyze the API response data above
|
527 |
+
# 2. SECOND: Identify all date_time fields in the format 'YYYY-MM-DDTHH:MM:SS'
|
528 |
+
# 3. THIRD: Extract the EXACT dates and times from the API response - DO NOT use any example dates
|
529 |
+
# 4. FOURTH: Convert these extracted dates to the user-friendly format specified below
|
530 |
+
# 5. FIFTH: Respond ONLY in {detected_language} language
|
531 |
+
# 6. Use a warm, friendly, conversational tone like talking to a friend
|
532 |
+
|
533 |
+
# === DATE EXTRACTION AND CONVERSION ===
|
534 |
+
|
535 |
+
# Step 1: Find date_time fields in the API response (format: 'YYYY-MM-DDTHH:MM:SS')
|
536 |
+
# Step 2: Convert ONLY the actual extracted dates using these rules:
|
537 |
+
|
538 |
+
# For English:
|
539 |
+
# - Convert 'YYYY-MM-DDTHH:MM:SS' to readable format
|
540 |
+
# - Example: '2025-06-01T08:00:00' becomes "June 1, 2025 at 8:00 AM"
|
541 |
+
# - Use 12-hour format with AM/PM
|
542 |
+
|
543 |
+
# For Arabic:
|
544 |
+
# - Convert to Arabic numerals and month names
|
545 |
+
# - Example: '2025-06-01T08:00:00' becomes "١ يونيو ٢٠٢٥ في الساعة ٨:٠٠ صباحاً"
|
546 |
+
# - Arabic months: يناير، فبراير، مارس، أبريل، مايو، يونيو، يوليو، أغسطس، سبتمبر، أكتوبر، نوفمبر، ديسمبر
|
547 |
+
# - Arabic numerals: ٠١٢٣٤٥٦٧٨٩
|
548 |
+
|
549 |
+
# === RESPONSE APPROACH ===
|
550 |
+
|
551 |
+
# 1. Analyze what the user is asking for
|
552 |
+
# 2. Find the relevant information in the API response
|
553 |
+
# 3. Extract actual dates/times from the API data
|
554 |
+
# 4. Convert technical information to simple language
|
555 |
+
# 5. Respond warmly and helpfully
|
556 |
+
|
557 |
+
# === TONE AND LANGUAGE ===
|
558 |
+
|
559 |
+
# English responses:
|
560 |
+
# - Use phrases like: "Great!", "Perfect!", "All set!", "Here's what I found:"
|
561 |
+
# - Be conversational and reassuring
|
562 |
+
|
563 |
+
# Arabic responses:
|
564 |
+
# - Use phrases like: "ممتاز!", "رائع!", "تمام!", "إليك ما وجدته:"
|
565 |
+
# - Be warm and helpful in Arabic style
|
566 |
+
|
567 |
+
# === IMPORTANT REMINDERS ===
|
568 |
+
# - NEVER use example dates from this prompt
|
569 |
+
# - ALWAYS extract dates from the actual API response data
|
570 |
+
# - If no dates exist in API response, don't mention any dates
|
571 |
+
# - Stay focused on answering the user's specific question
|
572 |
+
# - Use only information that exists in the API response
|
573 |
+
|
574 |
+
# Now, carefully analyze the API response above and generate a helpful response to the user's query using ONLY the actual data provided.
|
575 |
+
# """,
|
576 |
+
# input_variables=["user_query", "api_response", "detected_language", "sentiment_analysis"]
|
577 |
+
# )
|
578 |
|
579 |
# Create chains
|
580 |
self.intent_chain = LLMChain(llm=self.llm, prompt=self.intent_classifier_template)
|