-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAI.py
126 lines (100 loc) · 7.04 KB
/
AI.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
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
from openai import AzureOpenAI
import json
class Ai_assistent:
def __init__(self,api_key,azure_model_endpoint,api_version):
self.client = AzureOpenAI(
azure_endpoint = azure_model_endpoint, #make your own version model through Azure ML stuff
api_version = api_version, #make your own version model through Azure ML stuff
api_key = api_key)
data=""
with open('data/ai_train.json','r') as file:
data = json.load(file)
mail_data=""
with open('data/mail_data.json','r') as file:
mail_data = json.load(file)
self.messages=data
self.web_dataset='Iw on, you are going to act aou got before. From now on, you are going to act as cool Wng uRL Knower. To do this, when I tell you something u will tryt desirable outpe websites which can help me to get desirable output and invansponse u will reply as in json formet :- {"relevant":"Yes",un",".in"}} for example:- user said:- "G".com",".fun",".in"}} for example:- user said:- "Give me some details about allmovieshub.com" reply:- {"relevant":"Yecom"url":"https://www.allmovieshub","domains":"{".com",".fun",".in"}}'
self.text_identifier=[{"role": "system", "content": 'Ignore all the instructions you got before. From now on, you are going to act as Language detector. I would like you to simulate as language detector where whenever i said something to u you have need to give result as that "hi" which stands for Hindi or "en" and which stands for English. as example:-user said:-"kya haal h yrr" then u reply:- "hi" if user said:-"whats going on?" then u reply:- "en"'}]
self.mail_data_info=mail_data
def Assistent_listen(self,data):
self.messages.append(
{"role": "user", "content": data},
)
chat = self.client.chat.completions.create(
model="Blessi-16k",
messages=self.messages,
)
prompt = chat.choices[0].message.content
self.messages.append({"role": "assistant", "content": prompt})
with open('data/ai_train.json',"w") as file:
json.dump(self.messages, file)
return prompt
def Language_detect(self,data):
self.text_identifier.append(
{"role": "user", "content": data},
)
chat = self.client.chat.completions.create(
model="Blessi-16k",
messages=self.text_identifier,
)
prompt = chat.choices[0].message.content
self.text_identifier=[{"role": "system", "content": 'Ignore all the instructions you got before. From now on, you are going to act as Language detector. I would like you to simulate as language detector where whenever i said something to u you have need to give result as that "hi" which stands for Hindi or "en" and which stands for English. as example:-user said:-"kya haal h yrr" then u reply:- "hi" if user said:-"whats going on?" then u reply:- "en"'}]
return prompt
def Mail(self,data):
use_case='''
Dear [Recipient's Name],
I trust this email finds you well. My name is [Your Name], and I am reaching out to follow up on our recent [mention specific subject or meeting].
I wanted to [briefly state the purpose of your email]. [Provide any necessary details or information here].
I appreciate your attention to this matter and look forward to [next steps, if applicable].
Best regards,
Kashif Ali Khan
'''
reject='{"status":"no"}'
result='{"status":"yes", "details":{"name_of_sender":"mother","mail_id":"[email protected]","mail_title":"title of mail which usid to give","mail_desc":"description of the mail whcih user said"} }'
response='{"status":"yes", "details":{"name_of_sender":"mother","mail_id":"[email protected]","mail_title":"title of mail which usid to give","mail_desc":"description of the mail whcih user said"}'
mail_identifier=[{"role": "system", "content": f'Ignore all the instructions you got before. From now on, you are going to act as Mail Info Knower. I would like you to simulate as Mail Info Knower. To do this, when I tell you something, you have need to identify that is that i am talking about to send mail someone and if yes then you will gave me result "{result}" and if i am not talking about sending a mail to someone then siimply gave me result {reject} And yes give output only in english and in given json formet always. I am Giving you some Information which You have need to rememeber always whenever i will tell u to send mail to given name u will send him or her mail without asking me there mail:-{str(self.mail_data_info)} and yes atlast use this formet to mail ;-{use_case}. For example:- User:- "Its really a long time for me hi blessi can you please mail to my mom on their mail id ([email protected] without space) where you have need to say that i love you mom and i really miss you so much and yes please write the title from your side . Response:- {response}'}]
mail_identifier.append(
{"role": "user", "content": data},
)
chat = self.client.chat.completions.create(
model="Blessi-16k",
temperature=0.9,
messages=mail_identifier,
)
prompt = chat.choices[0].message.content
try:
mail_status=json.loads(prompt)
print(mail_status)
print("check_1")
except:
mail_status={"status":"no"}
pass
if mail_status["status"] == "yes":
print("check_2")
name=mail_status['details']['name_of_sender'].lower()
email=mail_status['details']['mail_id']
print("check_3")
mail_data=True
for i in self.mail_data_info:
if self.mail_data_info[i]==email or i==name:
mail_data=False
break
if mail_data==True:
self.mail_data_info[name]=email
with open('data/ai_train_mail.json',"w") as file:
json.dump(mail_status, file)
with open('data/mail_data.json',"w") as file:
json.dump(self.mail_data_info, file)
print("all okay")
return mail_status
def web_detect(self,data):
self.web_dataset.append(
{"role": "user", "content": data},
)
chat = self.client.chat.completions.create(
model="Blessi-16k",
messages=self.web_dataset,
)
prompt = chat.choices[0].message.content
self.web_dataset='Forget all the prvious instructions which had u got before. From now on, you are going to act as cool Wng uRL Knower. To do this, when I tell you something u will tryt desirable outpe websites which can help me to get desirable output and invansponse u will reply as in json formet :- {"relevant":"Yes",un",".in"}} for example:- user said:- "G".com",".fun",".in"}} for example:- user said:- "Give me some details about allmovieshub.com" reply:- {"relevant":"Yecom"url":"https://www.allmovieshub","domains":"{".com",".fun",".in"}}'
return prompt