mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 07:21:43 +00:00
Add support the Groq LLM API
This commit is contained in:
parent
6d0a6c645f
commit
2f1a0f6e41
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -107,6 +107,7 @@ dist
|
||||||
bin
|
bin
|
||||||
data/chatgpt-apikey.txt
|
data/chatgpt-apikey.txt
|
||||||
data/anthropic-apikey.txt
|
data/anthropic-apikey.txt
|
||||||
|
data/groq-apikey.txt
|
||||||
app/assets/img/_templates
|
app/assets/img/_templates
|
||||||
app/assets/img/_captured
|
app/assets/img/_captured
|
||||||
settings.ini
|
settings.ini
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Anthropic.js
|
// anthropic.js
|
||||||
// https://github.com/gnh1201/welsonjs
|
// https://github.com/gnh1201/welsonjs
|
||||||
// Anthropic API documentation: https://docs.anthropic.com/en/api/getting-started
|
// Anthropic API documentation: https://docs.anthropic.com/en/api/getting-started
|
||||||
var FILE = require("lib/file");
|
var FILE = require("lib/file");
|
||||||
|
@ -19,8 +19,8 @@ function chat(content) {
|
||||||
.setVariables({
|
.setVariables({
|
||||||
"ANTHROPIC_API_KEY": apikey
|
"ANTHROPIC_API_KEY": apikey
|
||||||
})
|
})
|
||||||
|
.setContentType("application/json")
|
||||||
.setHeaders({
|
.setHeaders({
|
||||||
"Content-Type": "application/json",
|
|
||||||
"x-api-key": "{ANTHROPIC_API_KEY}",
|
"x-api-key": "{ANTHROPIC_API_KEY}",
|
||||||
"anthropic-version": "2023-06-01"
|
"anthropic-version": "2023-06-01"
|
||||||
})
|
})
|
||||||
|
@ -53,7 +53,7 @@ function chat(content) {
|
||||||
|
|
||||||
exports.chat = chat;
|
exports.chat = chat;
|
||||||
|
|
||||||
exports.VERSIONINFO = "Anthropic (Claude) interface (anthropic.js) version 0.1";
|
exports.VERSIONINFO = "Anthropic (Claude) interface (anthropic.js) version 0.1.1";
|
||||||
exports.AUTHOR = "abuse@catswords.net";
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
46
lib/groq.js
Normal file
46
lib/groq.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// groq.js
|
||||||
|
// https://github.com/gnh1201/welsonjs
|
||||||
|
// Groq API documentation: https://console.groq.com/docs/api-reference
|
||||||
|
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;
|
Loading…
Reference in New Issue
Block a user