2024-06-18 19:48:16 -07:00
|
|
|
import Groq from 'groq-sdk'
|
2024-06-18 17:56:49 -07:00
|
|
|
import { getKey } from '../utils/keys.js';
|
2024-06-18 17:56:04 -07:00
|
|
|
|
2024-08-25 13:16:32 -07:00
|
|
|
export class Mixtral_Groq {
|
2024-06-18 19:10:56 -07:00
|
|
|
constructor(model_name, url) {
|
|
|
|
this.model_name = model_name;
|
|
|
|
this.url = url;
|
2024-08-25 00:42:37 -07:00
|
|
|
this.groq = new Groq({ apiKey: getKey('GROQCLOUD_API_KEY')});
|
2024-06-18 19:10:56 -07:00
|
|
|
}
|
|
|
|
|
2024-08-25 00:42:37 -07:00
|
|
|
async sendRequest(turns, systemMessage, stop_seq=null) {
|
2024-06-18 19:10:56 -07:00
|
|
|
let messages = [{"role": "system", "content": systemMessage}].concat(turns);
|
|
|
|
let res = null;
|
|
|
|
try {
|
|
|
|
console.log("Awaiting Groq response...");
|
|
|
|
let completion = await this.groq.chat.completions.create({
|
|
|
|
"messages": messages,
|
|
|
|
"model": this.model_name || "mixtral-8x7b-32768",
|
2024-06-18 21:15:42 -07:00
|
|
|
"temperature": 0.2,
|
2024-06-18 19:59:41 -07:00
|
|
|
"max_tokens": 16384,
|
2024-06-18 19:10:56 -07:00
|
|
|
"top_p": 1,
|
|
|
|
"stream": true,
|
2024-08-25 00:42:37 -07:00
|
|
|
"stop": stop_seq // "***"
|
2024-06-18 19:10:56 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
let temp_res = "";
|
|
|
|
for await (const chunk of completion) {
|
|
|
|
temp_res += chunk.choices[0]?.delta?.content || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
res = temp_res;
|
|
|
|
|
|
|
|
}
|
|
|
|
catch(err) {
|
|
|
|
console.log(err);
|
|
|
|
res = "My brain just kinda stopped working. Try again.";
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2024-08-25 13:16:32 -07:00
|
|
|
async embed(text) {
|
|
|
|
console.log("There is no support for embeddings in Groq support. However, the following text was provided: " + text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class LLama3_70b_Groq {
|
|
|
|
constructor(model_name, url) {
|
|
|
|
this.model_name = model_name;
|
|
|
|
this.url = url;
|
|
|
|
this.groq = new Groq({ apiKey: getKey('GROQCLOUD_API_KEY')});
|
|
|
|
}
|
|
|
|
|
|
|
|
async sendRequest(turns, systemMessage, stop_seq=null) {
|
|
|
|
let messages = [{"role": "system", "content": systemMessage}].concat(turns);
|
|
|
|
let res = null;
|
|
|
|
try {
|
|
|
|
console.log("Awaiting Groq response...");
|
|
|
|
let completion = await this.groq.chat.completions.create({
|
|
|
|
"messages": messages,
|
|
|
|
"model": this.model_name || "llama3-70b-8192",
|
|
|
|
"temperature": 0.2,
|
|
|
|
"max_tokens": 8192, // maximum token limit
|
|
|
|
"top_p": 1,
|
|
|
|
"stream": true,
|
|
|
|
"stop": stop_seq // "***"
|
|
|
|
});
|
|
|
|
|
|
|
|
let temp_res = "";
|
|
|
|
for await (const chunk of completion) {
|
|
|
|
temp_res += chunk.choices[0]?.delta?.content || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
res = temp_res;
|
|
|
|
|
|
|
|
}
|
|
|
|
catch(err) {
|
|
|
|
console.log(err);
|
|
|
|
res = "My brain just kinda stopped working. Try again.";
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
async embed(text) {
|
|
|
|
console.log("There is no support for embeddings in Groq support. However, the following text was provided: " + text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Gemma2_9b_Groq {
|
|
|
|
constructor(model_name, url) {
|
|
|
|
this.model_name = model_name;
|
|
|
|
this.url = url;
|
|
|
|
this.groq = new Groq({ apiKey: getKey('GROQCLOUD_API_KEY')});
|
|
|
|
}
|
|
|
|
|
|
|
|
async sendRequest(turns, systemMessage, stop_seq=null) {
|
|
|
|
let messages = [{"role": "system", "content": systemMessage}].concat(turns);
|
|
|
|
let res = null;
|
|
|
|
try {
|
|
|
|
console.log("Awaiting Groq response...");
|
|
|
|
let completion = await this.groq.chat.completions.create({
|
|
|
|
"messages": messages,
|
|
|
|
"model": this.model_name || "gemma2-9b-it",
|
|
|
|
"temperature": 0.2,
|
|
|
|
"max_tokens": 8192, // maximum token limit
|
|
|
|
"top_p": 1,
|
|
|
|
"stream": true,
|
|
|
|
"stop": stop_seq // "***"
|
|
|
|
});
|
|
|
|
|
|
|
|
let temp_res = "";
|
|
|
|
for await (const chunk of completion) {
|
|
|
|
temp_res += chunk.choices[0]?.delta?.content || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
res = temp_res;
|
|
|
|
|
|
|
|
}
|
|
|
|
catch(err) {
|
|
|
|
console.log(err);
|
|
|
|
res = "My brain just kinda stopped working. Try again.";
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2024-06-18 19:10:56 -07:00
|
|
|
async embed(text) {
|
2024-08-25 00:42:37 -07:00
|
|
|
console.log("There is no support for embeddings in Groq support. However, the following text was provided: " + text);
|
2024-06-18 19:10:56 -07:00
|
|
|
}
|
2024-06-18 20:15:17 -07:00
|
|
|
}
|