Skip to content

Commit

Permalink
Wuhoh, I'm still working on stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisfiregamer1 committed Apr 8, 2024
1 parent 6555fcc commit 0ef6bdd
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 184 deletions.
5 changes: 4 additions & 1 deletion bots/chatgpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const information: types.information = {
name: "GPT-3.5",
description:
"OpenAI's original flagship chat model, a low cost and quick to use model for general purposes.",
highCostLLM: false
highCostLLM: false,
};

async function doTools(
Expand Down Expand Up @@ -85,6 +85,8 @@ export async function send(
| null,
requirements?: types.Requirements,
): Promise<types.Response> {
console.log(requirements)

if (!requirements?.env?.OPENAI_API_KEY) {
throw new DOMException("env.OPENAI_API_KEY", "NotFoundError");
}
Expand Down Expand Up @@ -123,6 +125,7 @@ export async function send(
let resp: types.Response = await res.json();

if (resp.error) {
console.log(resp.error)
throw new DOMException(resp.error.message, "ExecutionError");
}

Expand Down
93 changes: 73 additions & 20 deletions bots/claude_3.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,73 @@
import * as types from "../main.d.ts";

type ClaudeResponse = {
id: string;
type: string;
role: string;
content: {
type: string;
text: string;
}[];
model: string;
stop_reason: string | null;
stop_sequence: null;
usage: {
input_tokens: number;
output_tokens: number;
};
};

export const information: types.information = {
llmFileVersion: "1.0",
env: ["ANTHROPIC_API_KEY"],
functions: false,
multiModal: false, // Listen man I just want to get this to work. I will fix the images later. SHUT UP. IT FUNCTIONS.
callbackSupport: true,
streamingSupport: false,
id: "c3opus",
name: "Claude 3 Opus",
description: "A very strong LLM for answering questions.",
highCostLLM: true,
};

// const db = await Deno.openKv("./db.sqlite")

function arrayBufferToBase64(buffer: ArrayBuffer) {
/*function arrayBufferToBase64(buffer: ArrayBuffer) {
let binary = "";
const bytes = new Uint8Array(buffer);
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return btoa(binary); // Base64 encode the binary string
}
}*/

export async function send(
messages: types.Message[],
prompt: string | null,
callback: (type: string, data: types.llmFileResponseClaude) => void,
values: types.Values,
): Promise<types.llmFileResponseClaude> {
messages: types.Message[],
callback?:
| ((information: types.callbackData, complete: boolean) => void)
| null,
requirements?: types.Requirements,
): Promise<types.Response> {
// here we go

if (!requirements?.env?.ANTHROPIC_API_KEY) {
throw new DOMException("env.OPENAI_API_KEY", "NotFoundError");
}

if (requirements.streaming) {
throw new DOMException("streaming", "NotSupportedError");
}

const sysprompt =
"You are Claude 3 Opus, an LLM by Anthropic. You are running through a Discord bot named LLM Bot, by Eris.";

const contentarr: types.AnthropicContentPart[] = [];
/*const contentarr: types.AnthropicContentPart[] = [];
if (values.images) {
if (requirements.images) {
// Use map to create an array of promises
const imagePromises = values.images.map(async (image_url) => {
const imagePromises = requirements.images.map(async (image_url) => {
const img = await fetch(image_url);
const imageType = img.headers.get("Content-Type");
Expand Down Expand Up @@ -62,18 +102,23 @@ export async function send(
text: prompt!,
});
let msg = {
let msg: ClaudeMessage = {
role: "user",
content: contentarr,
};
messages.push(msg);
messages.push(msg);*/

messages.push({
role: "user",
content: prompt,
});

const res = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": `${values.env.ANTHROPIC_API_KEY}`,
"x-api-key": `${requirements.env.ANTHROPIC_API_KEY}`,
"anthropic-version": "2023-06-01",
},
body: JSON.stringify({
Expand All @@ -84,16 +129,24 @@ export async function send(
}),
});

const resp: types.claudeResponse | types.Error = await res.json();
const resp: ClaudeResponse = await res.json();

messages.push({ role: "assistant", content: resp.content[0].text });

const fresp = {
resp,
messages,
if (callback) callback({ data: resp.content[0].text }, true);

return {
id: resp.id,
choices: [{
finish_reason: resp.stop_reason,
message: {
content: resp.content[0].text,
role: "assistant",
},
}],
messages: messages,
created: Date.now(),
model: resp.model,
object: "chat.completion",
};

callback("complete", fresp);

return fresp;
}
2 changes: 1 addition & 1 deletion bots/gpt_4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const information: types.information = {
name: "GPT-4",
description:
"An upgraded version of ChatGPT (GPT-3.5). Much better at answering questions!",
highCostLLM: true
highCostLLM: true,
};

async function doTools(
Expand Down
2 changes: 1 addition & 1 deletion bots/gpt_4_vision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const information: types.information = {
id: "gpt4v",
name: "GPT-4 Vision",
description: "A further upgraded version of GPT-4 with vision capabilities.",
highCostLLM: true
highCostLLM: true,
};

async function doTools(
Expand Down
2 changes: 1 addition & 1 deletion bots/mixtral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const information: types.information = {
id: "mixtral-groq",
name: "Mixtral (Groq)",
description: "Mistral's MOE model. Powered by Groq!",
highCostLLM: false
highCostLLM: false,
};

// const db = await Deno.openKv("./db.sqlite")
Expand Down
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ did some magijcks to the rest of the files idk man I forgor

# 3/31/2024: April Fools, Idiot

Reworked how LLMs are loaded, the bot is less of a full solution and more of a framework now
Reworked how LLMs are loaded, the bot is less of a full solution and more of a
framework now
38 changes: 19 additions & 19 deletions importLLMFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as types from "./main.d.ts";

import { build } from "https://deno.land/x/[email protected]/mod.js"
import { build } from "https://deno.land/x/[email protected]/mod.js";

export default async function importLLMFile(modulePath: string) {
try {
Expand All @@ -12,32 +12,30 @@ export default async function importLLMFile(modulePath: string) {

const tsCode = await Deno.readTextFile(Deno.cwd() + `/${modulePath}`);

const { outputFiles } = await build({
stdin: {
contents: tsCode,
loader: "ts",
},
bundle: true,
write: false,
format: "esm", // Specify output format as ESM
});
const { outputFiles } = await build({
stdin: {
contents: tsCode,
loader: "ts",
},
bundle: true,
write: false,
format: "esm", // Specify output format as ESM
});

const jsCode = outputFiles[0].text;
const jsCode = outputFiles[0].text;

const base64Data = btoa(jsCode);

// Create the Data URL
const dataURL = `data:text/plain;base64,${base64Data}`;

const module: types.llmFile = await import(dataURL)
const base64Data = btoa(jsCode);

// Create the Data URL
const dataURL = `data:text/plain;base64,${base64Data}`;

const module: types.llmFile = await import(dataURL);

if (module && module.information && typeof module.send === "function") {
globalThis.availableLLMs[module.information.id] = {
information: module.information,
send: module.send,
}
};

return module.information; // Return the information object
} else {
Expand All @@ -47,7 +45,9 @@ const dataURL = `data:text/plain;base64,${base64Data}`;
return null; // Return null if the module doesn't have the required exports
}
} catch (error) {
if (Deno.env.get("debug") === "true") console.error(`Error importing module ${modulePath}':`, error);
if (Deno.env.get("debug") === "true") {
console.error(`Error importing module ${modulePath}':`, error);
}
return null; // Return null if there's an error importing the module
}
}
Loading

0 comments on commit 0ef6bdd

Please sign in to comment.