From ab2f3df4eabd8d053aaaa551e409a49bc5ddf607 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Tue, 28 Jan 2025 00:02:22 +0900 Subject: [PATCH] Update language-inference-engine.js --- lib/language-inference-engine.js | 57 ++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/lib/language-inference-engine.js b/lib/language-inference-engine.js index 1ca11dc..30697df 100644 --- a/lib/language-inference-engine.js +++ b/lib/language-inference-engine.js @@ -9,8 +9,9 @@ // - Anthropic: https://www.anthropic.com/legal/privacy // - Groq: https://groq.com/privacy-policy/ // - xAI: https://x.ai/legal/privacy-policy +// - Google Gemini: https://developers.google.com/idx/support/privacy // - DeepSeek: https://chat.deepseek.com/downloads/DeepSeek%20Privacy%20Policy.html -// +// var HTTP = require("lib/http"); var CRED = require("lib/credentials"); @@ -43,6 +44,7 @@ var engineProfiles = { } else { return response.choices.reduce(function(a, x) { a.push(x.message.content); + return a; }, []); } @@ -81,6 +83,7 @@ var engineProfiles = { } else { a.push("Not supported type: " + x.type); } + return a; }, []); } @@ -113,6 +116,7 @@ var engineProfiles = { } else { return response.choices.reduce(function(a, x) { a.push(x.message.content); + return a; }, []); } @@ -142,10 +146,48 @@ var engineProfiles = { "callback": function(response) { return response.choices.reduce(function(a, x) { a.push(x.message.content); + return a; }, []); } }, + "google": { + "headers": { + "Content-Type": "application/json", + "Authorization": "Bearer {apikey}" + }, + "url": "https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent?key={apikey}", + "warp": function(model, message) { + return { + "contents": [ + { + "parts": [ + { + "text": message + } + ] + } + ] + } + }, + "callback": function(response) { + if ("error" in response) { + return ["Error: " + response.error.message]; + } else { + return response.candidates.reduce(function(a, x) { + x.content.parts.forEach(function(part) { + if ("text" in part) { + a.push(part.text); + } else { + a.push("Not supported type"); + } + }); + + return a; + }, []); + } + } + }, "deepseek": { "headers": { "Content-Type": "application/json", @@ -173,6 +215,7 @@ var engineProfiles = { } else { return response.choices.reduce(function(a, x) { a.push(x.message.content); + return a; }, []); } @@ -218,9 +261,8 @@ function LanguageInferenceEngine() { var wrap = this.engineProfile.wrap; var url = this.engineProfile.url; var callback = this.engineProfile.callback; - - return callback( - HTTP.create("MSXML") + + var response = HTTP.create("MSXML") .setVariables({ "apikey": apikey }) @@ -228,8 +270,9 @@ function LanguageInferenceEngine() { .setRequestBody(wrap(message)) .open("post", url) .send() - .responseBody - ); + .responseBody; + + return callback(response); }; } @@ -238,7 +281,7 @@ exports.create = function() { return new LanguageInferenceEngine(); }; -exports.VERSIONINFO = "Language Inference Engine (NLP/LLM) integration version 0.1"; +exports.VERSIONINFO = "Language Inference Engine (NLP/LLM) integration version 0.1.1"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = global.require;