diff --git a/examples/honoai_gemini.ai.js b/examples/honoai_gemini.ai.js new file mode 100644 index 0000000..cda3cec --- /dev/null +++ b/examples/honoai_gemini.ai.js @@ -0,0 +1,17 @@ +var LIE = require("lib/language-inference-engine") + +function main(args) { + + var provider = "gemini" + var text = "hanoi tower example" + + var res = LIE.create() + .setProvider(provider) + // If no model is specified, the first possible model is used. + .setModel("gemini-2.0-flash") + .inference(text, 0) + .join(' ') + console.log(res) +} + +exports.main = main; diff --git a/lib/language-inference-engine.js b/lib/language-inference-engine.js index 52b822e..1a71080 100644 --- a/lib/language-inference-engine.js +++ b/lib/language-inference-engine.js @@ -185,33 +185,39 @@ var ENGINE_PROFILES = { }, []); } }, - "google": { + "gemini": { "type": "llm", "availableModels": [ + "gemini-2.0-flash", "gemini-1.5-flash" ], "headers": { "Content-Type": "application/json" }, "url": "https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent?key={apikey}", - "warp": function(model, message, temperature) { + "wrap": function(model, message, temperature) { return { - "contents": [ - { - "parts": [ - { - "text": message - } - ] - } - ] + "contents": [{ + "role": "system", + "parts": [{ + "text": BIAS_MESSAGE + }] + }, { + "role": "user", + "parts": [{ + "text": message + }] + }], + "generationConfig": { + "temperature": temperature + } }; }, "callback": function(response) { if ("error" in response) { return ["Error: " + response.error.message]; } else { - return response.candidates.reduce(function(a, x) { + return response["candidates"].reduce(function(a, x) { x.content.parts.forEach(function(part) { if ("text" in part) { a.push(part.text); @@ -219,7 +225,6 @@ var ENGINE_PROFILES = { a.push("Not supported type"); } }); - return a; }, []); } @@ -508,6 +513,11 @@ function LanguageInferenceEngine() { var headers = this.engineProfile.headers; var wrap = this.engineProfile.wrap; var url = this.engineProfile.url; + if(this.provider === "gemini"){ + url = url + .replace(/{model}/g, this.model) + .replace(/{apikey}/g, apikey); + } var callback = this.engineProfile.callback; var response = HTTP.create("MSXML") @@ -520,6 +530,14 @@ function LanguageInferenceEngine() { .send() .responseBody; + if(typeof response === 'string'){ + try { + response = JSON.parse(response) + } catch (e) { + return ["Error: Malformed response - " + e.message]; + } + } + return callback(response); }; } diff --git a/lib/security.js b/lib/security.js index 1e490eb..3ba833b 100644 --- a/lib/security.js +++ b/lib/security.js @@ -14,7 +14,7 @@ function __BOOL_TO_DWORD__(x) { } // Check 'Run as administrator' -function isElevated = function() { +var isElevated = function() { try { CreateObject("WScript.Shell").RegRead("HKEY_USERS\\s-1-5-19\\"); return true; diff --git a/lib/winservice.js b/lib/winservice.js index eea23bd..cff7960 100644 --- a/lib/winservice.js +++ b/lib/winservice.js @@ -13,7 +13,7 @@ var VirtualInputObject = function() { } catch (e) { console.error("VirtualInputObject.create() -> " + e.message); } - ); + }; this.moveMouse = function(x, y) { this.oAutoIt.MouseMove(x, y); diff --git a/testloader.js b/testloader.js index 092457f..21bcbaa 100644 --- a/testloader.js +++ b/testloader.js @@ -1137,7 +1137,7 @@ var test_implements = { job.setHostName("example.org"); job.setResourceName(resourceName); job.saveTo("D:\\"); - }; + }); } };