mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 15:04:58 +00:00
Add Grok (x.ai) interface
This commit is contained in:
parent
1cea720a70
commit
74005364e2
|
@ -2,6 +2,7 @@
|
||||||
"chatgpt": "file:data/chatgpt_apikey.txt",
|
"chatgpt": "file:data/chatgpt_apikey.txt",
|
||||||
"anthropic": "file:data/anthropic_apikey.txt",
|
"anthropic": "file:data/anthropic_apikey.txt",
|
||||||
"groq": "file:data/groq_apikey.txt",
|
"groq": "file:data/groq_apikey.txt",
|
||||||
|
"grok": "file:data/grok_apikey.txt",
|
||||||
"scrapeops": "file:data/scrapeops_apikey.txt",
|
"scrapeops": "file:data/scrapeops_apikey.txt",
|
||||||
"searchapi": "file:data/searchapi_apikey.txt",
|
"searchapi": "file:data/searchapi_apikey.txt",
|
||||||
"aviationstack": "file:data/aviationstack_apikey.txt",
|
"aviationstack": "file:data/aviationstack_apikey.txt",
|
||||||
|
|
|
@ -14,7 +14,7 @@ function chat(content) {
|
||||||
var answers = [];
|
var answers = [];
|
||||||
|
|
||||||
var apikey = CRED.get("apikey", "chatgpt");
|
var apikey = CRED.get("apikey", "chatgpt");
|
||||||
console.log("ChatGPT API KEY:", apikey);
|
console.log("OpenAI (ChatGPT) API KEY:", apikey);
|
||||||
|
|
||||||
var response = HTTP.create("MSXML")
|
var response = HTTP.create("MSXML")
|
||||||
.setVariables({
|
.setVariables({
|
||||||
|
@ -38,7 +38,7 @@ function chat(content) {
|
||||||
.responseBody
|
.responseBody
|
||||||
;
|
;
|
||||||
|
|
||||||
if (response.choices.length > 0) {
|
if ("choices" in response && response.choices.length > 0) {
|
||||||
response.choices.forEach(function(x) {
|
response.choices.forEach(function(x) {
|
||||||
answers.push(x.message.content);
|
answers.push(x.message.content);
|
||||||
});
|
});
|
||||||
|
@ -49,7 +49,7 @@ function chat(content) {
|
||||||
|
|
||||||
exports.chat = chat;
|
exports.chat = chat;
|
||||||
|
|
||||||
exports.VERSIONINFO = "ChatGPT interface (chatgpt.js) version 0.1.1";
|
exports.VERSIONINFO = "OpenAI (ChatGPT) interface version 0.1.2";
|
||||||
exports.AUTHOR = "abuse@catswords.net";
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
53
lib/grok.js
Normal file
53
lib/grok.js
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
// grok.js
|
||||||
|
// Namhyeon Go <abuse@catswords.net>
|
||||||
|
// https://github.com/gnh1201/welsonjs
|
||||||
|
//
|
||||||
|
// ***SECURITY NOTICE***
|
||||||
|
// Grok (x.ai) requires an internet connection, and data may be transmitted externally. Users must adhere to the terms of use and privacy policy.
|
||||||
|
// - Privacy Policy: https://x.ai/legal/privacy-policy
|
||||||
|
//
|
||||||
|
var FILE = require("lib/file");
|
||||||
|
var HTTP = require("lib/http");
|
||||||
|
var CRED = require("lib/credentials");
|
||||||
|
|
||||||
|
function chat(content) {
|
||||||
|
var answers = [];
|
||||||
|
|
||||||
|
var apikey = CRED.get("apikey", "grok");
|
||||||
|
console.log("Grok (x.ai) API KEY:", apikey);
|
||||||
|
|
||||||
|
var response = HTTP.create("MSXML")
|
||||||
|
.setVariables({
|
||||||
|
"GROK_API_KEY": apikey
|
||||||
|
})
|
||||||
|
.setHeaders({
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": "Bearer {GROK_API_KEY}"
|
||||||
|
})
|
||||||
|
.setRequestBody({
|
||||||
|
"messages": [{
|
||||||
|
"role": "user",
|
||||||
|
"content": content
|
||||||
|
}],
|
||||||
|
"model": "grok-2-latest"
|
||||||
|
})
|
||||||
|
.open("post", "https://api.x.ai/v1/chat/completions")
|
||||||
|
.send()
|
||||||
|
.responseBody
|
||||||
|
;
|
||||||
|
|
||||||
|
if ("choices" in response && response.choices.length > 0) {
|
||||||
|
response.choices.forEach(function(x) {
|
||||||
|
answers.push(x.message.content);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return answers.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.chat = chat;
|
||||||
|
|
||||||
|
exports.VERSIONINFO = "Grok (x.ai) interface version 0.1";
|
||||||
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
|
exports.global = global;
|
||||||
|
exports.require = global.require;
|
Loading…
Reference in New Issue
Block a user