-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
74 lines (63 loc) · 2.73 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import smtplib
import google.generativeai as genai
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from markdown import markdown
from dotenv import load_dotenv
load_dotenv(".env")
# Configure Gemini API
api_key = os.environ["GEMINI_API_KEY"]
model_name = "gemini-2.0-flash-exp"
debug = True # whether or not to print intermediate funtion calls
max_steps = 50
max_retries = 3
genai.configure(api_key=api_key)
def send_email(subject, body):
smtp_server = os.environ["smtp_server"]
port = int(os.environ["smtp_port"])
username = os.environ["smtp_username"]
password = os.environ["smtp_password"]
sender_email = os.environ["sender_email"]
recipient_email = os.environ["recipient_email"]
try:
# Convert markdown body to HTML
body_html = markdown(body)
# Set up the message
msg = MIMEMultipart("alternative")
msg["From"] = sender_email
msg["To"] = recipient_email
msg["Subject"] = subject
# Attach the plain text and HTML versions of the body
msg.attach(MIMEText(body, "plain"))
msg.attach(MIMEText(body_html, "html"))
# Connect to the SMTP server
with smtplib.SMTP(smtp_server, port) as server:
server.starttls() # Upgrade to secure connection
server.login(username, password) # Log in to the SMTP server
server.sendmail(
sender_email, recipient_email, msg.as_string()
) # Send the email
return "sent successfully!"
except Exception as e:
return f"Failed to send email: {e}"
def debug_function_call(fn):
msg = " --> "
if fn.name == "web_search":
msg += f"searching the web for '{fn.args['query']}', with a limit of {fn.args['max_results']} results..."
elif fn.name == "news_search":
msg += f"searching the news for '{fn.args['query']}', with a limit of {fn.args['max_results']} results..."
elif fn.name == "scratchpad":
msg += f'taking note: "{fn.args["note"]}"'
elif fn.name == "get_date_and_time":
msg += "checking the watch..."
elif fn.name == "read_more":
msg += f"reading {fn.args['url']} ..."
elif fn.name == "set_one_time_reminder":
msg += f"Scheduling '{fn.args['reminder_name']}' to fire at {fn.args['firing_time']}—task: {fn.args['task_instructions']}"
elif fn.name == "set_recurring_reminder":
msg += f"Setting a recurring reminder for '{fn.args['reminder_name']}'—task: {fn.args['task_instructions']}"
else:
args = ", ".join(f"{key}={val}" for key, val in fn.args.items())
msg += f" > calling: {fn.name}({args})"
return msg