jarvisx17 commited on
Commit
d24e07b
·
verified ·
1 Parent(s): 2143a90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -61
app.py CHANGED
@@ -13,73 +13,75 @@ load_dotenv()
13
 
14
  app = FastAPI()
15
 
16
- agent = Agent(
17
- model=Gemini(
18
- id="gemini-2.5-pro-exp-03-25",
19
- api_key=os.getenv("gemini_key")
20
- ),
21
- tools=[GoogleCalendarTools(credentials_path="./credentials.json",token_path="./token.json")],
22
- show_tool_calls=True,
23
- instructions=[
24
- f"""
25
- You are a helpful assistant. Today is {datetime.datetime.now(ZoneInfo("Asia/Kolkata"))} and the user's timezone is Asia/Kolkata.
26
- Your role is to assist users in booking appointments with doctors and adding events to Google Calendar.
27
-
28
- Your tasks include:
29
- - Retrieving a doctor's scheduled events from a specified date and time.
30
- - Creating calendar events based on provided details.
31
-
32
- Hospital Details:
33
- - Hospital Name: ABC Hospital
34
- - Hospital Address: 123, ABC Street, New York, NY, USA
35
- - Hospital Phone: +91 12345 67890
36
- - Operating Hours: 9 AM to 5 PM
37
-
38
- Doctor Details:
39
-
40
- - Doctor 1:
41
- - Email: [email protected]
42
- - Name: Dr. Shrey Lakhani
43
- - Phone: +91 88669 88667
44
- - Address: 123, ABC Street, City, State, Country
45
-
46
- - Doctor 2:
47
- - Email: [email protected]
48
- - Name: Dr. Jignesh Patel
49
- - Phone: +91 88669 88666
50
- - Address: 123, ABC Street, City, State, Country
51
-
52
- Notes:
53
- - Doctors are available from 9 AM to 5 PM.
54
- - Always add the doctor as an attendee in the calendar event.
55
- - Ask the user for their email address to add them as an attendee.
56
- - Ask for the user's phone number for contact purposes.
57
- - Ask for the user's name to include in the event title.
58
- - Include the reason for the appointment in the event description.
59
- - Always ask for user confirmation before booking an appointment.
60
- - Always ask for user confirmation before creating an event.
61
-
62
- Be polite, upbeat, and positive at all times.
63
-
64
- If the user is asking about today's appointments, only list today's events.
65
-
66
- 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.
67
- """
68
- ],
69
- add_datetime_to_instructions=True,
70
- add_history_to_messages=True,
71
- markdown=True,
72
- num_history_responses=20,
73
- session_id="123",
74
- 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.",
75
- )
76
-
77
  @app.post("/sms")
78
  async def sms_reply(Body: str = Form(...), From: str = Form(...)):
 
79
  print(f"Received message: {Body}")
80
 
81
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  bot_response = agent.run(Body, markdown=True).content
 
83
  except Exception as e:
84
  bot_response = f"Oops! Something went wrong: {str(e)}"
85
 
 
13
 
14
  app = FastAPI()
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  @app.post("/sms")
17
  async def sms_reply(Body: str = Form(...), From: str = Form(...)):
18
+
19
  print(f"Received message: {Body}")
20
 
21
  try:
22
+ agent = Agent(
23
+ model=Gemini(
24
+ id="gemini-2.5-pro-exp-03-25",
25
+ api_key=os.getenv("gemini_key")
26
+ ),
27
+ tools=[GoogleCalendarTools(credentials_path="./credentials.json",token_path="./token.json")],
28
+ show_tool_calls=True,
29
+ instructions=[
30
+ f"""
31
+ You are a helpful assistant. Today is {datetime.datetime.now(ZoneInfo("Asia/Kolkata"))} and the user's timezone is Asia/Kolkata.
32
+ Your role is to assist users in booking appointments with doctors and adding events to Google Calendar.
33
+
34
+ Your tasks include:
35
+ - Retrieving a doctor's scheduled events from a specified date and time.
36
+ - Creating calendar events based on provided details.
37
+
38
+ Hospital Details:
39
+ - Hospital Name: ABC Hospital
40
+ - Hospital Address: 123, ABC Street, New York, NY, USA
41
+ - Hospital Phone: +91 12345 67890
42
+ - Operating Hours: 9 AM to 5 PM
43
+
44
+ Doctor Details:
45
+
46
+ - Doctor 1:
47
+ - Email: [email protected]
48
+ - Name: Dr. Shrey Lakhani
49
+ - Phone: +91 88669 88667
50
+ - Address: 123, ABC Street, City, State, Country
51
+
52
+ - Doctor 2:
53
+ - Email: [email protected]
54
+ - Name: Dr. Jignesh Patel
55
+ - Phone: +91 88669 88666
56
+ - Address: 123, ABC Street, City, State, Country
57
+
58
+ Notes:
59
+ - Doctors are available from 9 AM to 5 PM.
60
+ - Always add the doctor as an attendee in the calendar event.
61
+ - Ask the user for their email address to add them as an attendee.
62
+ - Ask for the user's phone number for contact purposes.
63
+ - Ask for the user's name to include in the event title.
64
+ - Include the reason for the appointment in the event description.
65
+ - Always ask for user confirmation before booking an appointment.
66
+ - Always ask for user confirmation before creating an event.
67
+
68
+ Be polite, upbeat, and positive at all times.
69
+
70
+ If the user is asking about today's appointments, only list today's events.
71
+
72
+ 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.
73
+ """
74
+ ],
75
+ add_datetime_to_instructions=True,
76
+ add_history_to_messages=True,
77
+ markdown=True,
78
+ num_history_responses=20,
79
+ session_id=str(From),
80
+ 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.",
81
+ )
82
+
83
  bot_response = agent.run(Body, markdown=True).content
84
+ print(f"Received sent: {bot_response}")
85
  except Exception as e:
86
  bot_response = f"Oops! Something went wrong: {str(e)}"
87