Mostly works

This commit is contained in:
2026-05-03 11:13:06 -04:00
parent 6f4519894b
commit 60663b8d4a
21 changed files with 3188 additions and 1706 deletions
+34 -1
View File
@@ -6,6 +6,15 @@ class GeminiProvider {
constructor(config) {
this.config = config;
this.session = null;
this.tools = [];
}
supportsTools() {
return true;
}
setTools(tools) {
this.tools = tools;
}
async start(history) {
@@ -18,7 +27,7 @@ class GeminiProvider {
}
__settings(history) {
return {
const settings = {
generationConfig: {
temperature: this.config.temperature || 1,
topP: this.config.topP || 0.95,
@@ -55,6 +64,19 @@ class GeminiProvider {
},
],
};
// Add tools if configured
if (this.tools && this.tools.length > 0) {
settings.tools = this.tools.map(tool => ({
functionDeclarations: [{
name: tool.name,
description: tool.description,
parameters: tool.parameters
}]
}));
}
return settings;
}
async chat(message, retryCount = 0) {
@@ -65,6 +87,9 @@ class GeminiProvider {
if (retryCount > 3) {
throw new Error(`Gemini API error after ${retryCount} retries: ${error.message}`);
}
const baseDelay = Math.min(1000 * Math.pow(2, retryCount), 30000);
const jitter = Math.random() * 1000;
await new Promise(resolve => setTimeout(resolve, baseDelay + jitter));
// Recover by removing last history entry and restarting
this.session.params.history.pop();
await this.start(this.session.params.history);
@@ -80,6 +105,14 @@ class GeminiProvider {
return result.response.text();
}
getToolCalls(result) {
// Gemini returns function calls in result.response.functionCalls()
if (result.response && typeof result.response.functionCalls === 'function') {
return result.response.functionCalls();
}
return null;
}
async close() {
this.session = null;
}