Skip to content

Commit

Permalink
Merge pull request #5 from genericness/testing
Browse files Browse the repository at this point in the history
Llama 3 groq
  • Loading branch information
Erisfiregamer1 authored May 5, 2024
2 parents d187d77 + 9bc2756 commit 85ec939
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions bots/llama_3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as types from "../main.d.ts";

export const information: types.information = {
llmFileVersion: "1.0",
env: ["GROQ_API_KEY"],
functions: false,
multiModal: false,
callbackSupport: true,
streamingSupport: false,
id: "llama3-groq",
name: "Llama 3 Groq",
description: "Meta's new flagship model. Powered by Groq!",
highCostLLM: false,
};

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

export async function send(
prompt: string | null,
messages: types.Message[],
callback?:
| ((information: types.callbackData, complete: boolean) => void)
| null,
requirements?: types.Requirements,
): Promise<types.Response> {
if (!requirements?.env?.GROQ_API_KEY) {
throw new DOMException("env.GROQ_API_KEY", "NotFoundError");
}

if (requirements.streaming) {
throw new DOMException("streaming", "NotSupportedError");
}
// here we go

if (messages.length === 0) {
messages.push({
role: "system",
content:
"You are Llama, an LLM by Meta. You are running through a Discord bot named LLM Bot, by Eris.",
});
}

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

const res = await fetch("https://api.groq.com/openai/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${requirements.env.GROQ_API_KEY}`,
},
body: JSON.stringify({
model: "llama3-70b-8192",
messages: messages,
}),
});

const resp: types.Response = await res.json();

if (resp.error) {
// Fuck.
throw resp.error.message; // well at least they know why the fuck it crashed??
}

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

resp.messages = messages;

if (callback) callback({ data: resp.choices[0].message.content }, true);

return resp;
}

0 comments on commit 85ec939

Please sign in to comment.