2024-11-05 19:17:56 +00:00
|
|
|
// groq.js
|
2024-11-25 11:55:47 +00:00
|
|
|
// Namhyeon Go <abuse@catswords.net>
|
2024-11-05 19:17:56 +00:00
|
|
|
// https://github.com/gnh1201/welsonjs
|
2024-11-25 11:55:47 +00:00
|
|
|
//
|
|
|
|
// ***SECURITY NOTICE***
|
2024-11-25 16:41:21 +00:00
|
|
|
// Groq requires an internet connection, and data may be transmitted externally. Users must adhere to the terms of use and privacy policy.
|
2024-11-25 11:55:47 +00:00
|
|
|
// - Privacy Policy: https://groq.com/privacy-policy/
|
|
|
|
//
|
2024-11-05 19:17:56 +00:00
|
|
|
var FILE = require("lib/file");
|
|
|
|
var HTTP = require("lib/http");
|
|
|
|
|
|
|
|
function loadApiKey() {
|
|
|
|
var s = FILE.readFile("data/groq-apikey.txt", FILE.CdoCharset.CdoUTF_8);
|
|
|
|
return s.trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
function chat(content) {
|
|
|
|
var answers = [];
|
|
|
|
|
|
|
|
var apikey = loadApiKey();
|
|
|
|
console.log("Groq (GroqCloud) API KEY:", apikey);
|
|
|
|
|
|
|
|
var response = HTTP.create("MSXML")
|
|
|
|
.setContentType("application/json")
|
|
|
|
.setBearerAuth(apikey)
|
|
|
|
.setRequestBody({
|
|
|
|
"model": "llama3-8b-8192",
|
|
|
|
"messages": [{
|
|
|
|
"role": "user",
|
|
|
|
"content": content
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
.open("post", "https://api.groq.com/openai/v1/chat/completions")
|
|
|
|
.send()
|
|
|
|
.responseBody;
|
|
|
|
|
|
|
|
if ("error" in response) {
|
|
|
|
answers.push("Error: " + response.error.message);
|
|
|
|
} else if (response.choices.length > 0) {
|
|
|
|
answers.push(response.choices[0].message.content);
|
|
|
|
}
|
|
|
|
|
|
|
|
return answers.join(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.chat = chat;
|
|
|
|
|
|
|
|
exports.VERSIONINFO = "Groq (GroqCloud) interface (groq.js) version 0.1";
|
|
|
|
exports.AUTHOR = "abuse@catswords.net";
|
|
|
|
exports.global = global;
|
|
|
|
exports.require = global.require;
|