forked from leifermendez/bot-promp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatgpt.class.js
44 lines (38 loc) · 984 Bytes
/
chatgpt.class.js
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
require('dotenv').config()
class ChatGPTClass {
queue = [];
optionsGPT = { model: "gpt-3.5-turbo-0301" };
openai = undefined;
constructor() {
this.init().then();
}
/**
* Esta funciona inicializa
*/
init = async () => {
const { ChatGPTAPI } = await import("chatgpt");
this.openai = new ChatGPTAPI(
{
apiKey: process.env.OPENAI_API_KEY
}
);
};
/**
* Manejador de los mensajes
* sun funcion es enviar un mensaje a wahtsapp
* @param {*} ctx
*/
handleMsgChatGPT = async (body) => {
const interaccionChatGPT = await this.openai.sendMessage(body, {
conversationId: !this.queue.length
? undefined
: this.queue[this.queue.length - 1].conversationId,
parentMessageId: !this.queue.length
? undefined
: this.queue[this.queue.length - 1].id,
});
this.queue.push(interaccionChatGPT);
return interaccionChatGPT
};
}
module.exports = ChatGPTClass;