Merge pull request #248 from baramofme/master

Fix Gemini llm call
This commit is contained in:
Namhyeon Go 2025-05-12 02:25:56 +09:00 committed by GitHub
commit e1cb460649
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 51 additions and 16 deletions

View File

@ -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;

View File

@ -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);
};
}

View File

@ -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;

View File

@ -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);

View File

@ -1137,7 +1137,7 @@ var test_implements = {
job.setHostName("example.org");
job.setResourceName(resourceName);
job.saveTo("D:\\");
};
});
}
};