Skip to content

Commit

Permalink
Fix: FallBack Api
Browse files Browse the repository at this point in the history
  • Loading branch information
Guru322 committed Nov 20, 2023
1 parent da85e2d commit da49f24
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions plugins/GURU-Openai.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fetch from 'node-fetch';


let handler = async (m, { text, conn, usedPrefix, command }) => {
if (!text && !(m.quoted && m.quoted.text)) {
throw `Please provide some text or quote a message to get a response.`;
Expand All @@ -19,34 +18,52 @@ let handler = async (m, { text, conn, usedPrefix, command }) => {
conn.sendPresenceUpdate('composing', m.chat);
const prompt = encodeURIComponent(text);


const guru1 = `${gurubot}/chatgpt?text=${prompt}`;
let response = await fetch(guru1);
let data = await response.json();
let result = data.result;

try {
let response = await fetch(guru1);
let data = await response.json();
let result = data.result;


if (!result) {
if (!result) {

throw new Error('No valid JSON response from the first API');
}

await conn.relayMessage(m.chat, {
protocolMessage: {
key,
type: 14,
editedMessage: {
imageMessage: { caption: result }
}
}
}, {});
m.react(done);
} catch (error) {
console.error('Error from the first API:', error);


const model = 'llama';
const senderNumber = m.sender.replace(/[^0-9]/g, '');
const session = `GURU_BOT_${senderNumber}`;
const guru2 = `https://ultimetron.guruapi.tech/gpt3?prompt=${prompt}`;

response = await fetch(guru2);
data = await response.json();
result = data.completion;
}
let response = await fetch(guru2);
let data = await response.json();
let result = data.completion;

await conn.relayMessage(m.chat, {
protocolMessage: {
key,
type: 14,
editedMessage: {
imageMessage: { caption: result }
await conn.relayMessage(m.chat, {
protocolMessage: {
key,
type: 14,
editedMessage: {
imageMessage: { caption: result }
}
}
}
}, {});
m.react(done)
}, {});
m.react(done);
}

} catch (error) {
console.error('Error:', error);
Expand Down

0 comments on commit da49f24

Please sign in to comment.