Groq updates

This commit is contained in:
FateUnix29 2025-02-17 15:49:52 -08:00
parent 7a9faca7c3
commit 600df8e475
2 changed files with 58 additions and 17 deletions

View file

@ -8,7 +8,7 @@
"canvas": "^3.1.0", "canvas": "^3.1.0",
"express": "^4.18.2", "express": "^4.18.2",
"google-translate-api-x": "^10.7.1", "google-translate-api-x": "^10.7.1",
"groq-sdk": "^0.5.0", "groq-sdk": "^0.15.0",
"minecraft-data": "^3.78.0", "minecraft-data": "^3.78.0",
"mineflayer": "^4.23.0", "mineflayer": "^4.23.0",
"mineflayer-armor-manager": "^2.0.1", "mineflayer-armor-manager": "^2.0.1",

View file

@ -1,53 +1,94 @@
import Groq from 'groq-sdk' import Groq from 'groq-sdk'
import { getKey } from '../utils/keys.js'; import { getKey } from '../utils/keys.js';
// THIS API IS NOT TO BE CONFUSED WITH GROK!
// Go to grok.js for that. :)
// Umbrella class for Mixtral, LLama, Gemma...
// NOTICE: I've moved to an actual custom coding style. Sorry if this seems quite a bit more spaced out than the rest of the classes, as this style places HEAVY emphasis on spacing and
// readability.
// I'm just maintaining my old legacy code.
// Cheers, Kalinite/Copper/FateUnix29/...
// Umbrella class for everything under the sun... That GroqCloud provides, that is.
export class GroqCloudAPI { export class GroqCloudAPI {
constructor(model_name, url, params) { constructor(model_name, url, params) {
this.model_name = model_name; this.model_name = model_name;
this.url = url; this.url = url;
this.params = params || {}; this.params = params || {};
// ReplicateAPI theft :3
if (this.url) {
// Remove any mention of "tools" from params:
if (this.params.tools)
delete this.params.tools;
// This is just a bit of future-proofing in case we drag Mindcraft in that direction.
// I'm going to do a sneaky ReplicateAPI theft for a lot of this, aren't I?
if (this.url)
console.warn("Groq Cloud has no implementation for custom URLs. Ignoring provided URL."); console.warn("Groq Cloud has no implementation for custom URLs. Ignoring provided URL.");
}
this.groq = new Groq({ apiKey: getKey('GROQCLOUD_API_KEY') }); this.groq = new Groq({ apiKey: getKey('GROQCLOUD_API_KEY') });
} }
async sendRequest(turns, systemMessage, stop_seq=null) { async sendRequest(turns, systemMessage, stop_seq=null) {
let messages = [{"role": "system", "content": systemMessage}].concat(turns);
let messages = [{"role": "system", "content": systemMessage}].concat(turns); // The standard for GroqCloud is just appending to a messages array starting with the system prompt, but
// this is perfectly acceptable too, and I recommend it.
// I still feel as though I should note it for any future revisions of MindCraft, though.
// These variables look odd, but they're for the future. Please keep them intact.
let raw_res = null;
let res = null; let res = null;
let tool_calls = null;
try { try {
console.log("Awaiting Groq response..."); console.log("Awaiting Groq response...");
if (!this.params.max_tokens) {
this.params.max_tokens = 16384; if (this.params.max_tokens) {
console.warn("GROQCLOUD WARNING: A profile is using `max_tokens`. This is deprecated. Please move to `max_completion_tokens`.");
this.params.max_completion_tokens = this.params.max_tokens;
delete this.params.max_tokens;
} }
if (!this.params.max_completion_tokens) {
this.params.max_completion_tokens = 8000; // Set it lower. This is a common theme.
}
let completion = await this.groq.chat.completions.create({ let completion = await this.groq.chat.completions.create({
"messages": messages, "messages": messages,
"model": this.model_name || "mixtral-8x7b-32768", "model": this.model_name || "llama-3.3-70b-versatile",
"stream": true, "stream": false,
"tools": null,
"tool_choice": "auto",
"stop": stop_seq, "stop": stop_seq,
...(this.params || {}) ...(this.params || {})
}); });
let temp_res = ""; raw_res = completion.choices[0].message;
for await (const chunk of completion) { res = raw_res.content;
temp_res += chunk.choices[0]?.delta?.content || '';
}
res = temp_res;
} }
catch(err) { catch(err) {
console.log(err); console.log(err);
res = "My brain just kinda stopped working. Try again."; res = "My brain just kinda stopped working. Try again.";
} }
return res; return res;
} }
async embed(text) { async embed(_) {
throw new Error('Embeddings are not supported by Groq.'); throw new Error('Embeddings are not supported by Groq.');
} }
} }