From ef23e41e3a35742d96287348f4a7531dde8ebfe6 Mon Sep 17 00:00:00 2001 From: Jihoon Yi <44565599+baramofme@users.noreply.github.com> Date: Sat, 10 May 2025 15:50:55 +0900 Subject: [PATCH 1/8] Update language-inference-engine.js Fix gemini call broken --- lib/language-inference-engine.js | 37 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/language-inference-engine.js b/lib/language-inference-engine.js index 52b822e..0cde9f6 100644 --- a/lib/language-inference-engine.js +++ b/lib/language-inference-engine.js @@ -185,33 +185,40 @@ 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": "user", // Changed "developer" to "user" for the initial prompt. The overall prompt is still intended to guide the model, so this is reasonable. + "parts": [{ + "text": BIAS_MESSAGE + }] + }, { + "role": "user", + "parts": [{ + "text": message + }] + }], + "generationConfig": { + "temperature": temperature + } }; }, "callback": function(response) { + response = JSON.parse(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 +226,6 @@ var ENGINE_PROFILES = { a.push("Not supported type"); } }); - return a; }, []); } @@ -508,6 +514,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") From bcdfef3f6f72917dadc6b1e7b44fe04891516c70 Mon Sep 17 00:00:00 2001 From: Jihoon Yi <44565599+baramofme@users.noreply.github.com> Date: Sat, 10 May 2025 15:54:04 +0900 Subject: [PATCH 2/8] Create honoai_gemini.ai.js Add honoi ai call with gemini --- examples/honoai_gemini.ai.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 examples/honoai_gemini.ai.js diff --git a/examples/honoai_gemini.ai.js b/examples/honoai_gemini.ai.js new file mode 100644 index 0000000..a5f21c0 --- /dev/null +++ b/examples/honoai_gemini.ai.js @@ -0,0 +1,15 @@ +var LIE = require("lib/language-inference-engine") + +function main(args) { + + var provider = "gemini" + var text = "hanoi tower example" + + var res = LIE.create() + .setProvider(provider) + .inference(text, 0) + .join(' ') + console.log(res) +} + +exports.main = main; From b1078cd36c7d2e53784de4c2bf0a9d23c4374612 Mon Sep 17 00:00:00 2001 From: Jihoon Yi <44565599+baramofme@users.noreply.github.com> Date: Sat, 10 May 2025 16:22:08 +0900 Subject: [PATCH 3/8] Add missing model selection in honoai_gemini.ai.js Add missing model selection --- examples/honoai_gemini.ai.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/honoai_gemini.ai.js b/examples/honoai_gemini.ai.js index a5f21c0..cda3cec 100644 --- a/examples/honoai_gemini.ai.js +++ b/examples/honoai_gemini.ai.js @@ -7,6 +7,8 @@ function main(args) { 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) From d8a29eaeeefc8d9d50e494c1a7930b5f3010f2de Mon Sep 17 00:00:00 2001 From: Jihoon Yi <44565599+baramofme@users.noreply.github.com> Date: Sat, 10 May 2025 16:30:46 +0900 Subject: [PATCH 4/8] Update language-inference-engine.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add response type check before parsing - Wrap JSON.parse in a try/catch to handle potential malformed responses. - Use “system” role for the initial bias message on gemini model object's wrap --- lib/language-inference-engine.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/language-inference-engine.js b/lib/language-inference-engine.js index 0cde9f6..b40340f 100644 --- a/lib/language-inference-engine.js +++ b/lib/language-inference-engine.js @@ -196,9 +196,10 @@ var ENGINE_PROFILES = { }, "url": "https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent?key={apikey}", "wrap": function(model, message, temperature) { + const BIAS_MESSAGE = BIAS_MESSAGE return { "contents": [{ - "role": "user", // Changed "developer" to "user" for the initial prompt. The overall prompt is still intended to guide the model, so this is reasonable. + "role": "system", "parts": [{ "text": BIAS_MESSAGE }] @@ -214,7 +215,6 @@ var ENGINE_PROFILES = { }; }, "callback": function(response) { - response = JSON.parse(response) if ("error" in response) { return ["Error: " + response.error.message]; } else { @@ -531,6 +531,14 @@ function LanguageInferenceEngine() { .send() .responseBody; + if(typeof response === 'string'){ + try { + response = JSON.parse(response) + } catch (e) { + return ["Error: Malformed response"]; + } + } + return callback(response); }; } From 452675273b817a5789dfbbf82711b8e130b1bcd0 Mon Sep 17 00:00:00 2001 From: Jihoon Yi <44565599+baramofme@users.noreply.github.com> Date: Sat, 10 May 2025 16:36:53 +0900 Subject: [PATCH 5/8] Update language-inference-engine.js --- lib/language-inference-engine.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/language-inference-engine.js b/lib/language-inference-engine.js index b40340f..1a71080 100644 --- a/lib/language-inference-engine.js +++ b/lib/language-inference-engine.js @@ -196,7 +196,6 @@ var ENGINE_PROFILES = { }, "url": "https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent?key={apikey}", "wrap": function(model, message, temperature) { - const BIAS_MESSAGE = BIAS_MESSAGE return { "contents": [{ "role": "system", @@ -535,7 +534,7 @@ function LanguageInferenceEngine() { try { response = JSON.parse(response) } catch (e) { - return ["Error: Malformed response"]; + return ["Error: Malformed response - " + e.message]; } } From 10606532cb52434a0120941deedb8ca1341a62c6 Mon Sep 17 00:00:00 2001 From: Jihoon Yi <44565599+baramofme@users.noreply.github.com> Date: Sat, 10 May 2025 18:38:45 +0900 Subject: [PATCH 6/8] Update testloader.js Add missing closing brackets in test_implementsobject --- testloader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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:\\"); - }; + }); } }; From 2bff4df4be235913da72fe1928e834d5b7d05f4a Mon Sep 17 00:00:00 2001 From: Jihoon Yi <44565599+baramofme@users.noreply.github.com> Date: Sat, 10 May 2025 20:50:24 +0900 Subject: [PATCH 7/8] Update security.js fix wrong typo --- lib/security.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 90ea515f41a306bf882a76014191bcb3a079fb64 Mon Sep 17 00:00:00 2001 From: Jihoon Yi <44565599+baramofme@users.noreply.github.com> Date: Sat, 10 May 2025 20:51:17 +0900 Subject: [PATCH 8/8] Update winservice.js fix wrong typo --- lib/winservice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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);