Skip to content

Commit

Permalink
POMNI WAKE UP TIME TO GO ON AN ADVENTURE
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisfiregamer1 committed Feb 26, 2024
1 parent fa0df26 commit f62c099
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 204 deletions.
13 changes: 6 additions & 7 deletions bots/chatgpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const tools: types.Tool[] = [{
async function doTools(
oaires: types.Response,
messages: types.Message[],
callback: Function,
callback: (type: string, data: types.Response) => void,
): Promise<types.Response> {
if (oaires.choices[0].finish_reason !== "tool_calls") {
throw "What The Shit?";
Expand Down Expand Up @@ -108,7 +108,7 @@ export async function send(
messages: types.Message[],
prompt: string | null,
userid: string,
callback: Function,
callback: (type: string, data: types.Response) => void,
): Promise<types.Response> {
// here we go

Expand All @@ -119,7 +119,8 @@ export async function send(
if (messages.length === 0) {
messages.push({
role: "system",
content: "You are ChatGPT, an LLM by OpenAI. You are running through a Discord bot named LLM Bot, by Eris.",
content:
"You are ChatGPT, an LLM by OpenAI. You are running through a Discord bot named LLM Bot, by Eris.",
});
}

Expand Down Expand Up @@ -151,7 +152,7 @@ export async function send(
throw resp.error.message; // well at least they know why the fuck it crashed??
}

let finalresp = resp
let finalresp = resp;

messages.push(resp.choices[0].message);

Expand All @@ -160,9 +161,7 @@ export async function send(

finalresp = await doTools(resp, messages, callback);
} else {

callback("complete", finalresp)

callback("complete", finalresp);
}

return finalresp;
Expand Down
2 changes: 1 addition & 1 deletion bots/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function send(

const res = await fetch(
`https://generativelanguage.googleapis.com/v1beta/models/${
useImageModel === true ? "gemini-pro-vision" : "gemini-pro"
useImageModel === true ? "gemini-1.0-pro-vision" : "gemini-1.0-pro"
}:generateContent?key=${Deno.env.get("GEMINI_API_KEY")}`,
{
method: "POST",
Expand Down
39 changes: 17 additions & 22 deletions bots/openrouter.ts → bots/mixtral.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
export const isEnabled = true; // OpenRouter is always enabled as a fallback option in case the bot's screwed up

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

export const requested_values = {
env: ["GROQ_API_KEY"],
};

type response = {
oaires: types.Response;
messages: types.Message[];
};

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

export async function send(
messages: types.Message[],
prompt: string | null,
_userid: string, // Included in case it becomes possible to use. OpenRouter doesn't use this one.
model: string,
api_key: string,
): Promise<response> {
callback: (type: string, data: types.Response) => void,
values: types.Values,
): Promise<types.Response> {
// here we go

if (!isEnabled) {
throw "not_enabled";
}

if (messages.length === 0) {
messages.push({
role: "system",
content: `You are ${model}, an LLM hosted by OpenRouter.`,
content:
"You are ChatGPT, an LLM by OpenAI. You are running through a Discord bot named LLM Bot, by Eris.",
});
}

Expand All @@ -34,16 +34,14 @@ export async function send(
});
}

console.log(messages);

const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
const res = await fetch("https://api.groq.com/openai/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${api_key}`,
Authorization: `Bearer ${values.env.GROQ_API_KEY}`,
},
body: JSON.stringify({
model,
model: "mixtral-8x7b-32768",
messages: messages,
}),
});
Expand All @@ -55,12 +53,9 @@ export async function send(
throw resp.error.message; // well at least they know why the fuck it crashed??
}

const finalresp: response = {
oaires: resp,
messages,
};

messages.push(resp.choices[0].message);

return finalresp;
callback("complete", resp);

return resp;
}
6 changes: 6 additions & 0 deletions bots/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,9 @@ export type geminiResponse = {
candidates: GeminiCandidate[];
promptFeedback: GeminiPromptFeedback;
};

export type Values = {
env: {
[envValue: string]: string;
};
};
1 change: 1 addition & 0 deletions lib/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export function safeEval(code: string): Promise<string> {
import.meta.resolve("./eval_worker.js"),
{
type: "module",
// @ts-ignore
name,
deno: {
//@ts-ignore ignore the namespace annotation. Deno < 1.22 required this
Expand Down
20 changes: 9 additions & 11 deletions lib/eval_worker.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// deno-lint-ignore no-global-assign
console = null
console = null;

self.onmessage = async (e) => {
try {

const response = `${eval(e.data)}`

postMessage(response)

} catch (err) {
postMessage(`Error occured during code processing: ${err}`)
}
}
try {
const response = `${eval(e.data)}`;

postMessage(response);
} catch (err) {
postMessage(`Error occured during code processing: ${err}`);
}
};
Loading

0 comments on commit f62c099

Please sign in to comment.