-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
239 lines (211 loc) · 11 KB
/
Copy pathmain.py
File metadata and controls
239 lines (211 loc) · 11 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
from google import genai
import os
from dotenv import load_dotenv
import pymysql
from time import sleep
#======================================================================================
# AGENTS
from agent.account import *
from agent.convo import *
from agent.fulfillment import *
from agent.inv import *
from agent.loyalty import *
from agent.payment import *
from agent.recommend import *
from agent.support import *
#======================================================================================
# FEATURES
from features.email_custom import *
from features.email_order import *
from features.email_pay import *
#======================================================================================
#Setup of AI
load_dotenv()
client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"))
with open("base_prompt.txt", "r", encoding="utf-8") as f:
base_prompt = f.read()
#======================================================================================
# DATABASE SETUP
DB_NAME=os.getenv("DB_NAME")
DB_HOST=os.getenv("DB_HOST")
DB_PASS=os.getenv("DB_PASS")
DB_PORT=os.getenv("DB_PORT")
DB_USER=os.getenv("DB_USER")
# timeout = 10
# connection = pymysql.connect(
# charset="utf8mb4",
# connect_timeout=timeout,
# cursorclass=pymysql.cursors.DictCursor,
# db=DB_NAME,
# host=DB_HOST,
# password=DB_PASS,
# read_timeout=timeout,
# port=DB_PORT,
# user=DB_USER,
# write_timeout=timeout,
# )
# try:
# cursor = connection.cursor()
# cursor.execute("CREATE TABLE mytest (id INTEGER PRIMARY KEY)")
# cursor.execute("INSERT INTO mytest (id) VALUES (1), (2)")
# cursor.execute("SELECT * FROM mytest")
# print(cursor.fetchall())
# finally:
# connection.close()
#======================================================================================
def createResponse(prompt):
conversation_text = ""
# print(prompt)
for msg in prompt:
conversation_text += f"{msg['role']}: {msg['content']}\n"
# print(conversation_text)
response = client.models.generate_content(
model="gemini-2.5-flash",
contents=conversation_text
)
return response
if __name__=="__main__":
conversation = [{"role": "Instructions", "content": str([base_prompt])}]
print("Hello I am a Sales Agent for TearHackx,Let's start todays potential pucharse process. I am here for your help!!\n Please provide me your mobile number to begin with so that I can fetch your data from our database. ")
x=1
while True:
n=input("".center(120,'-')+"\nPlease, Enter your Input-> ")
print("".center(120,'-'))
if n=="-1":
print("\n👋 Goodbye!\n")
break
conversation.append({"role": "user", "content": str([n])})
res = createResponse(conversation)
response=res.text
conversation.append({"role": "model", "content": str([response])})
for i in response.splitlines():
(func, _, args)=i.partition(':')
if func.strip()=="createAccount":
(name, age, email, address, mobno)=args.split(';')
createAccount(name, age, email, address, mobno)
if func.strip()=="accountExistsOrNot":
(mobno)=args.split(';')
data=accountExistsOrNot(mobno[0].strip())
conversation.append({"role": "Latest Output from the accountExistsOrNot Function", "content": data})
if data=="Account does exist now lets move to the next step":
data=fetchCustomerInfo(mobno[0].strip())
conversation.append({"role": "Latest Output from the fetchCustomerInfo Function", "content": "The data is Structured as [C_Name,C_Age,C_Mobno,C_Email,C_Address,Cart]"+str(data)})
if func.strip()=="fetchOffers":
data=fetchOffers()
conversation.append({"role": "Latest Output from the fetchOffers Function", "content": "The data is Structured as [O_ID,O_Items,O_Date,Status,CompletionDate]"+str(data)})
# if func.strip()=="fetchHistory":
# (customerID)=args.split(';')
# data=fetchHistory(customerID)
conversation.append({"role": "Latest Output from the fetchHistory Function", "content": "The data is Structured as [Heading,Content]"+str(data)})
if func.strip()=="saveHistory":
(customerID, heading, content)=args.split(';')
saveHistory(customerID, heading, content)
if func.strip()=="fetchItems":
data=fetchItems()
conversation.append({"role": "Latest Output from the fetchItems Function", "content": "The data is Structured as [P_ID,P_Name,P_Sizes,P_Price]"+str(data)})
if func.strip()=="fetchCustomerInfo":
(customerID)=args.split(';')
data=fetchCustomerInfo(customerID)
conversation.append({"role": "Latest Output from the fetchCustomerInfo Function", "content": "The data is Structured as [C_Name,C_Age,C_Mobno,C_Email,C_Address,Cart]"+str(data)})
if func.strip()=="contactOwner":
(message)=args.split(';')
contactOwner(message)
if func.strip()=="addToCart":
if len(args.split(';'))!=3:
(customerID, productID, Quantity)=('','','')
else:
(customerID, productID, Quantity)=args.split(';')
addToCart(customerID, productID, Quantity)
if func.strip()=="placeOrder":
(customerID)=args.split(';')
placeOrder(customerID)
if func.strip()=="fetchOrders":
(customerID)=args.split(';')
data=fetchOrders(customerID)
conversation.append({"role": "Latest Output from the fetchOrders Function", "content": "The data is Structured as [O_ID,O_Items,O_Date,Status,CompletionDate]"+str(data)})
if func.strip()=="speak":
(response)=args.split(';')
speak(response)
if func.strip()=="create_payment_link":
(amount_rupees, customer_name, customer_email, customer_contact, description)=args.split(';')
create_payment_link(amount_rupees, customer_name, customer_email, customer_contact, description)
if func.strip()=="sendEmail":
(rEmail, custom_header, custom_message)=args.split(';')
sendEmail(rEmail, custom_header, custom_message)
if func.strip()=="orderConfirmationEmail":
(rEmail)=args.split(';')
orderConfirmationEmail(rEmail)
if func.strip()=="endConversation":
speak("Bye Bye!!!!")
break
res = createResponse(conversation)
response=res.text
conversation.append({"role": "model", "content": response})
for i in response.splitlines():
(func, _, args)=i.partition(':')
if func.strip()=="createAccount":
(name, age, email, address, mobno)=args.split(';')
createAccount(name, age, email, address, mobno)
if func.strip()=="accountExistsOrNot":
(mobno)=args.split(';')
data=accountExistsOrNot(mobno[0].strip())
conversation.append({"role": "Latest Output from the accountExistsOrNot Function", "content": data})
if data=="Account does exist now lets move to the next step":
data=fetchCustomerInfo(mobno[0].strip())
conversation.append({"role": "Latest Output from the fetchCustomerInfo Function", "content": "The data is Structured as [C_Name,C_Age,C_Mobno,C_Email,C_Address,Cart]"+str(data)})
if func.strip()=="fetchOffers":
data=fetchOffers()
conversation.append({"role": "Latest Output from the fetchOffers Function", "content": "The data is Structured as [O_ID,O_Items,O_Date,Status,CompletionDate]"+str(data)})
# if func.strip()=="fetchHistory":
# (customerID)=args.split(';')
# data=fetchHistory(customerID)
conversation.append({"role": "Latest Output from the fetchHistory Function", "content": "The data is Structured as [Heading,Content]"+str(data)})
if func.strip()=="saveHistory":
(customerID, heading, content)=args.split(';')
saveHistory(customerID, heading, content)
if func.strip()=="fetchItems":
data=fetchItems()
conversation.append({"role": "Latest Output from the fetchItems Function", "content": "The data is Structured as [P_ID,P_Name,P_Sizes,P_Price]"+str(data)})
if func.strip()=="fetchCustomerInfo":
(customerID)=args.split(';')
data=fetchCustomerInfo(customerID)
conversation.append({"role": "Latest Output from the fetchCustomerInfo Function", "content": "The data is Structured as [C_Name,C_Age,C_Mobno,C_Email,C_Address,Cart]"+str(data)})
if func.strip()=="contactOwner":
(message)=args.split(';')
contactOwner(message)
if func.strip()=="addToCart":
if len(args.split(';'))!=3:
(customerID, productID, Quantity)=('','','')
else:
(customerID, productID, Quantity)=args.split(';')
addToCart(customerID, productID, Quantity)
if func.strip()=="placeOrder":
(customerID)=args.split(';')
placeOrder(customerID)
if func.strip()=="fetchOrders":
(customerID)=args.split(';')
data=fetchOrders(customerID)
conversation.append({"role": "Latest Output from the fetchOrders Function", "content": "The data is Structured as [O_ID,O_Items,O_Date,Status,CompletionDate]"+str(data)})
if func.strip()=="speak":
(response)=args.split(';')
speak(response)
if func.strip()=="create_payment_link":
(amount_rupees, customer_name, customer_email, customer_contact, description)=args.split(';')
create_payment_link(amount_rupees, customer_name, customer_email, customer_contact, description)
if func.strip()=="sendEmail":
(rEmail, custom_header, custom_message)=args.split(';')
sendEmail(rEmail, custom_header, custom_message)
if func.strip()=="orderConfirmationEmail":
(rEmail)=args.split(';')
orderConfirmationEmail(rEmail)
if func.strip()=="endConversation":
speak("Bye Bye!!!!")
break
print("\nOutput Done......")
# sleep(3)
# print("".center(200,"="))
# print("AI THINKING".center(200))
# print(conversation[x:len(conversation)])
# x=len(conversation)
# print("".center(200,"="))
# print("".center(120,'-'))