ChatGPT не будет корректно взаимодействовать с использованием Javascript API и WhatsApp-web.js.
Проблема, с которой я столкнулся, заключается в том, что ChatGPT дает странные ответы, когда вы предоставляете ему нормальную информацию. Вы можете скопировать мой код, если хотите попробовать это самостоятельно, инициализировать с помощью узла и установить эти пакеты:
npm i qrcode-terminal
npm i child_process
npm i canvas
npm i whatsapp-web.js
npm i openai
Вы можете начать чат, набрав!chat
и прекратите использовать его!chat stop
Это мой код: (не беспокойтесь о случайных командах)
const qrcode = require('qrcode-terminal');
const { exec } = require('child_process');
const { createCanvas } = require('canvas');
const { Client, LocalAuth, MessageMedia, Buttons, List } = require('whatsapp-web.js');
const { Configuration, OpenAIApi } = require("openai");
require('dotenv').config()
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const client = new Client({
authStrategy: new LocalAuth()
});
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
client.on('ready', () => {
console.log('Client is ready!');
});
smp = false
chatting = false
client.on('message', async message => {
const content = message.body.toLowerCase()
commandCount = 0
if (content.includes("!chat stop")) {
chatting = false
console.log("chat stop")
}
if (chatting) {
console.log("\""+content+"\"")
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: content,
max_tokens:4000
});
console.log(completion)
message.reply(completion.data.choices[0].text);
}
if (!chatting) {
if (content.includes("SMP")) {
if (content.includes("start")) {
commandCount += 1
message.reply('The SMP Server is attempting to start. Please wait a minute or two for the SMP to start. This may not work if player @GoldenD60 is currently playing a game.');
smp = true
exec('start.bat',
(error, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
}
if (content.includes("stop")) {
commandCount += 1
message.reply('The SMP Server is attempting to stop...');
smp = false
exec('stop.bat',
(error, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
}
}
if ((content.includes("give") || content.includes("send")) && content.includes("cat")) {
client.sendMessage(message.from, await MessageMedia.fromUrl("https://cataas.com/cat", {unsafeMime: true}), {caption: 'OK, here is a photo of a cat.'})
}
if ((content.includes("give") || content.includes("send")) && (content.includes("dog") || content.includes("puppy"))) {
dog = await fetch("https://dog.ceo/api/breeds/image/random").then(res => res.json())
client.sendMessage(message.from, await MessageMedia.fromUrl(dog.message, {unsafeMime: true}), {caption: 'OK, here is a photo of a dog/puppy.'})
}
if ((content.includes("give") || content.includes("send")) && content.includes("meme")) {
meme = await fetch("https://meme-api.com/gimme/wholesomememes")
.then(response => response.json())
client.sendMessage(message.from, await MessageMedia.fromUrl(meme.url, {unsafeMime: true}), {caption: meme.title})
}
if (content.includes("!chat"))
{
chatting = true
console.log("chat start")
}
}
});
client.initialize();
Вот как начинается разговор:
Подсказка: «Привет»
Ответ:
;
uint32_t esi;
uint32_t edi;
uint32_t ebp;
uint32_t io_base;
uint32_t eip;
uint32_t cs;
uint32_t eflags;
uint32_t esp;
uint32_t ss;
uint32_t es;
uint32_t ds;
uint32_t fs;
uint32_t gs;
uint32_t ldt_selector;
uint16_t t;
uint16_t icharel_offset;
} _attribute_((packed)) TaskStateSegment;
/**
* An interrupt gate holds the function to call when the interrupt is received.
*/
typedef struct {
uint16_t offset_low;
uint16_t segment_selector;
uint8_t ist;
uint8_t type_attr;
uint16_t offset_middle;
uint32_t offset_high;
uint32_t reserved;
} _attribute_((packed)) InterruptGate;
/**
* Represents any general descriptor in the system.
* This could be a segment, task state, interrupt gate, or segment register.
*/
typedef struct {
union {
SegmentDescriptor segment;
TaskStateSegment tss;
InterruptGate interrupt_gate;
uint32_t segment_register;
};
} Descriptor;
/**
* Represents a global descriptor.
* This is basically just a descriptor with a tag denoting it's type.
*/
typedef struct {
Descriptor descriptor;
unsigned type;
} GDescriptor;
// Creates an interrupt gate to the given function.
InterruptGate interrupt_gate(void* handler, uint32_t ist);
// Creates a 64-bit TSS.
Descriptor tss_descriptor(uint32_t tss_size);
TaskSta
Я понятия не имею, что происходит, но если кто-то захочет помочь, буду очень признателен!