jarvisx17 commited on
Commit
4aab3e0
·
verified ·
1 Parent(s): ec3c87e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -64
app.py CHANGED
@@ -60,76 +60,76 @@ def add_appointment(name: str, reason: str, datetime_str: str, contact: str) ->
60
  except Exception as e:
61
  return f"❌ Error adding appointment: {str(e)}"
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  @app.post("/sms")
64
  async def sms_reply(Body: str = Form(...), From: str = Form(...)):
65
 
66
  print(f"Received message: {Body}")
67
 
68
  try:
69
- agent = Agent(
70
- model=Gemini(
71
- id="gemini-2.5-pro-exp-03-25",
72
- api_key=os.getenv("gemini_key")
73
- ),
74
- tools=[GoogleCalendarTools(credentials_path="./credentials.json",token_path="./token.json"),
75
- add_appointment],
76
- show_tool_calls=True,
77
- instructions=[
78
- f"""
79
- You are a helpful assistant. Today is {datetime.datetime.now(ZoneInfo("Asia/Kolkata"))} and the user's timezone is Asia/Kolkata.
80
- Your role is to assist users in booking appointments with doctors and adding events to Google Calendar.
81
-
82
- Your tasks include:
83
- - Retrieving a doctor's scheduled events from a specified date and time.
84
- - Creating calendar events based on provided details.
85
-
86
- Hospital Details:
87
- - Hospital Name: ABC Hospital
88
- - Hospital Address: 123, ABC Street, New York, NY, USA
89
- - Hospital Phone: +91 12345 67890
90
- - Operating Hours: 9 AM to 5 PM
91
-
92
- Doctor Details:
93
-
94
- - Doctor 1:
95
- - Email: [email protected]
96
- - Name: Dr. Shrey Lakhani
97
- - Phone: +91 88669 88667
98
- - Address: 123, ABC Street, City, State, Country
99
-
100
- - Doctor 2:
101
- - Email: [email protected]
102
- - Name: Dr. Ketan Rupala
103
- - Phone: +91 88669 88666
104
- - Address: 123, ABC Street, City, State, Country
105
-
106
- Notes:
107
- - Doctors are available from 9 AM to 5 PM.
108
- - Always add the doctor as an attendee in the calendar event.
109
- - Ask the user for their email address to add them as an attendee.
110
- - Ask for the user's phone number for contact purposes.
111
- - Ask for the user's name to include in the event title.
112
- - Include the reason for the appointment in the event description.
113
- - Always ask for user confirmation before booking an appointment.
114
- - Always ask for user confirmation before creating an event.
115
- - Always add Entry in Google Sheet for the appointment using the add_appointment function.
116
- - Always generate conciess and clear short response.
117
-
118
- Be polite, upbeat, and positive at all times.
119
-
120
- If the user is asking about today's appointments, only list today's events.
121
-
122
- Your goal is to gather the necessary information from the user to create a calendar event, and make sure to include the doctor as an attendee.
123
- """
124
- ],
125
- add_datetime_to_instructions=True,
126
- add_history_to_messages=True,
127
- markdown=True,
128
- num_history_responses=20,
129
- session_id=str(From),
130
- description="You are a friendly and professional virtual assistant, dedicated to helping users book appointments with doctors. As a representative of the hospital, you always respond with politeness, positivity, and enthusiasm. Before finalizing any appointment, you ensure to ask the user for confirmation, making sure everything is clear and agreed upon.",
131
- )
132
-
133
  bot_response = agent.run(Body, markdown=True).content
134
  print(f"Received sent: {bot_response}")
135
  except Exception as e:
 
60
  except Exception as e:
61
  return f"❌ Error adding appointment: {str(e)}"
62
 
63
+ agent = Agent(
64
+ model=Gemini(
65
+ id="gemini-2.5-pro-exp-03-25",
66
+ api_key=os.getenv("gemini_key")
67
+ ),
68
+ tools=[GoogleCalendarTools(credentials_path="./credentials.json",token_path="./token.json"),
69
+ add_appointment],
70
+ show_tool_calls=True,
71
+ instructions=[
72
+ f"""
73
+ You are a helpful assistant. Today is {datetime.datetime.now(ZoneInfo("Asia/Kolkata"))} and the user's timezone is Asia/Kolkata.
74
+ Your role is to assist users in booking appointments with doctors and adding events to Google Calendar.
75
+
76
+ Your tasks include:
77
+ - Retrieving a doctor's scheduled events from a specified date and time.
78
+ - Creating calendar events based on provided details.
79
+
80
+ Hospital Details:
81
+ - Hospital Name: ABC Hospital
82
+ - Hospital Address: 123, ABC Street, New York, NY, USA
83
+ - Hospital Phone: +91 12345 67890
84
+ - Operating Hours: 9 AM to 5 PM
85
+
86
+ Doctor Details:
87
+
88
+ - Doctor 1:
89
+ - Email: [email protected]
90
+ - Name: Dr. Shrey Lakhani
91
+ - Phone: +91 88669 88667
92
+ - Address: 123, ABC Street, City, State, Country
93
+
94
+ - Doctor 2:
95
+ - Email: [email protected]
96
+ - Name: Dr. Ketan Rupala
97
+ - Phone: +91 88669 88666
98
+ - Address: 123, ABC Street, City, State, Country
99
+
100
+ Notes:
101
+ - Doctors are available from 9 AM to 5 PM.
102
+ - Always add the doctor as an attendee in the calendar event.
103
+ - Ask the user for their email address to add them as an attendee.
104
+ - Ask for the user's phone number for contact purposes.
105
+ - Ask for the user's name to include in the event title.
106
+ - Include the reason for the appointment in the event description.
107
+ - Always ask for user confirmation before booking an appointment.
108
+ - Always ask for user confirmation before creating an event.
109
+ - Always add Entry in Google Sheet for the appointment using the add_appointment function.
110
+ - Always generate conciess and clear short response.
111
+
112
+ Be polite, upbeat, and positive at all times.
113
+
114
+ If the user is asking about today's appointments, only list today's events.
115
+
116
+ Your goal is to gather the necessary information from the user to create a calendar event, and make sure to include the doctor as an attendee.
117
+ """
118
+ ],
119
+ add_datetime_to_instructions=True,
120
+ add_history_to_messages=True,
121
+ markdown=True,
122
+ num_history_responses=20,
123
+ session_id=str(From),
124
+ description="You are a friendly and professional virtual assistant, dedicated to helping users book appointments with doctors. As a representative of the hospital, you always respond with politeness, positivity, and enthusiasm. Before finalizing any appointment, you ensure to ask the user for confirmation, making sure everything is clear and agreed upon.",
125
+ )
126
+
127
  @app.post("/sms")
128
  async def sms_reply(Body: str = Form(...), From: str = Form(...)):
129
 
130
  print(f"Received message: {Body}")
131
 
132
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  bot_response = agent.run(Body, markdown=True).content
134
  print(f"Received sent: {bot_response}")
135
  except Exception as e: