@elizaos/plugin-google-genai 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -1
- package/dist/index.js +331 -267
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Plugin } from '@elizaos/core';
|
|
2
2
|
|
|
3
|
+
interface GoogleGenAIImageDescriptionResult {
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* Defines the Google Generative AI plugin with its name, description, and configuration options.
|
|
5
10
|
* @type {Plugin}
|
|
@@ -13,4 +18,4 @@ import { Plugin } from '@elizaos/core';
|
|
|
13
18
|
*/
|
|
14
19
|
declare const googleGenAIPlugin: Plugin;
|
|
15
20
|
|
|
16
|
-
export { googleGenAIPlugin as default, googleGenAIPlugin };
|
|
21
|
+
export { type GoogleGenAIImageDescriptionResult, googleGenAIPlugin as default, googleGenAIPlugin };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import { logger as logger7, ModelType as ModelType3 } from "@elizaos/core";
|
|
3
|
+
|
|
4
|
+
// src/init.ts
|
|
5
|
+
import { GoogleGenAI as GoogleGenAI2 } from "@google/genai";
|
|
6
|
+
import { logger as logger2 } from "@elizaos/core";
|
|
7
|
+
|
|
8
|
+
// src/utils/config.ts
|
|
2
9
|
import { GoogleGenAI, HarmCategory, HarmBlockThreshold } from "@google/genai";
|
|
3
|
-
import {
|
|
4
|
-
import { fetch } from "undici";
|
|
10
|
+
import { logger } from "@elizaos/core";
|
|
5
11
|
function getSetting(runtime, key, defaultValue) {
|
|
6
12
|
return runtime.getSetting(key) ?? process.env[key] ?? defaultValue;
|
|
7
13
|
}
|
|
@@ -48,6 +54,45 @@ function getSafetySettings() {
|
|
|
48
54
|
}
|
|
49
55
|
];
|
|
50
56
|
}
|
|
57
|
+
|
|
58
|
+
// src/init.ts
|
|
59
|
+
function initializeGoogleGenAI(_config, runtime) {
|
|
60
|
+
void (async () => {
|
|
61
|
+
try {
|
|
62
|
+
const apiKey = getApiKey(runtime);
|
|
63
|
+
if (!apiKey) {
|
|
64
|
+
logger2.warn(
|
|
65
|
+
"GOOGLE_GENERATIVE_AI_API_KEY is not set in environment - Google AI functionality will be limited"
|
|
66
|
+
);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const genAI = new GoogleGenAI2({ apiKey });
|
|
71
|
+
const modelList = await genAI.models.list();
|
|
72
|
+
const models = [];
|
|
73
|
+
for await (const model of modelList) {
|
|
74
|
+
models.push(model);
|
|
75
|
+
}
|
|
76
|
+
logger2.log(`Google AI API key validated successfully. Available models: ${models.length}`);
|
|
77
|
+
} catch (fetchError) {
|
|
78
|
+
const message = fetchError instanceof Error ? fetchError.message : String(fetchError);
|
|
79
|
+
logger2.warn(`Error validating Google AI API key: ${message}`);
|
|
80
|
+
logger2.warn("Google AI functionality will be limited until a valid API key is provided");
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
84
|
+
logger2.warn(
|
|
85
|
+
`Google AI plugin configuration issue: ${message} - You need to configure the GOOGLE_GENERATIVE_AI_API_KEY in your environment variables`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
})();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/models/text.ts
|
|
92
|
+
import { logger as logger3, ModelType } from "@elizaos/core";
|
|
93
|
+
|
|
94
|
+
// src/utils/events.ts
|
|
95
|
+
import { EventType } from "@elizaos/core";
|
|
51
96
|
function emitModelUsageEvent(runtime, type, prompt, usage) {
|
|
52
97
|
runtime.emitEvent(EventType.MODEL_USED, {
|
|
53
98
|
provider: "google",
|
|
@@ -60,9 +105,244 @@ function emitModelUsageEvent(runtime, type, prompt, usage) {
|
|
|
60
105
|
}
|
|
61
106
|
});
|
|
62
107
|
}
|
|
108
|
+
|
|
109
|
+
// src/utils/tokenization.ts
|
|
63
110
|
async function countTokens(text) {
|
|
64
111
|
return Math.ceil(text.length / 4);
|
|
65
112
|
}
|
|
113
|
+
|
|
114
|
+
// src/models/text.ts
|
|
115
|
+
async function handleTextSmall(runtime, {
|
|
116
|
+
prompt,
|
|
117
|
+
stopSequences = [],
|
|
118
|
+
maxTokens = 8192,
|
|
119
|
+
temperature = 0.7,
|
|
120
|
+
frequencyPenalty = 0.7,
|
|
121
|
+
presencePenalty = 0.7
|
|
122
|
+
}) {
|
|
123
|
+
const genAI = createGoogleGenAI(runtime);
|
|
124
|
+
if (!genAI) {
|
|
125
|
+
throw new Error("Google Generative AI client not initialized");
|
|
126
|
+
}
|
|
127
|
+
const modelName = getSmallModel(runtime);
|
|
128
|
+
logger3.log(`[TEXT_SMALL] Using model: ${modelName}`);
|
|
129
|
+
logger3.debug(`[TEXT_SMALL] Prompt: ${prompt}`);
|
|
130
|
+
try {
|
|
131
|
+
const systemInstruction = runtime.character.system || void 0;
|
|
132
|
+
const response = await genAI.models.generateContent({
|
|
133
|
+
model: modelName,
|
|
134
|
+
contents: prompt,
|
|
135
|
+
config: {
|
|
136
|
+
temperature,
|
|
137
|
+
topK: 40,
|
|
138
|
+
topP: 0.95,
|
|
139
|
+
maxOutputTokens: maxTokens,
|
|
140
|
+
stopSequences,
|
|
141
|
+
safetySettings: getSafetySettings(),
|
|
142
|
+
...systemInstruction && { systemInstruction }
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const text = response.text || "";
|
|
146
|
+
const promptTokens = await countTokens(prompt);
|
|
147
|
+
const completionTokens = await countTokens(text);
|
|
148
|
+
emitModelUsageEvent(runtime, ModelType.TEXT_SMALL, prompt, {
|
|
149
|
+
promptTokens,
|
|
150
|
+
completionTokens,
|
|
151
|
+
totalTokens: promptTokens + completionTokens
|
|
152
|
+
});
|
|
153
|
+
return text;
|
|
154
|
+
} catch (error) {
|
|
155
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
156
|
+
logger3.error(`[TEXT_SMALL] Error: ${message}`);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function handleTextLarge(runtime, {
|
|
161
|
+
prompt,
|
|
162
|
+
stopSequences = [],
|
|
163
|
+
maxTokens = 8192,
|
|
164
|
+
temperature = 0.7,
|
|
165
|
+
frequencyPenalty = 0.7,
|
|
166
|
+
presencePenalty = 0.7
|
|
167
|
+
}) {
|
|
168
|
+
const genAI = createGoogleGenAI(runtime);
|
|
169
|
+
if (!genAI) {
|
|
170
|
+
throw new Error("Google Generative AI client not initialized");
|
|
171
|
+
}
|
|
172
|
+
const modelName = getLargeModel(runtime);
|
|
173
|
+
logger3.log(`[TEXT_LARGE] Using model: ${modelName}`);
|
|
174
|
+
logger3.debug(`[TEXT_LARGE] Prompt: ${prompt}`);
|
|
175
|
+
try {
|
|
176
|
+
const systemInstruction = runtime.character.system || void 0;
|
|
177
|
+
const response = await genAI.models.generateContent({
|
|
178
|
+
model: modelName,
|
|
179
|
+
contents: prompt,
|
|
180
|
+
config: {
|
|
181
|
+
temperature,
|
|
182
|
+
topK: 40,
|
|
183
|
+
topP: 0.95,
|
|
184
|
+
maxOutputTokens: maxTokens,
|
|
185
|
+
stopSequences,
|
|
186
|
+
safetySettings: getSafetySettings(),
|
|
187
|
+
...systemInstruction && { systemInstruction }
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
const text = response.text || "";
|
|
191
|
+
const promptTokens = await countTokens(prompt);
|
|
192
|
+
const completionTokens = await countTokens(text);
|
|
193
|
+
emitModelUsageEvent(runtime, ModelType.TEXT_LARGE, prompt, {
|
|
194
|
+
promptTokens,
|
|
195
|
+
completionTokens,
|
|
196
|
+
totalTokens: promptTokens + completionTokens
|
|
197
|
+
});
|
|
198
|
+
return text;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
201
|
+
logger3.error(`[TEXT_LARGE] Error: ${message}`);
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/models/embedding.ts
|
|
207
|
+
import { logger as logger4, ModelType as ModelType2 } from "@elizaos/core";
|
|
208
|
+
async function handleTextEmbedding(runtime, params) {
|
|
209
|
+
const genAI = createGoogleGenAI(runtime);
|
|
210
|
+
if (!genAI) {
|
|
211
|
+
throw new Error("Google Generative AI client not initialized");
|
|
212
|
+
}
|
|
213
|
+
const embeddingModelName = getEmbeddingModel(runtime);
|
|
214
|
+
logger4.debug(`[TEXT_EMBEDDING] Using model: ${embeddingModelName}`);
|
|
215
|
+
if (params === null) {
|
|
216
|
+
logger4.debug("Creating test embedding for initialization");
|
|
217
|
+
const dimension = 768;
|
|
218
|
+
const testVector = Array(dimension).fill(0);
|
|
219
|
+
testVector[0] = 0.1;
|
|
220
|
+
return testVector;
|
|
221
|
+
}
|
|
222
|
+
let text;
|
|
223
|
+
if (typeof params === "string") {
|
|
224
|
+
text = params;
|
|
225
|
+
} else if (typeof params === "object" && params.text) {
|
|
226
|
+
text = params.text;
|
|
227
|
+
} else {
|
|
228
|
+
logger4.warn("Invalid input format for embedding");
|
|
229
|
+
const dimension = 768;
|
|
230
|
+
const fallbackVector = Array(dimension).fill(0);
|
|
231
|
+
fallbackVector[0] = 0.2;
|
|
232
|
+
return fallbackVector;
|
|
233
|
+
}
|
|
234
|
+
if (!text.trim()) {
|
|
235
|
+
logger4.warn("Empty text for embedding");
|
|
236
|
+
const dimension = 768;
|
|
237
|
+
const emptyVector = Array(dimension).fill(0);
|
|
238
|
+
emptyVector[0] = 0.3;
|
|
239
|
+
return emptyVector;
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
const response = await genAI.models.embedContent({
|
|
243
|
+
model: embeddingModelName,
|
|
244
|
+
contents: text
|
|
245
|
+
});
|
|
246
|
+
const embedding = response.embeddings?.[0]?.values || [];
|
|
247
|
+
const promptTokens = await countTokens(text);
|
|
248
|
+
emitModelUsageEvent(runtime, ModelType2.TEXT_EMBEDDING, text, {
|
|
249
|
+
promptTokens,
|
|
250
|
+
completionTokens: 0,
|
|
251
|
+
totalTokens: promptTokens
|
|
252
|
+
});
|
|
253
|
+
logger4.log(`Got embedding with length ${embedding.length}`);
|
|
254
|
+
return embedding;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
257
|
+
logger4.error(`Error generating embedding: ${message}`);
|
|
258
|
+
const dimension = 768;
|
|
259
|
+
const errorVector = Array(dimension).fill(0);
|
|
260
|
+
errorVector[0] = 0.6;
|
|
261
|
+
return errorVector;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// src/models/image.ts
|
|
266
|
+
import { logger as logger5 } from "@elizaos/core";
|
|
267
|
+
import { fetch } from "undici";
|
|
268
|
+
async function handleImageDescription(runtime, params) {
|
|
269
|
+
const genAI = createGoogleGenAI(runtime);
|
|
270
|
+
if (!genAI) {
|
|
271
|
+
throw new Error("Google Generative AI client not initialized");
|
|
272
|
+
}
|
|
273
|
+
let imageUrl;
|
|
274
|
+
let promptText;
|
|
275
|
+
const modelName = getImageModel(runtime);
|
|
276
|
+
logger5.log(`[IMAGE_DESCRIPTION] Using model: ${modelName}`);
|
|
277
|
+
if (typeof params === "string") {
|
|
278
|
+
imageUrl = params;
|
|
279
|
+
promptText = "Please analyze this image and provide a title and detailed description.";
|
|
280
|
+
} else {
|
|
281
|
+
imageUrl = params.imageUrl;
|
|
282
|
+
promptText = params.prompt || "Please analyze this image and provide a title and detailed description.";
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
const imageResponse = await fetch(imageUrl);
|
|
286
|
+
if (!imageResponse.ok) {
|
|
287
|
+
throw new Error(`Failed to fetch image: ${imageResponse.statusText}`);
|
|
288
|
+
}
|
|
289
|
+
const imageData = await imageResponse.arrayBuffer();
|
|
290
|
+
const base64Image = Buffer.from(imageData).toString("base64");
|
|
291
|
+
const contentType = imageResponse.headers.get("content-type") || "image/jpeg";
|
|
292
|
+
const response = await genAI.models.generateContent({
|
|
293
|
+
model: modelName,
|
|
294
|
+
contents: [
|
|
295
|
+
{
|
|
296
|
+
role: "user",
|
|
297
|
+
parts: [
|
|
298
|
+
{ text: promptText },
|
|
299
|
+
{
|
|
300
|
+
inlineData: {
|
|
301
|
+
mimeType: contentType,
|
|
302
|
+
data: base64Image
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
]
|
|
306
|
+
}
|
|
307
|
+
],
|
|
308
|
+
config: {
|
|
309
|
+
temperature: 0.7,
|
|
310
|
+
topK: 40,
|
|
311
|
+
topP: 0.95,
|
|
312
|
+
maxOutputTokens: 8192,
|
|
313
|
+
safetySettings: getSafetySettings()
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
const responseText = response.text || "";
|
|
317
|
+
logger5.log("Received response for image description");
|
|
318
|
+
const isCustomPrompt = typeof params === "object" && params.prompt && params.prompt !== "Please analyze this image and provide a title and detailed description.";
|
|
319
|
+
if (isCustomPrompt) {
|
|
320
|
+
return responseText;
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
const jsonResponse = JSON.parse(responseText);
|
|
324
|
+
if (jsonResponse.title && jsonResponse.description) {
|
|
325
|
+
return jsonResponse;
|
|
326
|
+
}
|
|
327
|
+
} catch (e) {
|
|
328
|
+
logger5.debug(`Parsing as JSON failed, processing as text: ${e}`);
|
|
329
|
+
}
|
|
330
|
+
const titleMatch = responseText.match(/title[:\s]+(.+?)(?:\n|$)/i);
|
|
331
|
+
const title = titleMatch?.[1]?.trim() || "Image Analysis";
|
|
332
|
+
const description = responseText.replace(/title[:\s]+(.+?)(?:\n|$)/i, "").trim();
|
|
333
|
+
return { title, description };
|
|
334
|
+
} catch (error) {
|
|
335
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
336
|
+
logger5.error(`Error analyzing image: ${message}`);
|
|
337
|
+
return {
|
|
338
|
+
title: "Failed to analyze image",
|
|
339
|
+
description: `Error: ${message}`
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/models/object.ts
|
|
345
|
+
import { logger as logger6 } from "@elizaos/core";
|
|
66
346
|
async function generateObjectByModelType(runtime, params, modelType, getModelFn) {
|
|
67
347
|
const genAI = createGoogleGenAI(runtime);
|
|
68
348
|
if (!genAI) {
|
|
@@ -70,7 +350,7 @@ async function generateObjectByModelType(runtime, params, modelType, getModelFn)
|
|
|
70
350
|
}
|
|
71
351
|
const modelName = getModelFn(runtime);
|
|
72
352
|
const temperature = params.temperature ?? 0.1;
|
|
73
|
-
|
|
353
|
+
logger6.info(`Using ${modelType} model: ${modelName}`);
|
|
74
354
|
try {
|
|
75
355
|
let enhancedPrompt = params.prompt;
|
|
76
356
|
if (params.schema) {
|
|
@@ -100,13 +380,17 @@ ${JSON.stringify(params.schema, null, 2)}`;
|
|
|
100
380
|
totalTokens: promptTokens + completionTokens
|
|
101
381
|
});
|
|
102
382
|
try {
|
|
103
|
-
|
|
383
|
+
const parsedResult = JSON.parse(text);
|
|
384
|
+
return parsedResult;
|
|
104
385
|
} catch (parseError) {
|
|
105
|
-
|
|
386
|
+
logger6.error(
|
|
387
|
+
`Failed to parse JSON response: ${parseError instanceof Error ? parseError.message : String(parseError)}`
|
|
388
|
+
);
|
|
106
389
|
const jsonMatch = text.match(/\{[\s\S]*\}/);
|
|
107
390
|
if (jsonMatch) {
|
|
108
391
|
try {
|
|
109
|
-
|
|
392
|
+
const extractedResult = JSON.parse(jsonMatch[0]);
|
|
393
|
+
return extractedResult;
|
|
110
394
|
} catch (secondParseError) {
|
|
111
395
|
throw new Error("Failed to parse JSON from response");
|
|
112
396
|
}
|
|
@@ -115,10 +399,19 @@ ${JSON.stringify(params.schema, null, 2)}`;
|
|
|
115
399
|
}
|
|
116
400
|
} catch (error) {
|
|
117
401
|
const message = error instanceof Error ? error.message : String(error);
|
|
118
|
-
|
|
402
|
+
logger6.error(`[generateObject] Error: ${message}`);
|
|
119
403
|
throw error;
|
|
120
404
|
}
|
|
121
405
|
}
|
|
406
|
+
async function handleObjectSmall(runtime, params) {
|
|
407
|
+
return generateObjectByModelType(runtime, params, "OBJECT_SMALL", getSmallModel);
|
|
408
|
+
}
|
|
409
|
+
async function handleObjectLarge(runtime, params) {
|
|
410
|
+
return generateObjectByModelType(runtime, params, "OBJECT_LARGE", getLargeModel);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// src/index.ts
|
|
414
|
+
import { GoogleGenAI as GoogleGenAI3 } from "@google/genai";
|
|
122
415
|
var googleGenAIPlugin = {
|
|
123
416
|
name: "google-genai",
|
|
124
417
|
description: "Google Generative AI plugin for Gemini models",
|
|
@@ -133,255 +426,26 @@ var googleGenAIPlugin = {
|
|
|
133
426
|
IMAGE_MODEL: process.env.IMAGE_MODEL
|
|
134
427
|
},
|
|
135
428
|
async init(_config, runtime) {
|
|
136
|
-
|
|
137
|
-
const apiKey = getApiKey(runtime);
|
|
138
|
-
if (!apiKey) {
|
|
139
|
-
logger.warn(
|
|
140
|
-
"GOOGLE_GENERATIVE_AI_API_KEY is not set in environment - Google AI functionality will be limited"
|
|
141
|
-
);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
try {
|
|
145
|
-
const genAI = new GoogleGenAI({ apiKey });
|
|
146
|
-
const modelList = await genAI.models.list();
|
|
147
|
-
const models = [];
|
|
148
|
-
for await (const model of modelList) {
|
|
149
|
-
models.push(model);
|
|
150
|
-
}
|
|
151
|
-
logger.log(`Google AI API key validated successfully. Available models: ${models.length}`);
|
|
152
|
-
} catch (fetchError) {
|
|
153
|
-
const message = fetchError instanceof Error ? fetchError.message : String(fetchError);
|
|
154
|
-
logger.warn(`Error validating Google AI API key: ${message}`);
|
|
155
|
-
}
|
|
156
|
-
} catch (error) {
|
|
157
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
158
|
-
logger.warn(
|
|
159
|
-
`Google AI plugin configuration issue: ${message} - You need to configure the GOOGLE_GENERATIVE_AI_API_KEY in your environment variables`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
429
|
+
initializeGoogleGenAI(_config, runtime);
|
|
162
430
|
},
|
|
163
431
|
models: {
|
|
164
|
-
[
|
|
165
|
-
|
|
166
|
-
if (!genAI) {
|
|
167
|
-
throw new Error("Google Generative AI client not initialized");
|
|
168
|
-
}
|
|
169
|
-
const modelName = getSmallModel(runtime);
|
|
170
|
-
const temperature = 0.7;
|
|
171
|
-
const maxOutputTokens = 8192;
|
|
172
|
-
logger.log(`[TEXT_SMALL] Using model: ${modelName}`);
|
|
173
|
-
logger.debug(`[TEXT_SMALL] Prompt: ${prompt}`);
|
|
174
|
-
try {
|
|
175
|
-
const systemInstruction = runtime.character.system || void 0;
|
|
176
|
-
const response = await genAI.models.generateContent({
|
|
177
|
-
model: modelName,
|
|
178
|
-
contents: prompt,
|
|
179
|
-
config: {
|
|
180
|
-
temperature,
|
|
181
|
-
topK: 40,
|
|
182
|
-
topP: 0.95,
|
|
183
|
-
maxOutputTokens,
|
|
184
|
-
stopSequences,
|
|
185
|
-
safetySettings: getSafetySettings(),
|
|
186
|
-
...systemInstruction && { systemInstruction }
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
const text = response.text || "";
|
|
190
|
-
const promptTokens = await countTokens(prompt);
|
|
191
|
-
const completionTokens = await countTokens(text);
|
|
192
|
-
emitModelUsageEvent(runtime, ModelType.TEXT_SMALL, prompt, {
|
|
193
|
-
promptTokens,
|
|
194
|
-
completionTokens,
|
|
195
|
-
totalTokens: promptTokens + completionTokens
|
|
196
|
-
});
|
|
197
|
-
return text;
|
|
198
|
-
} catch (error) {
|
|
199
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
200
|
-
logger.error(`[TEXT_SMALL] Error: ${message}`);
|
|
201
|
-
throw error;
|
|
202
|
-
}
|
|
432
|
+
[ModelType3.TEXT_SMALL]: async (runtime, params) => {
|
|
433
|
+
return handleTextSmall(runtime, params);
|
|
203
434
|
},
|
|
204
|
-
[
|
|
205
|
-
|
|
206
|
-
stopSequences = [],
|
|
207
|
-
maxTokens = 8192,
|
|
208
|
-
temperature = 0.7,
|
|
209
|
-
frequencyPenalty = 0.7,
|
|
210
|
-
presencePenalty = 0.7
|
|
211
|
-
}) => {
|
|
212
|
-
const genAI = createGoogleGenAI(runtime);
|
|
213
|
-
if (!genAI) {
|
|
214
|
-
throw new Error("Google Generative AI client not initialized");
|
|
215
|
-
}
|
|
216
|
-
const modelName = getLargeModel(runtime);
|
|
217
|
-
logger.log(`[TEXT_LARGE] Using model: ${modelName}`);
|
|
218
|
-
logger.debug(`[TEXT_LARGE] Prompt: ${prompt}`);
|
|
219
|
-
try {
|
|
220
|
-
const systemInstruction = runtime.character.system || void 0;
|
|
221
|
-
const response = await genAI.models.generateContent({
|
|
222
|
-
model: modelName,
|
|
223
|
-
contents: prompt,
|
|
224
|
-
config: {
|
|
225
|
-
temperature,
|
|
226
|
-
topK: 40,
|
|
227
|
-
topP: 0.95,
|
|
228
|
-
maxOutputTokens: maxTokens,
|
|
229
|
-
stopSequences,
|
|
230
|
-
safetySettings: getSafetySettings(),
|
|
231
|
-
...systemInstruction && { systemInstruction }
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
const text = response.text || "";
|
|
235
|
-
const promptTokens = await countTokens(prompt);
|
|
236
|
-
const completionTokens = await countTokens(text);
|
|
237
|
-
emitModelUsageEvent(runtime, ModelType.TEXT_LARGE, prompt, {
|
|
238
|
-
promptTokens,
|
|
239
|
-
completionTokens,
|
|
240
|
-
totalTokens: promptTokens + completionTokens
|
|
241
|
-
});
|
|
242
|
-
return text;
|
|
243
|
-
} catch (error) {
|
|
244
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
245
|
-
logger.error(`[TEXT_LARGE] Error: ${message}`);
|
|
246
|
-
throw error;
|
|
247
|
-
}
|
|
435
|
+
[ModelType3.TEXT_LARGE]: async (runtime, params) => {
|
|
436
|
+
return handleTextLarge(runtime, params);
|
|
248
437
|
},
|
|
249
|
-
[
|
|
250
|
-
|
|
251
|
-
if (!genAI) {
|
|
252
|
-
throw new Error("Google Generative AI client not initialized");
|
|
253
|
-
}
|
|
254
|
-
const embeddingModelName = getEmbeddingModel(runtime);
|
|
255
|
-
logger.debug(`[TEXT_EMBEDDING] Using model: ${embeddingModelName}`);
|
|
256
|
-
if (params === null) {
|
|
257
|
-
logger.debug("Creating test embedding for initialization");
|
|
258
|
-
const dimension = 768;
|
|
259
|
-
const testVector = Array(dimension).fill(0);
|
|
260
|
-
testVector[0] = 0.1;
|
|
261
|
-
return testVector;
|
|
262
|
-
}
|
|
263
|
-
let text;
|
|
264
|
-
if (typeof params === "string") {
|
|
265
|
-
text = params;
|
|
266
|
-
} else if (typeof params === "object" && params.text) {
|
|
267
|
-
text = params.text;
|
|
268
|
-
} else {
|
|
269
|
-
logger.warn("Invalid input format for embedding");
|
|
270
|
-
const dimension = 768;
|
|
271
|
-
const fallbackVector = Array(dimension).fill(0);
|
|
272
|
-
fallbackVector[0] = 0.2;
|
|
273
|
-
return fallbackVector;
|
|
274
|
-
}
|
|
275
|
-
if (!text.trim()) {
|
|
276
|
-
logger.warn("Empty text for embedding");
|
|
277
|
-
const dimension = 768;
|
|
278
|
-
const emptyVector = Array(dimension).fill(0);
|
|
279
|
-
emptyVector[0] = 0.3;
|
|
280
|
-
return emptyVector;
|
|
281
|
-
}
|
|
282
|
-
try {
|
|
283
|
-
const response = await genAI.models.embedContent({
|
|
284
|
-
model: embeddingModelName,
|
|
285
|
-
contents: text
|
|
286
|
-
});
|
|
287
|
-
const embedding = response.embeddings?.[0]?.values || [];
|
|
288
|
-
const promptTokens = await countTokens(text);
|
|
289
|
-
emitModelUsageEvent(runtime, ModelType.TEXT_EMBEDDING, text, {
|
|
290
|
-
promptTokens,
|
|
291
|
-
completionTokens: 0,
|
|
292
|
-
totalTokens: promptTokens
|
|
293
|
-
});
|
|
294
|
-
logger.log(`Got embedding with length ${embedding.length}`);
|
|
295
|
-
return embedding;
|
|
296
|
-
} catch (error) {
|
|
297
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
298
|
-
logger.error(`Error generating embedding: ${message}`);
|
|
299
|
-
const dimension = 768;
|
|
300
|
-
const errorVector = Array(dimension).fill(0);
|
|
301
|
-
errorVector[0] = 0.6;
|
|
302
|
-
return errorVector;
|
|
303
|
-
}
|
|
438
|
+
[ModelType3.TEXT_EMBEDDING]: async (runtime, params) => {
|
|
439
|
+
return handleTextEmbedding(runtime, params);
|
|
304
440
|
},
|
|
305
|
-
[
|
|
306
|
-
|
|
307
|
-
if (!genAI) {
|
|
308
|
-
throw new Error("Google Generative AI client not initialized");
|
|
309
|
-
}
|
|
310
|
-
let imageUrl;
|
|
311
|
-
let promptText;
|
|
312
|
-
const modelName = getImageModel(runtime);
|
|
313
|
-
logger.log(`[IMAGE_DESCRIPTION] Using model: ${modelName}`);
|
|
314
|
-
if (typeof params === "string") {
|
|
315
|
-
imageUrl = params;
|
|
316
|
-
promptText = "Please analyze this image and provide a title and detailed description.";
|
|
317
|
-
} else {
|
|
318
|
-
imageUrl = params.imageUrl;
|
|
319
|
-
promptText = params.prompt || "Please analyze this image and provide a title and detailed description.";
|
|
320
|
-
}
|
|
321
|
-
try {
|
|
322
|
-
const imageResponse = await fetch(imageUrl);
|
|
323
|
-
if (!imageResponse.ok) {
|
|
324
|
-
throw new Error(`Failed to fetch image: ${imageResponse.statusText}`);
|
|
325
|
-
}
|
|
326
|
-
const imageData = await imageResponse.arrayBuffer();
|
|
327
|
-
const base64Image = Buffer.from(imageData).toString("base64");
|
|
328
|
-
const contentType = imageResponse.headers.get("content-type") || "image/jpeg";
|
|
329
|
-
const response = await genAI.models.generateContent({
|
|
330
|
-
model: modelName,
|
|
331
|
-
contents: [
|
|
332
|
-
{
|
|
333
|
-
role: "user",
|
|
334
|
-
parts: [
|
|
335
|
-
{ text: promptText },
|
|
336
|
-
{
|
|
337
|
-
inlineData: {
|
|
338
|
-
mimeType: contentType,
|
|
339
|
-
data: base64Image
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
]
|
|
343
|
-
}
|
|
344
|
-
],
|
|
345
|
-
config: {
|
|
346
|
-
temperature: 0.7,
|
|
347
|
-
topK: 40,
|
|
348
|
-
topP: 0.95,
|
|
349
|
-
maxOutputTokens: 8192,
|
|
350
|
-
safetySettings: getSafetySettings()
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
const responseText = response.text || "";
|
|
354
|
-
logger.log("Received response for image description");
|
|
355
|
-
const isCustomPrompt = typeof params === "object" && params.prompt && params.prompt !== "Please analyze this image and provide a title and detailed description.";
|
|
356
|
-
if (isCustomPrompt) {
|
|
357
|
-
return responseText;
|
|
358
|
-
}
|
|
359
|
-
try {
|
|
360
|
-
const jsonResponse = JSON.parse(responseText);
|
|
361
|
-
if (jsonResponse.title && jsonResponse.description) {
|
|
362
|
-
return jsonResponse;
|
|
363
|
-
}
|
|
364
|
-
} catch (e) {
|
|
365
|
-
logger.debug(`Parsing as JSON failed, processing as text: ${e}`);
|
|
366
|
-
}
|
|
367
|
-
const titleMatch = responseText.match(/title[:\s]+(.+?)(?:\n|$)/i);
|
|
368
|
-
const title = titleMatch?.[1]?.trim() || "Image Analysis";
|
|
369
|
-
const description = responseText.replace(/title[:\s]+(.+?)(?:\n|$)/i, "").trim();
|
|
370
|
-
return { title, description };
|
|
371
|
-
} catch (error) {
|
|
372
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
373
|
-
logger.error(`Error analyzing image: ${message}`);
|
|
374
|
-
return {
|
|
375
|
-
title: "Failed to analyze image",
|
|
376
|
-
description: `Error: ${message}`
|
|
377
|
-
};
|
|
378
|
-
}
|
|
441
|
+
[ModelType3.IMAGE_DESCRIPTION]: async (runtime, params) => {
|
|
442
|
+
return handleImageDescription(runtime, params);
|
|
379
443
|
},
|
|
380
|
-
[
|
|
381
|
-
return
|
|
444
|
+
[ModelType3.OBJECT_SMALL]: async (runtime, params) => {
|
|
445
|
+
return handleObjectSmall(runtime, params);
|
|
382
446
|
},
|
|
383
|
-
[
|
|
384
|
-
return
|
|
447
|
+
[ModelType3.OBJECT_LARGE]: async (runtime, params) => {
|
|
448
|
+
return handleObjectLarge(runtime, params);
|
|
385
449
|
}
|
|
386
450
|
},
|
|
387
451
|
tests: [
|
|
@@ -395,29 +459,29 @@ var googleGenAIPlugin = {
|
|
|
395
459
|
if (!apiKey) {
|
|
396
460
|
throw new Error("GOOGLE_GENERATIVE_AI_API_KEY not set");
|
|
397
461
|
}
|
|
398
|
-
const genAI = new
|
|
462
|
+
const genAI = new GoogleGenAI3({ apiKey });
|
|
399
463
|
const modelList = await genAI.models.list();
|
|
400
464
|
const models = [];
|
|
401
465
|
for await (const model of modelList) {
|
|
402
466
|
models.push(model);
|
|
403
467
|
}
|
|
404
|
-
|
|
468
|
+
logger7.log(`Available models: ${models.length}`);
|
|
405
469
|
}
|
|
406
470
|
},
|
|
407
471
|
{
|
|
408
472
|
name: "google_test_text_embedding",
|
|
409
473
|
fn: async (runtime) => {
|
|
410
474
|
try {
|
|
411
|
-
const embedding = await runtime.useModel(
|
|
475
|
+
const embedding = await runtime.useModel(ModelType3.TEXT_EMBEDDING, {
|
|
412
476
|
text: "Hello, world!"
|
|
413
477
|
});
|
|
414
|
-
|
|
478
|
+
logger7.log(`Embedding dimension: ${embedding.length}`);
|
|
415
479
|
if (embedding.length === 0) {
|
|
416
480
|
throw new Error("Failed to generate embedding");
|
|
417
481
|
}
|
|
418
482
|
} catch (error) {
|
|
419
483
|
const message = error instanceof Error ? error.message : String(error);
|
|
420
|
-
|
|
484
|
+
logger7.error(`Error in test_text_embedding: ${message}`);
|
|
421
485
|
throw error;
|
|
422
486
|
}
|
|
423
487
|
}
|
|
@@ -426,16 +490,16 @@ var googleGenAIPlugin = {
|
|
|
426
490
|
name: "google_test_text_small",
|
|
427
491
|
fn: async (runtime) => {
|
|
428
492
|
try {
|
|
429
|
-
const text = await runtime.useModel(
|
|
493
|
+
const text = await runtime.useModel(ModelType3.TEXT_SMALL, {
|
|
430
494
|
prompt: "What is the nature of reality in 10 words?"
|
|
431
495
|
});
|
|
432
496
|
if (text.length === 0) {
|
|
433
497
|
throw new Error("Failed to generate text");
|
|
434
498
|
}
|
|
435
|
-
|
|
499
|
+
logger7.log("Generated with TEXT_SMALL:", text);
|
|
436
500
|
} catch (error) {
|
|
437
501
|
const message = error instanceof Error ? error.message : String(error);
|
|
438
|
-
|
|
502
|
+
logger7.error(`Error in test_text_small: ${message}`);
|
|
439
503
|
throw error;
|
|
440
504
|
}
|
|
441
505
|
}
|
|
@@ -444,16 +508,16 @@ var googleGenAIPlugin = {
|
|
|
444
508
|
name: "google_test_text_large",
|
|
445
509
|
fn: async (runtime) => {
|
|
446
510
|
try {
|
|
447
|
-
const text = await runtime.useModel(
|
|
511
|
+
const text = await runtime.useModel(ModelType3.TEXT_LARGE, {
|
|
448
512
|
prompt: "Explain quantum mechanics in simple terms."
|
|
449
513
|
});
|
|
450
514
|
if (text.length === 0) {
|
|
451
515
|
throw new Error("Failed to generate text");
|
|
452
516
|
}
|
|
453
|
-
|
|
517
|
+
logger7.log("Generated with TEXT_LARGE:", text.substring(0, 100) + "...");
|
|
454
518
|
} catch (error) {
|
|
455
519
|
const message = error instanceof Error ? error.message : String(error);
|
|
456
|
-
|
|
520
|
+
logger7.error(`Error in test_text_large: ${message}`);
|
|
457
521
|
throw error;
|
|
458
522
|
}
|
|
459
523
|
}
|
|
@@ -463,17 +527,17 @@ var googleGenAIPlugin = {
|
|
|
463
527
|
fn: async (runtime) => {
|
|
464
528
|
try {
|
|
465
529
|
const result = await runtime.useModel(
|
|
466
|
-
|
|
530
|
+
ModelType3.IMAGE_DESCRIPTION,
|
|
467
531
|
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg/537px-Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg"
|
|
468
532
|
);
|
|
469
533
|
if (result && typeof result === "object" && "title" in result && "description" in result) {
|
|
470
|
-
|
|
534
|
+
logger7.log("Image description:", JSON.stringify(result));
|
|
471
535
|
} else {
|
|
472
|
-
|
|
536
|
+
logger7.error("Invalid image description result format:", result);
|
|
473
537
|
}
|
|
474
538
|
} catch (error) {
|
|
475
539
|
const message = error instanceof Error ? error.message : String(error);
|
|
476
|
-
|
|
540
|
+
logger7.error(`Error in test_image_description: ${message}`);
|
|
477
541
|
throw error;
|
|
478
542
|
}
|
|
479
543
|
}
|
|
@@ -491,17 +555,17 @@ var googleGenAIPlugin = {
|
|
|
491
555
|
},
|
|
492
556
|
required: ["name", "age", "hobbies"]
|
|
493
557
|
};
|
|
494
|
-
const result = await runtime.useModel(
|
|
558
|
+
const result = await runtime.useModel(ModelType3.OBJECT_SMALL, {
|
|
495
559
|
prompt: "Generate a person profile with name, age, and hobbies.",
|
|
496
560
|
schema
|
|
497
561
|
});
|
|
498
|
-
|
|
562
|
+
logger7.log("Generated object:", result);
|
|
499
563
|
if (!result.name || !result.age || !result.hobbies) {
|
|
500
564
|
throw new Error("Generated object missing required fields");
|
|
501
565
|
}
|
|
502
566
|
} catch (error) {
|
|
503
567
|
const message = error instanceof Error ? error.message : String(error);
|
|
504
|
-
|
|
568
|
+
logger7.error(`Error in test_object_generation: ${message}`);
|
|
505
569
|
throw error;
|
|
506
570
|
}
|
|
507
571
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { GoogleGenAI, HarmCategory, HarmBlockThreshold } from '@google/genai';\nimport type {\n IAgentRuntime,\n ModelTypeName,\n ObjectGenerationParams,\n Plugin,\n GenerateTextParams,\n ImageDescriptionParams,\n TextEmbeddingParams,\n} from '@elizaos/core';\nimport { EventType, logger, ModelType } from '@elizaos/core';\nimport { fetch } from 'undici';\n\n/**\n * Retrieves a configuration setting from the runtime, falling back to environment variables or a default value if not found.\n *\n * @param key - The name of the setting to retrieve.\n * @param defaultValue - The value to return if the setting is not found in the runtime or environment.\n * @returns The resolved setting value, or {@link defaultValue} if not found.\n */\nfunction getSetting(\n runtime: IAgentRuntime,\n key: string,\n defaultValue?: string\n): string | undefined {\n return runtime.getSetting(key) ?? process.env[key] ?? defaultValue;\n}\n\n/**\n * Helper function to get the API key for Google AI\n *\n * @param runtime The runtime context\n * @returns The configured API key\n */\nfunction getApiKey(runtime: IAgentRuntime): string | undefined {\n return getSetting(runtime, 'GOOGLE_GENERATIVE_AI_API_KEY');\n}\n\n/**\n * Helper function to get the small model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured small model name\n */\nfunction getSmallModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, 'GOOGLE_SMALL_MODEL') ??\n getSetting(runtime, 'SMALL_MODEL', 'gemini-2.0-flash-001') ??\n 'gemini-2.0-flash-001'\n );\n}\n\n/**\n * Helper function to get the large model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured large model name\n */\nfunction getLargeModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, 'GOOGLE_LARGE_MODEL') ??\n getSetting(runtime, 'LARGE_MODEL', 'gemini-2.5-pro-preview-03-25') ??\n 'gemini-2.5-pro-preview-03-25'\n );\n}\n\n/**\n * Helper function to get the image model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured image model name\n */\nfunction getImageModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, 'GOOGLE_IMAGE_MODEL') ??\n getSetting(runtime, 'IMAGE_MODEL', 'gemini-2.5-pro-preview-03-25') ??\n 'gemini-2.5-pro-preview-03-25'\n );\n}\n\n/**\n * Helper function to get the embedding model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured embedding model name\n */\nfunction getEmbeddingModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, 'GOOGLE_EMBEDDING_MODEL', 'text-embedding-004') ?? 'text-embedding-004'\n );\n}\n\n/**\n * Create a Google Generative AI client instance with proper configuration\n *\n * @param runtime The runtime context\n * @returns Configured Google Generative AI instance\n */\nfunction createGoogleGenAI(runtime: IAgentRuntime): GoogleGenAI | null {\n const apiKey = getApiKey(runtime);\n if (!apiKey) {\n logger.error('Google Generative AI API Key is missing');\n return null;\n }\n\n return new GoogleGenAI({ apiKey });\n}\n\n/**\n * Convert safety settings to Google format\n */\nfunction getSafetySettings() {\n return [\n {\n category: HarmCategory.HARM_CATEGORY_HARASSMENT,\n threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,\n },\n {\n category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,\n threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,\n },\n {\n category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,\n threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,\n },\n {\n category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,\n threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,\n },\n ];\n}\n\n/**\n * Emits a model usage event\n * @param runtime The runtime context\n * @param type The model type\n * @param prompt The prompt used\n * @param usage The usage data\n */\nfunction emitModelUsageEvent(\n runtime: IAgentRuntime,\n type: ModelTypeName,\n prompt: string,\n usage: { promptTokens: number; completionTokens: number; totalTokens: number }\n) {\n runtime.emitEvent(EventType.MODEL_USED, {\n provider: 'google',\n type,\n prompt,\n tokens: {\n prompt: usage.promptTokens,\n completion: usage.completionTokens,\n total: usage.totalTokens,\n },\n });\n}\n\n/**\n * Helper function to count tokens for a given text (estimation)\n */\nasync function countTokens(text: string): Promise<number> {\n // Rough estimation: ~1 token per 4 characters\n return Math.ceil(text.length / 4);\n}\n\n/**\n * Helper function to generate objects using specified model type\n */\nasync function generateObjectByModelType(\n runtime: IAgentRuntime,\n params: ObjectGenerationParams,\n modelType: string,\n getModelFn: (runtime: IAgentRuntime) => string\n): Promise<any> {\n const genAI = createGoogleGenAI(runtime);\n if (!genAI) {\n throw new Error('Google Generative AI client not initialized');\n }\n\n const modelName = getModelFn(runtime);\n const temperature = params.temperature ?? 0.1;\n\n logger.info(`Using ${modelType} model: ${modelName}`);\n\n try {\n // Add schema instructions to prompt if provided\n let enhancedPrompt = params.prompt;\n if (params.schema) {\n enhancedPrompt += `\\n\\nPlease respond with a JSON object that follows this schema:\\n${JSON.stringify(params.schema, null, 2)}`;\n }\n\n const response = await genAI.models.generateContent({\n model: modelName,\n contents: enhancedPrompt,\n config: {\n temperature,\n topK: 40,\n topP: 0.95,\n maxOutputTokens: 8192,\n responseMimeType: 'application/json',\n safetySettings: getSafetySettings(),\n },\n });\n\n const text = response.text || '';\n\n // Count tokens for usage tracking\n const promptTokens = await countTokens(enhancedPrompt);\n const completionTokens = await countTokens(text);\n\n emitModelUsageEvent(runtime, modelType as ModelTypeName, params.prompt, {\n promptTokens,\n completionTokens,\n totalTokens: promptTokens + completionTokens,\n });\n\n try {\n return JSON.parse(text);\n } catch (parseError) {\n logger.error('Failed to parse JSON response:', parseError);\n // Try to extract JSON from the response\n const jsonMatch = text.match(/\\{[\\s\\S]*\\}/);\n if (jsonMatch) {\n try {\n return JSON.parse(jsonMatch[0]);\n } catch (secondParseError) {\n throw new Error('Failed to parse JSON from response');\n }\n }\n throw parseError;\n }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`[generateObject] Error: ${message}`);\n throw error;\n }\n}\n\n/**\n * Defines the Google Generative AI plugin with its name, description, and configuration options.\n * @type {Plugin}\n *\n * Available models as of March 2025:\n * - gemini-2.0-flash-001: Fast, efficient model for everyday tasks\n * - gemini-2.5-pro-exp-03-25: Latest experimental model with advanced reasoning (March 25, 2025)\n * - gemini-2.5-pro-preview-05-06: Preview version from Google I/O 2025\n * - gemini-2.5-pro: General model name for Gemini 2.5 Pro\n * - text-embedding-004: For text embeddings\n */\nexport const googleGenAIPlugin: Plugin = {\n name: 'google-genai',\n description: 'Google Generative AI plugin for Gemini models',\n config: {\n GOOGLE_GENERATIVE_AI_API_KEY: process.env.GOOGLE_GENERATIVE_AI_API_KEY,\n GOOGLE_SMALL_MODEL: process.env.GOOGLE_SMALL_MODEL,\n GOOGLE_LARGE_MODEL: process.env.GOOGLE_LARGE_MODEL,\n GOOGLE_IMAGE_MODEL: process.env.GOOGLE_IMAGE_MODEL,\n GOOGLE_EMBEDDING_MODEL: process.env.GOOGLE_EMBEDDING_MODEL,\n SMALL_MODEL: process.env.SMALL_MODEL,\n LARGE_MODEL: process.env.LARGE_MODEL,\n IMAGE_MODEL: process.env.IMAGE_MODEL,\n },\n async init(_config, runtime) {\n try {\n const apiKey = getApiKey(runtime);\n if (!apiKey) {\n logger.warn(\n 'GOOGLE_GENERATIVE_AI_API_KEY is not set in environment - Google AI functionality will be limited'\n );\n return;\n }\n\n // Test the API key by listing models\n try {\n const genAI = new GoogleGenAI({ apiKey });\n const modelList = await genAI.models.list();\n const models = [];\n for await (const model of modelList) {\n models.push(model);\n }\n logger.log(`Google AI API key validated successfully. Available models: ${models.length}`);\n } catch (fetchError: unknown) {\n const message = fetchError instanceof Error ? fetchError.message : String(fetchError);\n logger.warn(`Error validating Google AI API key: ${message}`);\n }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.warn(\n `Google AI plugin configuration issue: ${message} - You need to configure the GOOGLE_GENERATIVE_AI_API_KEY in your environment variables`\n );\n }\n },\n models: {\n [ModelType.TEXT_SMALL]: async (\n runtime: IAgentRuntime,\n { prompt, stopSequences = [] }: GenerateTextParams\n ) => {\n const genAI = createGoogleGenAI(runtime);\n if (!genAI) {\n throw new Error('Google Generative AI client not initialized');\n }\n\n const modelName = getSmallModel(runtime);\n const temperature = 0.7;\n const maxOutputTokens = 8192;\n\n logger.log(`[TEXT_SMALL] Using model: ${modelName}`);\n logger.debug(`[TEXT_SMALL] Prompt: ${prompt}`);\n\n try {\n const systemInstruction = runtime.character.system || undefined;\n const response = await genAI.models.generateContent({\n model: modelName,\n contents: prompt,\n config: {\n temperature,\n topK: 40,\n topP: 0.95,\n maxOutputTokens,\n stopSequences,\n safetySettings: getSafetySettings(),\n ...(systemInstruction && { systemInstruction }),\n },\n });\n\n const text = response.text || '';\n\n // Count tokens for usage tracking\n const promptTokens = await countTokens(prompt);\n const completionTokens = await countTokens(text);\n\n emitModelUsageEvent(runtime, ModelType.TEXT_SMALL, prompt, {\n promptTokens,\n completionTokens,\n totalTokens: promptTokens + completionTokens,\n });\n\n return text;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`[TEXT_SMALL] Error: ${message}`);\n throw error;\n }\n },\n [ModelType.TEXT_LARGE]: async (\n runtime: IAgentRuntime,\n {\n prompt,\n stopSequences = [],\n maxTokens = 8192,\n temperature = 0.7,\n frequencyPenalty = 0.7,\n presencePenalty = 0.7,\n }: GenerateTextParams\n ) => {\n const genAI = createGoogleGenAI(runtime);\n if (!genAI) {\n throw new Error('Google Generative AI client not initialized');\n }\n\n const modelName = getLargeModel(runtime);\n\n logger.log(`[TEXT_LARGE] Using model: ${modelName}`);\n logger.debug(`[TEXT_LARGE] Prompt: ${prompt}`);\n\n try {\n const systemInstruction = runtime.character.system || undefined;\n const response = await genAI.models.generateContent({\n model: modelName,\n contents: prompt,\n config: {\n temperature,\n topK: 40,\n topP: 0.95,\n maxOutputTokens: maxTokens,\n stopSequences,\n safetySettings: getSafetySettings(),\n ...(systemInstruction && { systemInstruction }),\n },\n });\n\n const text = response.text || '';\n\n // Count tokens for usage tracking\n const promptTokens = await countTokens(prompt);\n const completionTokens = await countTokens(text);\n\n emitModelUsageEvent(runtime, ModelType.TEXT_LARGE, prompt, {\n promptTokens,\n completionTokens,\n totalTokens: promptTokens + completionTokens,\n });\n\n return text;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`[TEXT_LARGE] Error: ${message}`);\n throw error;\n }\n },\n [ModelType.TEXT_EMBEDDING]: async (\n runtime: IAgentRuntime,\n params: TextEmbeddingParams | string | null\n ): Promise<number[]> => {\n const genAI = createGoogleGenAI(runtime);\n if (!genAI) {\n throw new Error('Google Generative AI client not initialized');\n }\n\n const embeddingModelName = getEmbeddingModel(runtime);\n logger.debug(`[TEXT_EMBEDDING] Using model: ${embeddingModelName}`);\n\n // Handle null case for initialization\n if (params === null) {\n logger.debug('Creating test embedding for initialization');\n // Return 768-dimensional vector for text-embedding-004\n const dimension = 768;\n const testVector = Array(dimension).fill(0);\n testVector[0] = 0.1;\n return testVector;\n }\n\n // Extract text from params\n let text: string;\n if (typeof params === 'string') {\n text = params;\n } else if (typeof params === 'object' && params.text) {\n text = params.text;\n } else {\n logger.warn('Invalid input format for embedding');\n const dimension = 768;\n const fallbackVector = Array(dimension).fill(0);\n fallbackVector[0] = 0.2;\n return fallbackVector;\n }\n\n if (!text.trim()) {\n logger.warn('Empty text for embedding');\n const dimension = 768;\n const emptyVector = Array(dimension).fill(0);\n emptyVector[0] = 0.3;\n return emptyVector;\n }\n\n try {\n const response = await genAI.models.embedContent({\n model: embeddingModelName,\n contents: text,\n });\n\n const embedding = response.embeddings?.[0]?.values || [];\n\n // Count tokens for usage tracking\n const promptTokens = await countTokens(text);\n\n emitModelUsageEvent(runtime, ModelType.TEXT_EMBEDDING, text, {\n promptTokens,\n completionTokens: 0,\n totalTokens: promptTokens,\n });\n\n logger.log(`Got embedding with length ${embedding.length}`);\n return embedding;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error generating embedding: ${message}`);\n // Return error vector\n const dimension = 768;\n const errorVector = Array(dimension).fill(0);\n errorVector[0] = 0.6;\n return errorVector;\n }\n },\n [ModelType.IMAGE_DESCRIPTION]: async (\n runtime: IAgentRuntime,\n params: ImageDescriptionParams | string\n ) => {\n const genAI = createGoogleGenAI(runtime);\n if (!genAI) {\n throw new Error('Google Generative AI client not initialized');\n }\n\n let imageUrl: string;\n let promptText: string | undefined;\n const modelName = getImageModel(runtime);\n logger.log(`[IMAGE_DESCRIPTION] Using model: ${modelName}`);\n\n if (typeof params === 'string') {\n imageUrl = params;\n promptText = 'Please analyze this image and provide a title and detailed description.';\n } else {\n imageUrl = params.imageUrl;\n promptText =\n params.prompt ||\n 'Please analyze this image and provide a title and detailed description.';\n }\n\n try {\n // Fetch image data\n const imageResponse = await fetch(imageUrl);\n if (!imageResponse.ok) {\n throw new Error(`Failed to fetch image: ${imageResponse.statusText}`);\n }\n\n const imageData = await imageResponse.arrayBuffer();\n const base64Image = Buffer.from(imageData).toString('base64');\n\n // Determine MIME type from URL or response headers\n const contentType = imageResponse.headers.get('content-type') || 'image/jpeg';\n\n const response = await genAI.models.generateContent({\n model: modelName,\n contents: [\n {\n role: 'user',\n parts: [\n { text: promptText },\n {\n inlineData: {\n mimeType: contentType,\n data: base64Image,\n },\n },\n ],\n },\n ],\n config: {\n temperature: 0.7,\n topK: 40,\n topP: 0.95,\n maxOutputTokens: 8192,\n safetySettings: getSafetySettings(),\n },\n });\n\n const responseText = response.text || '';\n\n logger.log('Received response for image description');\n\n // Check if a custom prompt was provided\n const isCustomPrompt =\n typeof params === 'object' &&\n params.prompt &&\n params.prompt !==\n 'Please analyze this image and provide a title and detailed description.';\n\n // If custom prompt is used, return the raw content\n if (isCustomPrompt) {\n return responseText;\n }\n\n // Try to parse the response as JSON first\n try {\n const jsonResponse = JSON.parse(responseText);\n if (jsonResponse.title && jsonResponse.description) {\n return jsonResponse;\n }\n } catch (e) {\n // If not valid JSON, process as text\n logger.debug(`Parsing as JSON failed, processing as text: ${e}`);\n }\n\n // Extract title and description from text format\n const titleMatch = responseText.match(/title[:\\s]+(.+?)(?:\\n|$)/i);\n const title = titleMatch?.[1]?.trim() || 'Image Analysis';\n const description = responseText.replace(/title[:\\s]+(.+?)(?:\\n|$)/i, '').trim();\n\n return { title, description };\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error analyzing image: ${message}`);\n return {\n title: 'Failed to analyze image',\n description: `Error: ${message}`,\n };\n }\n },\n [ModelType.OBJECT_SMALL]: async (runtime: IAgentRuntime, params: ObjectGenerationParams) => {\n return generateObjectByModelType(runtime, params, ModelType.OBJECT_SMALL, getSmallModel);\n },\n [ModelType.OBJECT_LARGE]: async (runtime: IAgentRuntime, params: ObjectGenerationParams) => {\n return generateObjectByModelType(runtime, params, ModelType.OBJECT_LARGE, getLargeModel);\n },\n },\n tests: [\n {\n name: 'google_genai_plugin_tests',\n tests: [\n {\n name: 'google_test_api_key_validation',\n fn: async (runtime: IAgentRuntime) => {\n const apiKey = getApiKey(runtime);\n if (!apiKey) {\n throw new Error('GOOGLE_GENERATIVE_AI_API_KEY not set');\n }\n const genAI = new GoogleGenAI({ apiKey });\n const modelList = await genAI.models.list();\n const models = [];\n for await (const model of modelList) {\n models.push(model);\n }\n logger.log('Available models:', models.length);\n },\n },\n {\n name: 'google_test_text_embedding',\n fn: async (runtime: IAgentRuntime) => {\n try {\n const embedding = await runtime.useModel(ModelType.TEXT_EMBEDDING, {\n text: 'Hello, world!',\n });\n logger.log('Embedding dimension:', embedding.length);\n if (embedding.length === 0) {\n throw new Error('Failed to generate embedding');\n }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_text_embedding: ${message}`);\n throw error;\n }\n },\n },\n {\n name: 'google_test_text_small',\n fn: async (runtime: IAgentRuntime) => {\n try {\n const text = await runtime.useModel(ModelType.TEXT_SMALL, {\n prompt: 'What is the nature of reality in 10 words?',\n });\n if (text.length === 0) {\n throw new Error('Failed to generate text');\n }\n logger.log('Generated with TEXT_SMALL:', text);\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_text_small: ${message}`);\n throw error;\n }\n },\n },\n {\n name: 'google_test_text_large',\n fn: async (runtime: IAgentRuntime) => {\n try {\n const text = await runtime.useModel(ModelType.TEXT_LARGE, {\n prompt: 'Explain quantum mechanics in simple terms.',\n });\n if (text.length === 0) {\n throw new Error('Failed to generate text');\n }\n logger.log('Generated with TEXT_LARGE:', text.substring(0, 100) + '...');\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_text_large: ${message}`);\n throw error;\n }\n },\n },\n {\n name: 'google_test_image_description',\n fn: async (runtime: IAgentRuntime) => {\n try {\n const result = await runtime.useModel(\n ModelType.IMAGE_DESCRIPTION,\n 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg/537px-Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg'\n );\n\n if (\n result &&\n typeof result === 'object' &&\n 'title' in result &&\n 'description' in result\n ) {\n logger.log('Image description:', result);\n } else {\n logger.error('Invalid image description result format:', result);\n }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_image_description: ${message}`);\n throw error;\n }\n },\n },\n {\n name: 'google_test_object_generation',\n fn: async (runtime: IAgentRuntime) => {\n try {\n const schema = {\n type: 'object',\n properties: {\n name: { type: 'string' },\n age: { type: 'number' },\n hobbies: { type: 'array', items: { type: 'string' } },\n },\n required: ['name', 'age', 'hobbies'],\n };\n\n const result = await runtime.useModel(ModelType.OBJECT_SMALL, {\n prompt: 'Generate a person profile with name, age, and hobbies.',\n schema,\n });\n\n logger.log('Generated object:', result);\n\n if (!result.name || !result.age || !result.hobbies) {\n throw new Error('Generated object missing required fields');\n }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_object_generation: ${message}`);\n throw error;\n }\n },\n },\n ],\n },\n ],\n};\n\nexport default googleGenAIPlugin;\n"],"mappings":";AAAA,SAAS,aAAa,cAAc,0BAA0B;AAU9D,SAAS,WAAW,QAAQ,iBAAiB;AAC7C,SAAS,aAAa;AAStB,SAAS,WACP,SACA,KACA,cACoB;AACpB,SAAO,QAAQ,WAAW,GAAG,KAAK,Q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AC1D,oBAAM;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/init.ts","../src/utils/config.ts","../src/models/text.ts","../src/utils/events.ts","../src/utils/tokenization.ts","../src/models/embedding.ts","../src/models/image.ts","../src/models/object.ts"],"sourcesContent":["import type {\n IAgentRuntime,\n Plugin,\n GenerateTextParams,\n ImageDescriptionParams,\n TextEmbeddingParams,\n ObjectGenerationParams,\n} from '@elizaos/core';\nimport { logger, ModelType } from '@elizaos/core';\nimport { initializeGoogleGenAI } from './init';\nimport {\n handleTextSmall,\n handleTextLarge,\n handleTextEmbedding,\n handleImageDescription,\n handleObjectSmall,\n handleObjectLarge,\n} from './models';\nimport { getApiKey } from './utils/config';\nimport { GoogleGenAI } from '@google/genai';\n\nexport * from './types';\n\n/**\n * Defines the Google Generative AI plugin with its name, description, and configuration options.\n * @type {Plugin}\n *\n * Available models as of March 2025:\n * - gemini-2.0-flash-001: Fast, efficient model for everyday tasks\n * - gemini-2.5-pro-exp-03-25: Latest experimental model with advanced reasoning (March 25, 2025)\n * - gemini-2.5-pro-preview-05-06: Preview version from Google I/O 2025\n * - gemini-2.5-pro: General model name for Gemini 2.5 Pro\n * - text-embedding-004: For text embeddings\n */\nexport const googleGenAIPlugin: Plugin = {\n name: 'google-genai',\n description: 'Google Generative AI plugin for Gemini models',\n config: {\n GOOGLE_GENERATIVE_AI_API_KEY: process.env.GOOGLE_GENERATIVE_AI_API_KEY,\n GOOGLE_SMALL_MODEL: process.env.GOOGLE_SMALL_MODEL,\n GOOGLE_LARGE_MODEL: process.env.GOOGLE_LARGE_MODEL,\n GOOGLE_IMAGE_MODEL: process.env.GOOGLE_IMAGE_MODEL,\n GOOGLE_EMBEDDING_MODEL: process.env.GOOGLE_EMBEDDING_MODEL,\n SMALL_MODEL: process.env.SMALL_MODEL,\n LARGE_MODEL: process.env.LARGE_MODEL,\n IMAGE_MODEL: process.env.IMAGE_MODEL,\n },\n async init(_config, runtime) {\n // Note: We intentionally don't await here because ElizaOS expects\n // the init method to return quickly. The initializeGoogleGenAI function\n // performs background validation and logging.\n initializeGoogleGenAI(_config, runtime);\n },\n models: {\n [ModelType.TEXT_SMALL]: async (runtime: IAgentRuntime, params: GenerateTextParams) => {\n return handleTextSmall(runtime, params);\n },\n [ModelType.TEXT_LARGE]: async (runtime: IAgentRuntime, params: GenerateTextParams) => {\n return handleTextLarge(runtime, params);\n },\n [ModelType.TEXT_EMBEDDING]: async (\n runtime: IAgentRuntime,\n params: TextEmbeddingParams | string | null\n ) => {\n return handleTextEmbedding(runtime, params);\n },\n [ModelType.IMAGE_DESCRIPTION]: async (\n runtime: IAgentRuntime,\n params: ImageDescriptionParams | string\n ) => {\n return handleImageDescription(runtime, params);\n },\n [ModelType.OBJECT_SMALL]: async (runtime: IAgentRuntime, params: ObjectGenerationParams) => {\n return handleObjectSmall(runtime, params);\n },\n [ModelType.OBJECT_LARGE]: async (runtime: IAgentRuntime, params: ObjectGenerationParams) => {\n return handleObjectLarge(runtime, params);\n },\n },\n tests: [\n {\n name: 'google_genai_plugin_tests',\n tests: [\n {\n name: 'google_test_api_key_validation',\n fn: async (runtime: IAgentRuntime) => {\n const apiKey = getApiKey(runtime);\n if (!apiKey) {\n throw new Error('GOOGLE_GENERATIVE_AI_API_KEY not set');\n }\n const genAI = new GoogleGenAI({ apiKey });\n const modelList = await genAI.models.list();\n const models = [];\n for await (const model of modelList) {\n models.push(model);\n }\n logger.log(`Available models: ${models.length}`);\n },\n },\n {\n name: 'google_test_text_embedding',\n fn: async (runtime: IAgentRuntime) => {\n try {\n const embedding = await runtime.useModel(ModelType.TEXT_EMBEDDING, {\n text: 'Hello, world!',\n });\n logger.log(`Embedding dimension: ${embedding.length}`);\n if (embedding.length === 0) {\n throw new Error('Failed to generate embedding');\n }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_text_embedding: ${message}`);\n throw error;\n }\n },\n },\n {\n name: 'google_test_text_small',\n fn: async (runtime: IAgentRuntime) => {\n try {\n const text = await runtime.useModel(ModelType.TEXT_SMALL, {\n prompt: 'What is the nature of reality in 10 words?',\n });\n if (text.length === 0) {\n throw new Error('Failed to generate text');\n }\n logger.log('Generated with TEXT_SMALL:', text);\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_text_small: ${message}`);\n throw error;\n }\n },\n },\n {\n name: 'google_test_text_large',\n fn: async (runtime: IAgentRuntime) => {\n try {\n const text = await runtime.useModel(ModelType.TEXT_LARGE, {\n prompt: 'Explain quantum mechanics in simple terms.',\n });\n if (text.length === 0) {\n throw new Error('Failed to generate text');\n }\n logger.log('Generated with TEXT_LARGE:', text.substring(0, 100) + '...');\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_text_large: ${message}`);\n throw error;\n }\n },\n },\n {\n name: 'google_test_image_description',\n fn: async (runtime: IAgentRuntime) => {\n try {\n const result = await runtime.useModel(\n ModelType.IMAGE_DESCRIPTION,\n 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg/537px-Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg'\n );\n\n if (\n result &&\n typeof result === 'object' &&\n 'title' in result &&\n 'description' in result\n ) {\n logger.log('Image description:', JSON.stringify(result));\n } else {\n logger.error('Invalid image description result format:', result);\n }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_image_description: ${message}`);\n throw error;\n }\n },\n },\n {\n name: 'google_test_object_generation',\n fn: async (runtime: IAgentRuntime) => {\n try {\n const schema = {\n type: 'object',\n properties: {\n name: { type: 'string' },\n age: { type: 'number' },\n hobbies: { type: 'array', items: { type: 'string' } },\n },\n required: ['name', 'age', 'hobbies'],\n };\n\n const result = await runtime.useModel(ModelType.OBJECT_SMALL, {\n prompt: 'Generate a person profile with name, age, and hobbies.',\n schema,\n });\n\n logger.log('Generated object:', result);\n\n if (!result.name || !result.age || !result.hobbies) {\n throw new Error('Generated object missing required fields');\n }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_object_generation: ${message}`);\n throw error;\n }\n },\n },\n ],\n },\n ],\n};\n\nexport default googleGenAIPlugin;\n","import { GoogleGenAI } from '@google/genai';\nimport { logger, type IAgentRuntime } from '@elizaos/core';\nimport { getApiKey } from './utils/config';\n\n/**\n * Initialize and validate Google Generative AI configuration\n */\nexport function initializeGoogleGenAI(_config: any, runtime: IAgentRuntime) {\n // Run validation in the background without blocking initialization\n void (async () => {\n try {\n const apiKey = getApiKey(runtime);\n if (!apiKey) {\n logger.warn(\n 'GOOGLE_GENERATIVE_AI_API_KEY is not set in environment - Google AI functionality will be limited'\n );\n return;\n }\n\n // Test the API key by listing models\n try {\n const genAI = new GoogleGenAI({ apiKey });\n const modelList = await genAI.models.list();\n const models = [];\n for await (const model of modelList) {\n models.push(model);\n }\n logger.log(`Google AI API key validated successfully. Available models: ${models.length}`);\n } catch (fetchError: unknown) {\n const message = fetchError instanceof Error ? fetchError.message : String(fetchError);\n logger.warn(`Error validating Google AI API key: ${message}`);\n logger.warn('Google AI functionality will be limited until a valid API key is provided');\n }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.warn(\n `Google AI plugin configuration issue: ${message} - You need to configure the GOOGLE_GENERATIVE_AI_API_KEY in your environment variables`\n );\n }\n })();\n}\n","import { GoogleGenAI, HarmCategory, HarmBlockThreshold } from '@google/genai';\nimport type { IAgentRuntime } from '@elizaos/core';\nimport { logger } from '@elizaos/core';\n\n/**\n * Retrieves a configuration setting from the runtime, falling back to environment variables or a default value if not found.\n *\n * @param key - The name of the setting to retrieve.\n * @param defaultValue - The value to return if the setting is not found in the runtime or environment.\n * @returns The resolved setting value, or {@link defaultValue} if not found.\n */\nexport function getSetting(\n runtime: IAgentRuntime,\n key: string,\n defaultValue?: string\n): string | undefined {\n return runtime.getSetting(key) ?? process.env[key] ?? defaultValue;\n}\n\n/**\n * Helper function to get the API key for Google AI\n *\n * @param runtime The runtime context\n * @returns The configured API key\n */\nexport function getApiKey(runtime: IAgentRuntime): string | undefined {\n return getSetting(runtime, 'GOOGLE_GENERATIVE_AI_API_KEY');\n}\n\n/**\n * Helper function to get the small model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured small model name\n */\nexport function getSmallModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, 'GOOGLE_SMALL_MODEL') ??\n getSetting(runtime, 'SMALL_MODEL', 'gemini-2.0-flash-001') ??\n 'gemini-2.0-flash-001'\n );\n}\n\n/**\n * Helper function to get the large model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured large model name\n */\nexport function getLargeModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, 'GOOGLE_LARGE_MODEL') ??\n getSetting(runtime, 'LARGE_MODEL', 'gemini-2.5-pro-preview-03-25') ??\n 'gemini-2.5-pro-preview-03-25'\n );\n}\n\n/**\n * Helper function to get the image model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured image model name\n */\nexport function getImageModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, 'GOOGLE_IMAGE_MODEL') ??\n getSetting(runtime, 'IMAGE_MODEL', 'gemini-2.5-pro-preview-03-25') ??\n 'gemini-2.5-pro-preview-03-25'\n );\n}\n\n/**\n * Helper function to get the embedding model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured embedding model name\n */\nexport function getEmbeddingModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, 'GOOGLE_EMBEDDING_MODEL', 'text-embedding-004') ?? 'text-embedding-004'\n );\n}\n\n/**\n * Create a Google Generative AI client instance with proper configuration\n *\n * @param runtime The runtime context\n * @returns Configured Google Generative AI instance\n */\nexport function createGoogleGenAI(runtime: IAgentRuntime): GoogleGenAI | null {\n const apiKey = getApiKey(runtime);\n if (!apiKey) {\n logger.error('Google Generative AI API Key is missing');\n return null;\n }\n\n return new GoogleGenAI({ apiKey });\n}\n\n/**\n * Convert safety settings to Google format\n */\nexport function getSafetySettings() {\n return [\n {\n category: HarmCategory.HARM_CATEGORY_HARASSMENT,\n threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,\n },\n {\n category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,\n threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,\n },\n {\n category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,\n threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,\n },\n {\n category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,\n threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,\n },\n ];\n}\n","import type { IAgentRuntime, GenerateTextParams } from '@elizaos/core';\nimport { logger, ModelType } from '@elizaos/core';\nimport {\n createGoogleGenAI,\n getSafetySettings,\n getSmallModel,\n getLargeModel,\n} from '../utils/config';\nimport { emitModelUsageEvent } from '../utils/events';\nimport { countTokens } from '../utils/tokenization';\n\nexport async function handleTextSmall(\n runtime: IAgentRuntime,\n {\n prompt,\n stopSequences = [],\n maxTokens = 8192,\n temperature = 0.7,\n frequencyPenalty = 0.7,\n presencePenalty = 0.7,\n }: GenerateTextParams\n) {\n const genAI = createGoogleGenAI(runtime);\n if (!genAI) {\n throw new Error('Google Generative AI client not initialized');\n }\n\n const modelName = getSmallModel(runtime);\n\n logger.log(`[TEXT_SMALL] Using model: ${modelName}`);\n logger.debug(`[TEXT_SMALL] Prompt: ${prompt}`);\n\n try {\n const systemInstruction = runtime.character.system || undefined;\n const response = await genAI.models.generateContent({\n model: modelName,\n contents: prompt,\n config: {\n temperature,\n topK: 40,\n topP: 0.95,\n maxOutputTokens: maxTokens,\n stopSequences,\n safetySettings: getSafetySettings(),\n ...(systemInstruction && { systemInstruction }),\n },\n });\n\n const text = response.text || '';\n\n // Count tokens for usage tracking\n const promptTokens = await countTokens(prompt);\n const completionTokens = await countTokens(text);\n\n emitModelUsageEvent(runtime, ModelType.TEXT_SMALL, prompt, {\n promptTokens,\n completionTokens,\n totalTokens: promptTokens + completionTokens,\n });\n\n return text;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`[TEXT_SMALL] Error: ${message}`);\n throw error;\n }\n}\n\nexport async function handleTextLarge(\n runtime: IAgentRuntime,\n {\n prompt,\n stopSequences = [],\n maxTokens = 8192,\n temperature = 0.7,\n frequencyPenalty = 0.7,\n presencePenalty = 0.7,\n }: GenerateTextParams\n) {\n const genAI = createGoogleGenAI(runtime);\n if (!genAI) {\n throw new Error('Google Generative AI client not initialized');\n }\n\n const modelName = getLargeModel(runtime);\n\n logger.log(`[TEXT_LARGE] Using model: ${modelName}`);\n logger.debug(`[TEXT_LARGE] Prompt: ${prompt}`);\n\n try {\n const systemInstruction = runtime.character.system || undefined;\n const response = await genAI.models.generateContent({\n model: modelName,\n contents: prompt,\n config: {\n temperature,\n topK: 40,\n topP: 0.95,\n maxOutputTokens: maxTokens,\n stopSequences,\n safetySettings: getSafetySettings(),\n ...(systemInstruction && { systemInstruction }),\n },\n });\n\n const text = response.text || '';\n\n // Count tokens for usage tracking\n const promptTokens = await countTokens(prompt);\n const completionTokens = await countTokens(text);\n\n emitModelUsageEvent(runtime, ModelType.TEXT_LARGE, prompt, {\n promptTokens,\n completionTokens,\n totalTokens: promptTokens + completionTokens,\n });\n\n return text;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`[TEXT_LARGE] Error: ${message}`);\n throw error;\n }\n}\n","import type { IAgentRuntime, ModelTypeName } from '@elizaos/core';\nimport { EventType } from '@elizaos/core';\n\n/**\n * Emits a model usage event\n * @param runtime The runtime context\n * @param type The model type\n * @param prompt The prompt used\n * @param usage The usage data\n */\nexport function emitModelUsageEvent(\n runtime: IAgentRuntime,\n type: ModelTypeName,\n prompt: string,\n usage: { promptTokens: number; completionTokens: number; totalTokens: number }\n) {\n runtime.emitEvent(EventType.MODEL_USED, {\n provider: 'google',\n type,\n prompt,\n tokens: {\n prompt: usage.promptTokens,\n completion: usage.completionTokens,\n total: usage.totalTokens,\n },\n });\n}\n","/**\n * Helper function to count tokens for a given text (estimation)\n */\nexport async function countTokens(text: string): Promise<number> {\n // Rough estimation: ~1 token per 4 characters\n return Math.ceil(text.length / 4);\n}\n","import type { IAgentRuntime, TextEmbeddingParams } from '@elizaos/core';\nimport { logger, ModelType } from '@elizaos/core';\nimport { createGoogleGenAI, getEmbeddingModel } from '../utils/config';\nimport { emitModelUsageEvent } from '../utils/events';\nimport { countTokens } from '../utils/tokenization';\n\nexport async function handleTextEmbedding(\n runtime: IAgentRuntime,\n params: TextEmbeddingParams | string | null\n): Promise<number[]> {\n const genAI = createGoogleGenAI(runtime);\n if (!genAI) {\n throw new Error('Google Generative AI client not initialized');\n }\n\n const embeddingModelName = getEmbeddingModel(runtime);\n logger.debug(`[TEXT_EMBEDDING] Using model: ${embeddingModelName}`);\n\n // Handle null case for initialization\n if (params === null) {\n logger.debug('Creating test embedding for initialization');\n // Return 768-dimensional vector for text-embedding-004\n const dimension = 768;\n const testVector = Array(dimension).fill(0);\n testVector[0] = 0.1;\n return testVector;\n }\n\n // Extract text from params\n let text: string;\n if (typeof params === 'string') {\n text = params;\n } else if (typeof params === 'object' && params.text) {\n text = params.text;\n } else {\n logger.warn('Invalid input format for embedding');\n const dimension = 768;\n const fallbackVector = Array(dimension).fill(0);\n fallbackVector[0] = 0.2;\n return fallbackVector;\n }\n\n if (!text.trim()) {\n logger.warn('Empty text for embedding');\n const dimension = 768;\n const emptyVector = Array(dimension).fill(0);\n emptyVector[0] = 0.3;\n return emptyVector;\n }\n\n try {\n const response = await genAI.models.embedContent({\n model: embeddingModelName,\n contents: text,\n });\n\n const embedding = response.embeddings?.[0]?.values || [];\n\n // Count tokens for usage tracking\n const promptTokens = await countTokens(text);\n\n emitModelUsageEvent(runtime, ModelType.TEXT_EMBEDDING, text, {\n promptTokens,\n completionTokens: 0,\n totalTokens: promptTokens,\n });\n\n logger.log(`Got embedding with length ${embedding.length}`);\n return embedding;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error generating embedding: ${message}`);\n // Return error vector\n const dimension = 768;\n const errorVector = Array(dimension).fill(0);\n errorVector[0] = 0.6;\n return errorVector;\n }\n}\n","import type { IAgentRuntime, ImageDescriptionParams } from '@elizaos/core';\nimport { logger } from '@elizaos/core';\nimport { fetch } from 'undici';\nimport { createGoogleGenAI, getSafetySettings, getImageModel } from '../utils/config';\n\nexport async function handleImageDescription(\n runtime: IAgentRuntime,\n params: ImageDescriptionParams | string\n) {\n const genAI = createGoogleGenAI(runtime);\n if (!genAI) {\n throw new Error('Google Generative AI client not initialized');\n }\n\n let imageUrl: string;\n let promptText: string | undefined;\n const modelName = getImageModel(runtime);\n logger.log(`[IMAGE_DESCRIPTION] Using model: ${modelName}`);\n\n if (typeof params === 'string') {\n imageUrl = params;\n promptText = 'Please analyze this image and provide a title and detailed description.';\n } else {\n imageUrl = params.imageUrl;\n promptText =\n params.prompt || 'Please analyze this image and provide a title and detailed description.';\n }\n\n try {\n // Fetch image data\n const imageResponse = await fetch(imageUrl);\n if (!imageResponse.ok) {\n throw new Error(`Failed to fetch image: ${imageResponse.statusText}`);\n }\n\n const imageData = await imageResponse.arrayBuffer();\n const base64Image = Buffer.from(imageData).toString('base64');\n\n // Determine MIME type from URL or response headers\n const contentType = imageResponse.headers.get('content-type') || 'image/jpeg';\n\n const response = await genAI.models.generateContent({\n model: modelName,\n contents: [\n {\n role: 'user',\n parts: [\n { text: promptText },\n {\n inlineData: {\n mimeType: contentType,\n data: base64Image,\n },\n },\n ],\n },\n ],\n config: {\n temperature: 0.7,\n topK: 40,\n topP: 0.95,\n maxOutputTokens: 8192,\n safetySettings: getSafetySettings(),\n },\n });\n\n const responseText = response.text || '';\n\n logger.log('Received response for image description');\n\n // Check if a custom prompt was provided\n const isCustomPrompt =\n typeof params === 'object' &&\n params.prompt &&\n params.prompt !== 'Please analyze this image and provide a title and detailed description.';\n\n // If custom prompt is used, return the raw content\n if (isCustomPrompt) {\n return responseText;\n }\n\n // Try to parse the response as JSON first\n try {\n const jsonResponse = JSON.parse(responseText);\n if (jsonResponse.title && jsonResponse.description) {\n return jsonResponse;\n }\n } catch (e) {\n // If not valid JSON, process as text\n logger.debug(`Parsing as JSON failed, processing as text: ${e}`);\n }\n\n // Extract title and description from text format\n const titleMatch = responseText.match(/title[:\\s]+(.+?)(?:\\n|$)/i);\n const title = titleMatch?.[1]?.trim() || 'Image Analysis';\n const description = responseText.replace(/title[:\\s]+(.+?)(?:\\n|$)/i, '').trim();\n\n return { title, description };\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error analyzing image: ${message}`);\n return {\n title: 'Failed to analyze image',\n description: `Error: ${message}`,\n };\n }\n}\n","import type { IAgentRuntime, ObjectGenerationParams, ModelTypeName } from '@elizaos/core';\nimport { logger } from '@elizaos/core';\nimport {\n createGoogleGenAI,\n getSafetySettings,\n getSmallModel,\n getLargeModel,\n} from '../utils/config';\nimport { emitModelUsageEvent } from '../utils/events';\nimport { countTokens } from '../utils/tokenization';\n\n/**\n * Helper function to generate objects using specified model type\n */\nasync function generateObjectByModelType(\n runtime: IAgentRuntime,\n params: ObjectGenerationParams,\n modelType: string,\n getModelFn: (runtime: IAgentRuntime) => string\n): Promise<any> {\n const genAI = createGoogleGenAI(runtime);\n if (!genAI) {\n throw new Error('Google Generative AI client not initialized');\n }\n\n const modelName = getModelFn(runtime);\n const temperature = params.temperature ?? 0.1;\n\n logger.info(`Using ${modelType} model: ${modelName}`);\n\n try {\n // Add schema instructions to prompt if provided\n let enhancedPrompt = params.prompt;\n if (params.schema) {\n enhancedPrompt += `\\n\\nPlease respond with a JSON object that follows this schema:\\n${JSON.stringify(params.schema, null, 2)}`;\n }\n\n const response = await genAI.models.generateContent({\n model: modelName,\n contents: enhancedPrompt,\n config: {\n temperature,\n topK: 40,\n topP: 0.95,\n maxOutputTokens: 8192,\n responseMimeType: 'application/json',\n safetySettings: getSafetySettings(),\n },\n });\n\n const text = response.text || '';\n\n // Count tokens for usage tracking\n const promptTokens = await countTokens(enhancedPrompt);\n const completionTokens = await countTokens(text);\n\n emitModelUsageEvent(runtime, modelType as ModelTypeName, params.prompt, {\n promptTokens,\n completionTokens,\n totalTokens: promptTokens + completionTokens,\n });\n\n try {\n const parsedResult = JSON.parse(text);\n return parsedResult;\n } catch (parseError) {\n logger.error(\n `Failed to parse JSON response: ${parseError instanceof Error ? parseError.message : String(parseError)}`\n );\n // Try to extract JSON from the response\n const jsonMatch = text.match(/\\{[\\s\\S]*\\}/);\n if (jsonMatch) {\n try {\n const extractedResult = JSON.parse(jsonMatch[0]);\n return extractedResult;\n } catch (secondParseError) {\n throw new Error('Failed to parse JSON from response');\n }\n }\n throw parseError;\n }\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`[generateObject] Error: ${message}`);\n throw error;\n }\n}\n\nexport async function handleObjectSmall(runtime: IAgentRuntime, params: ObjectGenerationParams) {\n return generateObjectByModelType(runtime, params, 'OBJECT_SMALL', getSmallModel);\n}\n\nexport async function handleObjectLarge(runtime: IAgentRuntime, params: ObjectGenerationParams) {\n return generateObjectByModelType(runtime, params, 'OBJECT_LARGE', getLargeModel);\n}\n"],"mappings":";AAQA,SAAS,UAAAA,SAAQ,aAAAC,kBAAiB;;;ACRlC,SAAS,eAAAC,oBAAmB;AAC5B,SAAS,UAAAC,eAAkC;;;ACD3C,SAAS,aAAa,cAAc,0BAA0B;AAE9D,SAAS,cAAc;AAShB,SAAS,WACd,SACA,KACA,cACoB;AACpB,SAAO,QAAQ,WAAW,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK;AACxD;AAQO,SAAS,UAAU,SAA4C;AACpE,SAAO,WAAW,SAAS,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","ModelType","GoogleGenAI","logger","logger","GoogleGenAI","logger","logger","logger","ModelType","logger","ModelType","logger","logger","logger","logger","GoogleGenAI","ModelType","logger"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-google-genai",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@elizaos/core": "^1.
|
|
25
|
+
"@elizaos/core": "^1.6.3",
|
|
26
26
|
"@google/genai": "^1.5.1",
|
|
27
27
|
"undici": "^7.9.0"
|
|
28
28
|
},
|