Spaces:
Sleeping
Sleeping
class AppointmentScheduler: | |
def __init__(self): | |
self.state = "greeting" | |
self.patient_info = {} | |
def handle_incoming_speech(self, full_sentence): | |
self.transcription_response = full_sentence.lower() | |
if "goodbye" in self.transcription_response: | |
return "Goodbye! Have a great day!" | |
if self.state == "greeting": | |
llm_response = "Good morning! Thank you for calling Dr. Smith's office. How can I assist you today?" | |
self.state = "collecting_name" | |
elif self.state == "collecting_name": | |
if len(self.transcription_response.split()) >= 2: # Basic check for full name | |
llm_response = "I’d be happy to help you book an appointment. Can I have your full name, please?" | |
self.state = "collecting_contact" | |
else: | |
llm_response = "Could you please provide your full name?" | |
elif self.state == "collecting_contact": | |
if self.validate_name(self.transcription_response): # Validate name | |
self.patient_info['name'] = self.transcription_response | |
llm_response = "Thank you. Can I have your contact number, please?" | |
self.state = "understanding_needs" | |
else: | |
llm_response = "Sorry, I didn't get that. Could you please repeat your full name?" | |
elif self.state == "understanding_needs": | |
if self.validate_phone_number(self.transcription_response): # Validate phone number | |
self.patient_info['contact'] = self.transcription_response | |
llm_response = "What is the reason for your visit? This helps us allocate the right amount of time for your appointment." | |
self.state = "checking_availability" | |
else: | |
llm_response = "That doesn't seem to be a valid contact number. Please provide a valid phone number." | |
elif self.state == "checking_availability": | |
self.patient_info['reason'] = self.transcription_response | |
llm_response = "When would you prefer to schedule your appointment? I’ll check the available slots for that day." | |
self.state = "confirming_appointment" | |
elif self.state == "confirming_appointment": | |
self.patient_info['preferred_time'] = self.transcription_response | |
llm_response = "I have received your request. Please wait while I check availability." | |
# Add logic for checking appointment availability | |
# Proceed with state transition | |
self.state = "providing_additional_info" | |
elif self.state == "providing_additional_info": | |
llm_response = "Is there anything else I can help you with today? If you have any questions before your appointment, feel free to call us." | |
self.state = "greeting" | |
else: | |
llm_response = "I'm sorry, I didn’t understand that. Could you please clarify?" | |
return llm_response | |
def validate_phone_number(self, phone_number): | |
# Placeholder validation logic | |
return True if len(phone_number) == 10 and phone_number.isdigit() else False | |
def validate_name(self, name): | |
return True if len(name.split()) >= 2 else False | |