Skip to content

Commit

Permalink
GPT-4 is now default and has s i g h t
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisfiregamer1 committed Nov 7, 2023
1 parent f758478 commit ea7e131
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 6 deletions.
26 changes: 24 additions & 2 deletions bots/gpt_4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export async function send(
messages: OpenAI.Chat.ChatCompletionMessage[],
prompt: string,
userid: string,
images: string[]
): Promise<response> {
// here we go

Expand All @@ -50,19 +51,40 @@ export async function send(
});
}

const content_arr = []

content_arr.push({
type: "text",
text: prompt
})

if (images.length !== 0) {


images.forEach((imgurl) => {
content_arr.push({
type: "image_url",
image_url: imgurl
})
})
}

messages.push({
role: "user",
content: prompt,
content: content_arr, // how do I force update type definitions again?!
});



const res = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${Deno.env.get("OPENAI_API_KEY")}`,
},
body: JSON.stringify({
model: "gpt-4",
max_tokens: 4096,
model: "gpt-4-vision-preview",
messages: messages,
user: userid,
}),
Expand Down
62 changes: 58 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as chatgpt from "./bots/chatgpt.ts";
// import * as bing_chat from "./bots/bing_chat.ts";
// import * as gpt4 from "./bots/gpt_4.ts";
import * as gpt4 from "./bots/gpt_4.ts";
// import * as palm from "./bots/palm.ts";

import OpenAI from "npm:openai";
Expand Down Expand Up @@ -81,18 +81,18 @@ client.on("messageCreate", async (message) => {

if (llm === null) {
// They haven't used the bot before
llm = "chatgpt";
llm = "gpt4";
await db.set(["users", message.author.id, "current_bot"], llm);
await message.reply(
"Looks like this is your first time using this bot! Run /info to learn how to use the full potential of this bot.",
);
error = true;
} else if (!llm.match(/^(chatgpt|bing|bard|gpt4|llama2)$/g)) {
// current LLM is corrupt. notify user and reset
llm = "chatgpt";
llm = "gpt4";
await db.set(["users", message.author.id, "current_bot"], llm);
await message.reply(
"Your current LLM is corrupted or removed! We've reset you to ChatGPT for now.",
"Your current LLM is corrupted or removed! We've reset you to GPT4 for now.",
);
error = true;
}
Expand Down Expand Up @@ -178,6 +178,60 @@ client.on("messageCreate", async (message) => {

let i = 0;

messagechunks.forEach(async (chunk) => {
if (i <= 0) {
await msg.edit(chunk);
i++;
} else {
await message.reply(chunk);
}
});
} catch (err) {
msg.edit(
"Something went catastrophically wrong! Please tell the bot host to check the logs, thaaaaanks",
);
console.error(
"hey dumbass this error got thrown, go check that thanks:",
err,
);
return;
}
} else if (llm === "gpt4") {
if (!gpt4.isEnabled) {
msg.edit(
"This LLM isn't enabled! Please switch to a different LLM to use this bot.",
);
return;
}

const images: string[] = []

message.attachments.forEach((image) => {
images.push(image.url)
})

try {
resp = await gpt4.send(
curmsgs,
message.content,
message.author.id,
images
);

messages[curconv].messages = resp.messages;

await db.set(
["users", message.author.id, "conversations", llm],
messages,
);

const messagechunks = splitStringIntoChunks(
resp.oaires.choices[0].message.content,
2000,
);

let i = 0;

messagechunks.forEach(async (chunk) => {
if (i <= 0) {
await msg.edit(chunk);
Expand Down

0 comments on commit ea7e131

Please sign in to comment.