Upload 4 files
Browse files- app.py +91 -0
- credentials.json +1 -0
- requirements.txt +11 -0
- token.json +1 -0
app.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Form
|
2 |
+
from fastapi.responses import Response
|
3 |
+
from twilio.twiml.messaging_response import MessagingResponse
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
from agno.agent import Agent
|
6 |
+
from agno.models.google import Gemini
|
7 |
+
from agno.tools.googlecalendar import GoogleCalendarTools
|
8 |
+
import datetime
|
9 |
+
from zoneinfo import ZoneInfo
|
10 |
+
|
11 |
+
load_dotenv()
|
12 |
+
|
13 |
+
app = FastAPI()
|
14 |
+
|
15 |
+
TWILIO_ACCOUNT_SID = 'ACc2daaa501806cfafa344eb2c87a35316'
|
16 |
+
TWILIO_AUTH_TOKEN = '9514033d2de1a04cae9e9a9e53efb374'
|
17 |
+
|
18 |
+
agent = Agent(
|
19 |
+
model=Gemini(
|
20 |
+
id="gemini-2.5-pro-exp-03-25",
|
21 |
+
api_key="AIzaSyD3AZHIzS4O7aUy0HFGWclToVznZ8236WM"
|
22 |
+
),
|
23 |
+
tools=[GoogleCalendarTools(credentials_path="./credentials.json",token_path="./token.json")],
|
24 |
+
show_tool_calls=True,
|
25 |
+
instructions=[
|
26 |
+
f"""
|
27 |
+
You are a helpful assistant. Today is {datetime.datetime.now(ZoneInfo("Asia/Kolkata"))} and the user's timezone is Asia/Kolkata.
|
28 |
+
Your role is to assist users in booking appointments with doctors and adding events to Google Calendar.
|
29 |
+
|
30 |
+
Your tasks include:
|
31 |
+
- Retrieving a doctor's scheduled events from a specified date and time.
|
32 |
+
- Creating calendar events based on provided details.
|
33 |
+
|
34 |
+
Hospital Details:
|
35 |
+
- Hospital Name: ABC Hospital
|
36 |
+
- Hospital Address: 123, ABC Street, New York, NY, USA
|
37 |
+
- Hospital Phone: +91 12345 67890
|
38 |
+
- Operating Hours: 9 AM to 5 PM
|
39 |
+
|
40 |
+
Doctor Details:
|
41 |
+
|
42 |
+
- Doctor 1:
|
43 |
+
- Email: [email protected]
|
44 |
+
- Name: Dr. Shrey Lakhani
|
45 |
+
- Phone: +91 88669 88667
|
46 |
+
- Address: 123, ABC Street, City, State, Country
|
47 |
+
|
48 |
+
- Doctor 2:
|
49 |
+
- Email: [email protected]
|
50 |
+
- Name: Dr. Jignesh Patel
|
51 |
+
- Phone: +91 88669 88666
|
52 |
+
- Address: 123, ABC Street, City, State, Country
|
53 |
+
|
54 |
+
Notes:
|
55 |
+
- Doctors are available from 9 AM to 5 PM.
|
56 |
+
- Always add the doctor as an attendee in the calendar event.
|
57 |
+
- Ask the user for their email address to add them as an attendee.
|
58 |
+
- Ask for the user's phone number for contact purposes.
|
59 |
+
- Ask for the user's name to include in the event title.
|
60 |
+
- Include the reason for the appointment in the event description.
|
61 |
+
- Always ask for user confirmation before booking an appointment.
|
62 |
+
- Always ask for user confirmation before creating an event.
|
63 |
+
|
64 |
+
Be polite, upbeat, and positive at all times.
|
65 |
+
|
66 |
+
If the user is asking about today's appointments, only list today's events.
|
67 |
+
|
68 |
+
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.
|
69 |
+
"""
|
70 |
+
|
71 |
+
],
|
72 |
+
add_datetime_to_instructions=True,
|
73 |
+
add_history_to_messages=True,
|
74 |
+
markdown=True,
|
75 |
+
num_history_responses=20,
|
76 |
+
session_id="123",
|
77 |
+
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.",
|
78 |
+
)
|
79 |
+
|
80 |
+
@app.post("/sms")
|
81 |
+
async def sms_reply(Body: str = Form(...), From: str = Form(...)):
|
82 |
+
print(f"Received message from {From}: {Body}")
|
83 |
+
|
84 |
+
try:
|
85 |
+
bot_response = agent.run(Body, markdown=True).content
|
86 |
+
except Exception as e:
|
87 |
+
bot_response = f"Oops! Something went wrong: {str(e)}"
|
88 |
+
|
89 |
+
twilio_response = MessagingResponse()
|
90 |
+
twilio_response.message(bot_response)
|
91 |
+
return Response(content=str(twilio_response), media_type="application/xml")
|
credentials.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"installed":{"client_id":"1010626285276-ib3vb9tn7i11eevk2ci24sspn7iefteb.apps.googleusercontent.com","project_id":"hybrid-subject-456511-t8","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"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","redirect_uris":["http://localhost"]}}
|
requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
google-api-core==2.19.1
|
2 |
+
google-api-python-client==2.140.0
|
3 |
+
google-auth==2.33.0
|
4 |
+
google-auth-httplib2==0.2.0
|
5 |
+
google-auth-oauthlib==1.2.1
|
6 |
+
googleapis-common-protos==1.63.2
|
7 |
+
fastapi==0.95.2
|
8 |
+
uvicorn==0.22.0
|
9 |
+
agno
|
10 |
+
twilio
|
11 |
+
python-dotenv
|
token.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"token": "ya29.a0AZYkNZiXGgNEpao9qeh38fylxmlqRV6abI_4uQQV38WSVHltt_VSurH8alOS0u8bHM6NBi8AHczxMzUPE7z8SCE0xc0DjUTyxiMdz6luKfZ9W17EMPEVX13GNzdl8Y8gI7zL_73btgD1BFmgJCr-bJP0yId0bKYsCrvOj6bYDQaCgYKATsSARcSFQHGX2MinFOcXy-gZGaVvu-ocmw1OA0177", "refresh_token": "1//0gNHsVhtGQQjMCgYIARAAGBASNgF-L9Ir3eSwGdoQs5I1m3vT8HCkDFOK3FVv8XLE-0lUMF5LbuAHTY_lDSyg5j_DNsbKiV5qUQ", "token_uri": "https://oauth2.googleapis.com/token", "client_id": "1010626285276-ib3vb9tn7i11eevk2ci24sspn7iefteb.apps.googleusercontent.com", "client_secret": "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", "scopes": ["https://www.googleapis.com/auth/calendar"], "universe_domain": "googleapis.com", "account": "", "expiry": "2025-04-12T11:11:06.868517Z"}
|