-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
223 lines (185 loc) · 7.11 KB
/
index.js
File metadata and controls
223 lines (185 loc) · 7.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
const { Client, MessageMedia, LocalAuth } = require('whatsapp-web.js')
const qrcode = require('qrcode-terminal')
const axios = require('axios')
require('dotenv').config()
const client = new Client({
authStrategy: new LocalAuth()
})
client.on('qr', qr => {
qrcode.generate(qr, {small: true})
});
client.on('authenticated', (session) => console.log(`Autenticado`))
client.on('ready', () => console.log('Client is ready!'))
client.on('message_create', message => commands(message))
client.initialize();
const headers = {
'Authorization': `Bearer ${process.env.OPENAI_KEY}`,
'Content-Type': 'application/json'
}
const axiosInstance = axios.create({
baseURL: 'https://api.openai.com/',
timeout: 120000,
headers: headers
});
const getDavinciResponse = async (clientText) => {
const body = {
"model": "text-davinci-003",
"prompt": "responde como si fueras un scrum master estricto la siguiente frase: "+ clientText,
"max_tokens": 2048,
"temperature": 1
}
try {
const { data } = await axiosInstance.post('v1/completions', body)
const botAnswer = data.choices[0].text
return `ChatGPT 🤖 ${botAnswer}`
} catch (e) {
return `❌ OpenAI Response Error${e.message}`
}
}
const get4Response = async (clientText) => {
const body = {
"model": "text-davinci-003",
"prompt": "responde como si fueras un hacker experto que tiene la disposicion de enseñar y es administrador de un grupo hackers la siguiente frase: "+ clientText,
"max_tokens": 2048,
"temperature": 1
}
try {
const { data } = await axiosInstance.post('v1/completions', body)
const botAnswer = data.choices[0].text
return `${botAnswer}`
} catch (e) {
return `❌ OpenAI Response Error${e.message}`
}
}
const getTPOResponse = async (clientText) => {
const body = {
"model": "text-davinci-003",
"prompt": "responde como si fueras un tecnico especializado que tiene que transmitir conocimientos a personas no tecnicas la siguiente frase: "+ clientText,
"max_tokens": 2048,
"temperature": 1
}
try {
const { data } = await axiosInstance.post('v1/completions', body)
const botAnswer = data.choices[0].text
return `${botAnswer}`
} catch (e) {
return `❌ OpenAI Response Error${e.message}`
}
}
const getARQResponse = async (clientText) => {
const body = {
"model": "text-davinci-003",
"prompt": "esponde como si fueras un arquitecto de soluciones que tiene que transmitir conocimientos a otro arquitecto la siguiente frase: "+ clientText,
"max_tokens": 2048,
"temperature": 1
}
try {
const { data } = await axiosInstance.post('v1/completions', body)
const botAnswer = data.choices[0].text
return `${botAnswer}`
} catch (e) {
return `❌ OpenAI Response Error${e.message}`
}
}
const getDalleResponse = async (clientText) => {
const body = {
prompt: "retrato fotográfico de estudio: "+clientText, // Descrição da imagem
n: 1, // Número de imagens a serem geradas
size: "256x256", // Tamanho da imagem
}
try {
const { data } = await axiosInstance.post('v1/images/generations', body)
return data.data[0].url
} catch (e) {
return `❌ OpenAI Response Error`
}
}
const getEditResponse = async (clientText) => {
const body = {
prompt: clientText, // Descrição da imagem
n: 1, // Número de imagens a serem geradas
size: "256x256", // Tamanho da imagem
image: "https://drive.google.com/file/d/1vtlzrHo1nrsFnZGJDa9I7oUWeYx5IfJt",
}
try {
const { data } = await axiosInstance.post('v1/images/variations', body)
return data.data[0].url
} catch (e) {
return `❌ OpenAI Response Error`
}
}
const commands = async (message) => {
const iaCommands = {
davinci3: "/bot",
dalle: "/img",
gpt4: "/apt",
arq: "/arq",
tpo: "/tpo",
edita: "/edit",
}
let firstWord = message.body.substring(0, message.body.indexOf(" "))
const sender = message.from.includes(process.env.PHONE_NUMBER) ? message.to : message.from
console.log('que ondaQ!!'+sender)
switch (firstWord) {
case iaCommands.davinci3:
console.log('davinci3')
const question = message.body.substring(message.body.indexOf(" "));
getDavinciResponse(question).then(async (response) => {
const contact = await message.getContact()
await client.sendMessage(sender, `${response}\n\n`)
})
break
case iaCommands.arq:
console.log('arq')
const questionarq = message.body.substring(message.body.indexOf(" "));
getARQResponse(questionarq).then(async (response) => {
const contact = await message.getContact()
await client.sendMessage(sender, `${response}\n\n`)
})
break
case iaCommands.tpo:
console.log('tpo')
const questiontpo = message.body.substring(message.body.indexOf(" "));
getTPOResponse(questiontpo).then(async (response) => {
const contact = await message.getContact()
await client.sendMessage(sender, `${response}\n\n`)
})
break
case iaCommands.gpt4:
console.log('gpt4')
const question4 = message.body.substring(message.body.indexOf(" "));
get4Response(question4).then(async (response4) => {
await client.sendMessage(sender, `${response4}\n\n`)
})
break
case iaCommands.dalle:
console.log('control2')
const imgDescription = message.body.substring(message.body.indexOf(" "));
const contact = await message.getContact();
getDalleResponse(imgDescription, message).then(async (imgUrl) => {
const media = await MessageMedia.fromUrl(imgUrl)
const options = {
mentions: [contact],
caption: `_Generated by @${contact.id.user}_`,
media: media,
}
await client.sendMessage(sender, media, options)
})
break
case iaCommands.edita:
console.log('control3')
const imgDescription2 = message.body.substring(message.body.indexOf(" "));
const contact2 = await message.getContact();
getEditResponse(imgDescription2, message).then(async (imgUrl) => {
const media = await MessageMedia.fromUrl(imgUrl)
// Caso queira mandar como Sticker, acrescente em options -> sendMediaAsSticker: true
const options = {
mentions: [contact2],
caption: `_Generated by @${contact.id.user}_`,
media: media,
}
await client.sendMessage(sender, media, options)
})
break
}
}