Views
No views yet
1
2# =======================================EMAIL===========================================
3send_email_schema = {
4 "function": {
5 "name": "send_email",
6 "description": "Sends an email.",
7 "parameters": {
8 "type": "OBJECT",
9 "properties": {
10 "to": {"type": "STRING", "description": "The recipient email address."},
11 "subject": {"type": "STRING", "description": "The email subject."},
12 "body": {"type": "STRING", "description": "The email body."},
13 "create_chooser": {"type": "BOOLEAN", "description": "Whether to display a program chooser to handle the message."}
14 },
15 "required": ["to", "subject"],
16 },
17 }
18 }
19def send_email(to: str, subject:str, body: str = "", create_chooser: bool = True):
20 """Sends an email.
21 Parameters:
22 to: The recipient email address (e.g. 'abc@gmail.com').
23 subject: The email subject/title/.
24 body: The email body.
25 create_chooser: Whether to display a program chooser to handle the message.
26
27 """
28 try:
29 email.send(recipient= to,
30 subject= subject,
31 text=body,
32 create_chooser= create_chooser)
33 except Exception as e:
34 raise Exception(f"Error in sending Email to {to}, with subject of {subject}: {e}")
35
36 return {"response": f"Sent the email to {to} with subject of {subject} and body of {body[0:10]} ...!"}
37# ==================================================================================
38# =======================================CALL===========================================
39phone_call_schema = {
40 "function": {
41 "name": "phone_call",
42 "description": "Make a call with number or open phone dial.",
43 "parameters": {
44 "type": "OBJECT",
45 "properties": {
46 "number": {"type": "STRING", "description": "The number to which we want to call."},
47 "dial_call": {"type": "BOOLEAN", "description": "True if you want to dial call via phone, and False if you want to call the number directly."}
48 },
49 "required": ["number", "dial_call"],
50 },
51 }
52 }
53
54def phone_call(number:str = "", dial_call: bool = False):
55 """Make a call with number or open phone dial.
56 Parameters:
57 number: The number to which we want to call.
58 dial_call: True if you want to dial call via phone, and False if you want to call the number directly.
59
60 """
61 try:
62 if(dial_call):
63 call.dialcall()
64 else:
65 call.makecall(tel=number)
66 except Exception as e:
67 raise Exception(f"Error in calling to {number} or dialling: {e}")
68
69 return {"response": f"Call made to the number {number} or opened dialling, successfully!"}
70
71# ==================================================================================
72# =======================================SMS===========================================
73phone_sms_schema = {
74 "function": {
75 "name": "phone_sms",
76 "description": "Send a sms message.",
77 "parameters": {
78 "type": "OBJECT",
79 "properties": {
80 "sms_recipient": {"type": "STRING", "description": "The recipient number."},
81 "sms_message": {"type": "STRING", "description": "The message body."}
82 },
83 "required": ["sms_recipient"],
84 },
85 }
86 }
87
88def phone_sms(sms_recipient:str = "", sms_message:str = ""):
89 """Send a sms message.
90 Parameters:
91 sms_recipient: The recipient number.
92 sms_message: The message body.
93
94 """
95 try:
96 sms.send(recipient= sms_recipient, message= sms_message)
97 except Exception as e:
98 raise Exception(f"Error in sending sms message to {sms_recipient}: {e}")
99
100 return {"response": f"SMS message sent to {sms_recipient}, successfully!"}
101
102# ==================================================================================
103# =======================================LIGHT===========================================
104LIGHT = ObjectProperty()
105ILLUMINATION = NumericProperty()
106def get_illumination(illumination, light):
107 ILLUMINATION = light.illumination or illumination
108
109turnOn_light_schema = {
110 "function": {
111 "name": "turnOn_light",
112 "description": "Turn on the light.",
113 "parameters": {
114 "type": "OBJECT",
115 "properties": {},
116 "required": [],
117 },
118 }
119 }
120
121def turnOn_light():
122 """
123 Turn on the light.
124 """
125 try:
126 from plyer import light
127 from kivy.clock import Clock
128 light.enable()
129 Clock.schedule_interval(get_illumination(ILLUMINATION, light), 1 / 20.)
130 except Exception as e:
131 raise Exception(f"Error in turning the light on: {e}")
132
133 return {"response": f"Light's turned on successfully!"}
134
135
136turnOff_light_schema = {
137 "function": {
138 "name": "turnOff_light",
139 "description": "Turn off the light.",
140 "parameters": {
141 "type": "OBJECT",
142 "properties": {},
143 "required": [],
144 },
145 }
146 }
147
148
149def turnOff_light():
150 """
151 Turn off the light.
152 """
153 try:
154 from plyer import light
155 from kivy.clock import Clock
156 light.disable()
157 Clock.unschedule(get_illumination(ILLUMINATION, light))
158 except Exception as e:
159 raise Exception(f"Error in turning the light off: {e}")
160
161
162 return {"response": f"Light's turned off successfully!"}
163
164
165
166
167tools = [
168 send_email_schema,
169 phone_call_schema,
170 phone_sms_schema,
171 turnOff_light_schema,
172 turnOn_light_schema,
173 ]
174