Update language-inference-engine.js

Fix gemini call broken
This commit is contained in:
Jihoon Yi 2025-05-10 15:50:55 +09:00 committed by GitHub
parent 5f10d50a3c
commit ef23e41e3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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": [
{
"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")