Spaces:
Sleeping
Sleeping
nileshhanotia
commited on
Commit
•
8f05cbd
1
Parent(s):
ca9766d
Create AppointmentScheduler.py
Browse files- AppointmentScheduler.py +66 -0
AppointmentScheduler.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class AppointmentScheduler:
|
2 |
+
def __init__(self):
|
3 |
+
self.state = "greeting"
|
4 |
+
self.patient_info = {}
|
5 |
+
|
6 |
+
def handle_incoming_speech(self, full_sentence):
|
7 |
+
self.transcription_response = full_sentence.lower()
|
8 |
+
|
9 |
+
if "goodbye" in self.transcription_response:
|
10 |
+
return "Goodbye! Have a great day!"
|
11 |
+
|
12 |
+
if self.state == "greeting":
|
13 |
+
llm_response = "Good morning! Thank you for calling Dr. Smith's office. How can I assist you today?"
|
14 |
+
self.state = "collecting_name"
|
15 |
+
|
16 |
+
elif self.state == "collecting_name":
|
17 |
+
if len(self.transcription_response.split()) >= 2: # Basic check for full name
|
18 |
+
llm_response = "I’d be happy to help you book an appointment. Can I have your full name, please?"
|
19 |
+
self.state = "collecting_contact"
|
20 |
+
else:
|
21 |
+
llm_response = "Could you please provide your full name?"
|
22 |
+
|
23 |
+
elif self.state == "collecting_contact":
|
24 |
+
if self.validate_name(self.transcription_response): # Validate name
|
25 |
+
self.patient_info['name'] = self.transcription_response
|
26 |
+
llm_response = "Thank you. Can I have your contact number, please?"
|
27 |
+
self.state = "understanding_needs"
|
28 |
+
else:
|
29 |
+
llm_response = "Sorry, I didn't get that. Could you please repeat your full name?"
|
30 |
+
|
31 |
+
elif self.state == "understanding_needs":
|
32 |
+
if self.validate_phone_number(self.transcription_response): # Validate phone number
|
33 |
+
self.patient_info['contact'] = self.transcription_response
|
34 |
+
llm_response = "What is the reason for your visit? This helps us allocate the right amount of time for your appointment."
|
35 |
+
self.state = "checking_availability"
|
36 |
+
else:
|
37 |
+
llm_response = "That doesn't seem to be a valid contact number. Please provide a valid phone number."
|
38 |
+
|
39 |
+
elif self.state == "checking_availability":
|
40 |
+
self.patient_info['reason'] = self.transcription_response
|
41 |
+
llm_response = "When would you prefer to schedule your appointment? I’ll check the available slots for that day."
|
42 |
+
self.state = "confirming_appointment"
|
43 |
+
|
44 |
+
elif self.state == "confirming_appointment":
|
45 |
+
self.patient_info['preferred_time'] = self.transcription_response
|
46 |
+
llm_response = "I have received your request. Please wait while I check availability."
|
47 |
+
# Add logic for checking appointment availability
|
48 |
+
|
49 |
+
# Proceed with state transition
|
50 |
+
self.state = "providing_additional_info"
|
51 |
+
|
52 |
+
elif self.state == "providing_additional_info":
|
53 |
+
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."
|
54 |
+
self.state = "greeting"
|
55 |
+
|
56 |
+
else:
|
57 |
+
llm_response = "I'm sorry, I didn’t understand that. Could you please clarify?"
|
58 |
+
|
59 |
+
return llm_response
|
60 |
+
|
61 |
+
def validate_phone_number(self, phone_number):
|
62 |
+
# Placeholder validation logic
|
63 |
+
return True if len(phone_number) == 10 and phone_number.isdigit() else False
|
64 |
+
|
65 |
+
def validate_name(self, name):
|
66 |
+
return True if len(name.split()) >= 2 else False
|