diff --git a/bots/gpt_4.ts b/bots/gpt_4.ts index 0e81f2a..4ee56df 100644 --- a/bots/gpt_4.ts +++ b/bots/gpt_4.ts @@ -36,6 +36,7 @@ export async function send( messages: OpenAI.Chat.ChatCompletionMessage[], prompt: string, userid: string, + images: string[] ): Promise { // here we go @@ -50,11 +51,31 @@ 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: { @@ -62,7 +83,8 @@ export async function send( 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, }), diff --git a/main.ts b/main.ts index b93231f..7990dbd 100644 --- a/main.ts +++ b/main.ts @@ -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"; @@ -81,7 +81,7 @@ 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.", @@ -89,10 +89,10 @@ client.on("messageCreate", async (message) => { 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; } @@ -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);