@olane/o-intelligence 0.7.60 → 0.7.62
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.
|
@@ -3,9 +3,9 @@ import { ToolResult } from '@olane/o-tool';
|
|
|
3
3
|
import { oLaneTool } from '@olane/o-lane';
|
|
4
4
|
import { oNodeToolConfig, oStreamRequest } from '@olane/o-node';
|
|
5
5
|
export declare class GeminiIntelligenceTool extends oLaneTool {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
protected apiKey: string;
|
|
7
|
+
protected baseUrl: string;
|
|
8
|
+
protected defaultModel: string;
|
|
9
9
|
constructor(config: oNodeToolConfig);
|
|
10
10
|
/**
|
|
11
11
|
* Chat completion with Gemini
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini-intelligence.tool.d.ts","sourceRoot":"","sources":["../../src/gemini-intelligence.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAEL,eAAe,EACf,cAAc,EAEf,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"gemini-intelligence.tool.d.ts","sourceRoot":"","sources":["../../src/gemini-intelligence.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAEL,eAAe,EACf,cAAc,EAEf,MAAM,eAAe,CAAC;AA2JvB,qBAAa,sBAAuB,SAAQ,SAAS;IACnD,SAAS,CAAC,MAAM,EAAE,MAAM,CAAoC;IAC5D,SAAS,CAAC,OAAO,EAAE,MAAM,CAC4B;IACrD,SAAS,CAAC,YAAY,EAAE,MAAM,CAA0B;gBAE5C,MAAM,EAAE,eAAe;IAUnC;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IA6FpE;;OAEG;YACY,iBAAiB;IA+HhC;;OAEG;IACG,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IA8FlE;;OAEG;YACY,eAAe;IAgI9B;;OAEG;IACG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAwC/D;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IA0C9D;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAgC1D;;OAEG;IACG,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IA2GlE;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IA0J9D;;OAEG;YACW,mBAAmB;CA0BlC"}
|
|
@@ -13,6 +13,8 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
13
13
|
dependencies: [],
|
|
14
14
|
});
|
|
15
15
|
this.apiKey = process.env.GEMINI_API_KEY || '';
|
|
16
|
+
this.baseUrl = 'https://generativelanguage.googleapis.com/v1beta';
|
|
17
|
+
this.defaultModel = 'gemini-3-pro-preview';
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Chat completion with Gemini
|
|
@@ -54,10 +56,11 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
54
56
|
},
|
|
55
57
|
safetySettings: options.safetySettings,
|
|
56
58
|
};
|
|
57
|
-
const response = await fetch(`${this.baseUrl}/models/${model}:generateContent
|
|
59
|
+
const response = await fetch(`${this.baseUrl}/models/${model}:generateContent`, {
|
|
58
60
|
method: 'POST',
|
|
59
61
|
headers: {
|
|
60
62
|
'Content-Type': 'application/json',
|
|
63
|
+
'x-goog-api-key': this.apiKey,
|
|
61
64
|
},
|
|
62
65
|
body: JSON.stringify(chatRequest),
|
|
63
66
|
});
|
|
@@ -76,8 +79,7 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
76
79
|
};
|
|
77
80
|
}
|
|
78
81
|
return {
|
|
79
|
-
|
|
80
|
-
response: result.candidates[0].content.parts[0]?.text || '',
|
|
82
|
+
message: result.candidates[0].content.parts[0]?.text || '',
|
|
81
83
|
model: model,
|
|
82
84
|
usage: result.usageMetadata,
|
|
83
85
|
finish_reason: result.candidates[0].finishReason,
|
|
@@ -128,10 +130,11 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
128
130
|
},
|
|
129
131
|
safetySettings: options.safetySettings,
|
|
130
132
|
};
|
|
131
|
-
const response = await fetch(`${this.baseUrl}/models/${model}:streamGenerateContent?
|
|
133
|
+
const response = await fetch(`${this.baseUrl}/models/${model}:streamGenerateContent?alt=sse`, {
|
|
132
134
|
method: 'POST',
|
|
133
135
|
headers: {
|
|
134
136
|
'Content-Type': 'application/json',
|
|
137
|
+
'x-goog-api-key': this.apiKey,
|
|
135
138
|
},
|
|
136
139
|
body: JSON.stringify(chatRequest),
|
|
137
140
|
});
|
|
@@ -242,10 +245,11 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
242
245
|
},
|
|
243
246
|
safetySettings: options.safetySettings,
|
|
244
247
|
};
|
|
245
|
-
const response = await fetch(`${this.baseUrl}/models/${model}:generateContent
|
|
248
|
+
const response = await fetch(`${this.baseUrl}/models/${model}:generateContent`, {
|
|
246
249
|
method: 'POST',
|
|
247
250
|
headers: {
|
|
248
251
|
'Content-Type': 'application/json',
|
|
252
|
+
'x-goog-api-key': this.apiKey,
|
|
249
253
|
},
|
|
250
254
|
body: JSON.stringify(generateRequest),
|
|
251
255
|
});
|
|
@@ -264,8 +268,7 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
264
268
|
};
|
|
265
269
|
}
|
|
266
270
|
return {
|
|
267
|
-
|
|
268
|
-
response: result.candidates[0].content.parts[0]?.text || '',
|
|
271
|
+
message: result.candidates[0].content.parts[0]?.text || '',
|
|
269
272
|
model: model,
|
|
270
273
|
usage: result.usageMetadata,
|
|
271
274
|
finish_reason: result.candidates[0].finishReason,
|
|
@@ -317,10 +320,11 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
317
320
|
},
|
|
318
321
|
safetySettings: options.safetySettings,
|
|
319
322
|
};
|
|
320
|
-
const response = await fetch(`${this.baseUrl}/models/${model}:streamGenerateContent?
|
|
323
|
+
const response = await fetch(`${this.baseUrl}/models/${model}:streamGenerateContent?alt=sse`, {
|
|
321
324
|
method: 'POST',
|
|
322
325
|
headers: {
|
|
323
326
|
'Content-Type': 'application/json',
|
|
327
|
+
'x-goog-api-key': this.apiKey,
|
|
324
328
|
},
|
|
325
329
|
body: JSON.stringify(generateRequest),
|
|
326
330
|
});
|
|
@@ -401,10 +405,11 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
401
405
|
error: 'Gemini API key is required',
|
|
402
406
|
};
|
|
403
407
|
}
|
|
404
|
-
const response = await fetch(`${this.baseUrl}/models
|
|
408
|
+
const response = await fetch(`${this.baseUrl}/models`, {
|
|
405
409
|
method: 'GET',
|
|
406
410
|
headers: {
|
|
407
411
|
'Content-Type': 'application/json',
|
|
412
|
+
'x-goog-api-key': this.apiKey,
|
|
408
413
|
},
|
|
409
414
|
});
|
|
410
415
|
if (!response.ok) {
|
|
@@ -440,10 +445,11 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
440
445
|
error: 'Gemini API key is required',
|
|
441
446
|
};
|
|
442
447
|
}
|
|
443
|
-
const response = await fetch(`${this.baseUrl}/models/${model}
|
|
448
|
+
const response = await fetch(`${this.baseUrl}/models/${model}`, {
|
|
444
449
|
method: 'GET',
|
|
445
450
|
headers: {
|
|
446
451
|
'Content-Type': 'application/json',
|
|
452
|
+
'x-goog-api-key': this.apiKey,
|
|
447
453
|
},
|
|
448
454
|
});
|
|
449
455
|
if (!response.ok) {
|
|
@@ -478,10 +484,11 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
478
484
|
error: 'Gemini API key is required',
|
|
479
485
|
};
|
|
480
486
|
}
|
|
481
|
-
const response = await fetch(`${this.baseUrl}/models
|
|
487
|
+
const response = await fetch(`${this.baseUrl}/models`, {
|
|
482
488
|
method: 'GET',
|
|
483
489
|
headers: {
|
|
484
490
|
'Content-Type': 'application/json',
|
|
491
|
+
'x-goog-api-key': this.apiKey,
|
|
485
492
|
},
|
|
486
493
|
});
|
|
487
494
|
return {
|
|
@@ -527,18 +534,19 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
527
534
|
parts: [{ text: fullPrompt }],
|
|
528
535
|
},
|
|
529
536
|
],
|
|
530
|
-
generationConfig: {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
},
|
|
537
|
+
// generationConfig: {
|
|
538
|
+
// responseModalities: ['TEXT', 'IMAGE'],
|
|
539
|
+
// imageConfig: {
|
|
540
|
+
// aspectRatio: aspectRatio as GeminiImageConfig['aspectRatio'],
|
|
541
|
+
// imageSize: imageSize as GeminiImageConfig['imageSize'],
|
|
542
|
+
// },
|
|
543
|
+
// },
|
|
537
544
|
};
|
|
538
|
-
const response = await fetch(`${this.baseUrl}/models/${model}:generateContent
|
|
545
|
+
const response = await fetch(`${this.baseUrl}/models/${model}:generateContent`, {
|
|
539
546
|
method: 'POST',
|
|
540
547
|
headers: {
|
|
541
548
|
'Content-Type': 'application/json',
|
|
549
|
+
'x-goog-api-key': this.apiKey,
|
|
542
550
|
},
|
|
543
551
|
body: JSON.stringify(imageRequest),
|
|
544
552
|
});
|
|
@@ -551,28 +559,23 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
551
559
|
}
|
|
552
560
|
const result = (await response.json());
|
|
553
561
|
if (!result.candidates || result.candidates.length === 0) {
|
|
554
|
-
|
|
555
|
-
success: false,
|
|
556
|
-
error: 'No response generated from Gemini',
|
|
557
|
-
};
|
|
562
|
+
throw new Error('No response generated from Gemini');
|
|
558
563
|
}
|
|
559
564
|
// Extract image and text from response parts
|
|
560
565
|
const parts = result.candidates[0].content.parts;
|
|
561
566
|
let imageData;
|
|
562
567
|
let description;
|
|
563
568
|
for (const part of parts) {
|
|
564
|
-
|
|
565
|
-
|
|
569
|
+
console.log('part:', part);
|
|
570
|
+
if (part.inlineData) {
|
|
571
|
+
imageData = part.inlineData.data;
|
|
566
572
|
}
|
|
567
573
|
else if (part.text) {
|
|
568
574
|
description = part.text;
|
|
569
575
|
}
|
|
570
576
|
}
|
|
571
577
|
if (!imageData) {
|
|
572
|
-
|
|
573
|
-
success: false,
|
|
574
|
-
error: 'No image data in response',
|
|
575
|
-
};
|
|
578
|
+
throw new Error('No image data in response');
|
|
576
579
|
}
|
|
577
580
|
return {
|
|
578
581
|
success: true,
|
|
@@ -672,10 +675,11 @@ export class GeminiIntelligenceTool extends oLaneTool {
|
|
|
672
675
|
},
|
|
673
676
|
},
|
|
674
677
|
};
|
|
675
|
-
const response = await fetch(`${this.baseUrl}/models/${model}:generateContent
|
|
678
|
+
const response = await fetch(`${this.baseUrl}/models/${model}:generateContent`, {
|
|
676
679
|
method: 'POST',
|
|
677
680
|
headers: {
|
|
678
681
|
'Content-Type': 'application/json',
|
|
682
|
+
'x-goog-api-key': this.apiKey,
|
|
679
683
|
},
|
|
680
684
|
body: JSON.stringify(imageRequest),
|
|
681
685
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olane/o-intelligence",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.62",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -54,13 +54,13 @@
|
|
|
54
54
|
"typescript": "5.4.5"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@olane/o-config": "0.7.
|
|
58
|
-
"@olane/o-core": "0.7.
|
|
59
|
-
"@olane/o-lane": "0.7.
|
|
60
|
-
"@olane/o-protocol": "0.7.
|
|
61
|
-
"@olane/o-tool": "0.7.
|
|
57
|
+
"@olane/o-config": "0.7.62",
|
|
58
|
+
"@olane/o-core": "0.7.62",
|
|
59
|
+
"@olane/o-lane": "0.7.62",
|
|
60
|
+
"@olane/o-protocol": "0.7.62",
|
|
61
|
+
"@olane/o-tool": "0.7.62",
|
|
62
62
|
"debug": "^4.4.1",
|
|
63
63
|
"dotenv": "^16.5.0"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "98ea2724c4a764edb33f6fec648d735ed5c236af"
|
|
66
66
|
}
|