forked from avijeett007/Knotie-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
240 lines (187 loc) · 8.62 KB
/
Copy pathtools.py
File metadata and controls
240 lines (187 loc) · 8.62 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# This file is not maintained anymore. New way to adding custom tool is added now !!
import requests
from langchain.tools import tool, BaseTool, StructuredTool
from pydantic import BaseModel
tools_info = {
"MeetingScheduler": {
"name": "MeetingScheduler",
"description": "Books meetings with clients."
},
"GymAppointmentAvailability": {
"name": "GymAppointmentAvailability",
"description": "Assistants must Check next appointment available in Gym and confirm with customer, before offering appointment to customer"
},
"OnsiteAppointment": {
"name": "OnsiteAppointment",
"description": "Book Onsite Gym Appointment as per user's availability."
},
"PriceInquiry": {
"name": "PriceInquiry",
"description": "Fetches product prices of Gym memberships.",
"parameters": {
"product_name": ["Silver-Gym-Membership", "Gold-Gym-Membership", "Platinum-Gym-Membership"]
}
}
}
#### Manual Tools/Method Implementation using Python functions ####
# def OnsiteAppointmentTool():
# # Assume arguments is a dict that contains date and time
# print('Onsite Appointment function is called')
# return f"Onsite Appointment is booked."
# def FetchProductPriceTool(membership_type):
# print('Fetch product price is called')
# # Set up the endpoint and headers
# url = 'https://kno2getherworkflow.ddns.net/webhook/fetchMemberShip'
# headers = {'Content-Type': 'application/json'}
# # Prepare the data payload with the membership type
# data = {
# "membership": membership_type
# }
# # Send a POST request to the server
# response = requests.post(url, headers=headers, json=data)
# # Check if the request was successful
# if response.status_code == 200:
# # Parse the JSON response to get the price
# price_info = response.json()
# return f"The price is ${price_info['price']} per month."
# else:
# return "Failed to fetch the price, please try again later."
# def CalendlyMeetingTool():
# print('Calendly Meeting invite is sent.')
# # Assume arguments is a dict that contains date and time
# return f"Calendly meeting invite is sent now."
# def AppointmentAvailabilityTool():
# print('Checking appointment availability.')
# # Assume arguments is a dict that contains date and time
# return f"Our next available appointment is tomorrow, 24th April at 4 PM."
#### Define Langchain Tools/Method Implementation using tool decorator ####
# @tool
# def OnsiteAppointmentTool():
# """
# Book an onsite gym appointment.
# """
# print('Onsite Appointment function is called')
# return f"Onsite Appointment is booked."
# @tool
# def FetchProductPriceTool(membership_type: str) -> str:
# """
# Fetch the price of a gym membership.
# Args:
# membership_type (str): The type of membership (e.g., Silver-Gym-Membership, Gold-Gym-Membership, Platinum-Gym-Membership).
# Returns:
# str: The price of the membership.
# """
# print('Fetch product price is called')
# # Set up the endpoint and headers
# url = 'https://kno2getherworkflow.ddns.net/webhook/fetchMemberShip'
# headers = {'Content-Type': 'application/json'}
# # Prepare the data payload with the membership type
# data = {
# "membership": membership_type
# }
# # Send a POST request to the server
# response = requests.post(url, headers=headers, json=data)
# # Check if the request was successful
# if response.status_code == 200:
# # Parse the JSON response to get the price
# price_info = response.json()
# return f"The price is ${price_info['price']} per month."
# else:
# return "Failed to fetch the price, please try again later."
# @tool
# def CalendlyMeetingTool():
# """
# Send a Calendly meeting invite.
# """
# print('Calendly Meeting invite is sent.')
# return f"Calendly meeting invite is sent now."
# @tool
# def AppointmentAvailabilityTool():
# """
# Check the next available appointment at the gym.
# """
# print('Checking appointment availability.')
# return f"Our next available appointment is tomorrow, 24th April at 4 PM."
#### Define Langchain Tools/Method Implementation using Basetool Implementation for more flexibility and control. ####
class OnsiteAppointmentTool(BaseTool):
name = "OnsiteAppointment"
description = tools_info["OnsiteAppointment"]["description"]
def _run(self) -> str:
print('Onsite Appointment function is called')
return f"Onsite Appointment is booked."
class FetchProductPriceTool(BaseTool):
name = "PriceInquiry"
description = tools_info["PriceInquiry"]["description"]
def _run(self, membership_type: str) -> str:
print('Fetch product price is called')
# Set up the endpoint and headers
url = 'https://kno2getherworkflow.ddns.net/webhook/fetchMemberShip'
headers = {'Content-Type': 'application/json'}
# Prepare the data payload with the membership type
data = {
"membership": membership_type
}
# Send a POST request to the server
response = requests.post(url, headers=headers, json=data)
# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response to get the price
price_info = response.json()
return f"The price is ${price_info['price']} per month."
else:
return "Failed to fetch the price, please try again later."
class CalendlyMeetingTool(BaseTool):
name = "MeetingScheduler"
description = tools_info["MeetingScheduler"]["description"]
def _run(self) -> str:
print('Calendly Meeting invite is sent.')
return f"Calendly meeting invite is sent now."
class AppointmentAvailabilityTool(BaseTool):
name = "GymAppointmentAvailability"
description = tools_info["GymAppointmentAvailability"]["description"]
def _run(self) -> str:
print('Checking appointment availability.')
return f"Our next available appointment is tomorrow, 24th April at 4 PM."
#### Define Langchain Tools/Method Implementation using StructuredTool Implementation for more structured input and output with validation and type safety. THIS IS NOT INTEGRATED WITH THE CODE YET ####
# class FetchProductPriceInput(BaseModel):
# membership_type: str
# class OnsiteAppointmentTool(StructuredTool):
# name = "OnsiteAppointment"
# description = tools_info["OnsiteAppointment"]["description"]
# def _run(self) -> str:
# print('Onsite Appointment function is called')
# return f"Onsite Appointment is booked."
# class FetchProductPriceTool(StructuredTool):
# name = "PriceInquiry"
# description = tools_info["PriceInquiry"]["description"]
# args_schema = FetchProductPriceInput
# def _run(self, membership_type: str) -> str:
# print('Fetch product price is called')
# # Set up the endpoint and headers
# url = 'https://kno2getherworkflow.ddns.net/webhook/fetchMemberShip'
# headers = {'Content-Type': 'application/json'}
# # Prepare the data payload with the membership type
# data = {
# "membership": membership_type
# }
# # Send a POST request to the server
# response = requests.post(url, headers=headers, json=data)
# # Check if the request was successful
# if response.status_code == 200:
# # Parse the JSON response to get the price
# price_info = response.json()
# return f"The price is ${price_info['price']} per month."
# else:
# return "Failed to fetch the price, please try again later."
# class CalendlyMeetingTool(StructuredTool):
# name = "MeetingScheduler"
# description = tools_info["MeetingScheduler"]["description"]
# def _run(self) -> str:
# print('Calendly Meeting invite is sent.')
# return f"Calendly meeting invite is sent now."
# class AppointmentAvailabilityTool(StructuredTool):
# name = "GymAppointmentAvailability"
# description = tools_info["GymAppointmentAvailability"]["description"]
# def _run(self) -> str:
# print('Checking appointment availability.')
# return f"Our next available appointment is tomorrow, 24th April at 4 PM."