@quatrain/ai-gemini 1.1.3 → 1.1.5
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/GeminiAdapter.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare class GeminiAdapter extends AbstractAiAdapter {
|
|
|
6
6
|
constructor(apiKey: string);
|
|
7
7
|
init(): void;
|
|
8
8
|
generateText(prompt: string, options?: any): Promise<string>;
|
|
9
|
-
generateStructured(prompt:
|
|
9
|
+
generateStructured(prompt: any, schema: any, options?: any): Promise<any>;
|
|
10
|
+
generateTextStream(prompt: string, options?: any): Promise<AsyncIterable<string>>;
|
|
10
11
|
}
|
|
11
12
|
//# sourceMappingURL=GeminiAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeminiAdapter.d.ts","sourceRoot":"","sources":["../src/GeminiAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAK3C,qBAAa,aAAc,SAAQ,iBAAiB;IACjD,SAAS,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAAO;IACxC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;gBAEb,MAAM,EAAE,MAAM;IAQ1B,IAAI,IAAI,IAAI;IAWN,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAqB5D,kBAAkB,CAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"GeminiAdapter.d.ts","sourceRoot":"","sources":["../src/GeminiAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAK3C,qBAAa,aAAc,SAAQ,iBAAiB;IACjD,SAAS,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAAO;IACxC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;gBAEb,MAAM,EAAE,MAAM;IAQ1B,IAAI,IAAI,IAAI;IAWN,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAqB5D,kBAAkB,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA2BzE,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;CAiBzF"}
|
package/dist/GeminiAdapter.js
CHANGED
|
@@ -40,6 +40,21 @@ class GeminiAdapter extends ai_1.AbstractAiAdapter {
|
|
|
40
40
|
}
|
|
41
41
|
return JSON.parse(response.text);
|
|
42
42
|
}
|
|
43
|
+
async generateTextStream(prompt, options) {
|
|
44
|
+
if (!this._ai)
|
|
45
|
+
this.init();
|
|
46
|
+
const model = options?.model || 'gemini-2.5-flash';
|
|
47
|
+
const responseStream = await this._ai.models.generateContentStream({
|
|
48
|
+
model,
|
|
49
|
+
contents: prompt,
|
|
50
|
+
});
|
|
51
|
+
async function* makeGenerator() {
|
|
52
|
+
for await (const chunk of responseStream) {
|
|
53
|
+
yield chunk.text || '';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return makeGenerator();
|
|
57
|
+
}
|
|
43
58
|
}
|
|
44
59
|
exports.GeminiAdapter = GeminiAdapter;
|
|
45
60
|
//# sourceMappingURL=GeminiAdapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeminiAdapter.js","sourceRoot":"","sources":["../src/GeminiAdapter.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AAChD,yCAA2C;AAK3C,MAAa,aAAc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AK,GAAG,OAAO,EAAE,KAAK,IAAI,kBAAkB,CAAA;QAClD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YACrD,KAAK;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE;gBACL,gBAAgB,EAAE,kBAAkB;gBACpC,cAAc,EAAE,MAAM;aACxB;SACH,CAAC,CAAA;QAEF,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;QACtD,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IASD,KAAK,CAAC,kBAAkB,CAAC,MAAc,EAAE,OAAa;QACnD,IAAI,CAAC,IAAI,CAAC,GAAG;YAAE,IAAI,CAAC,IAAI,EAAE,CAAA;QAE1B,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,kBAAkB,CAAA;QAClD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,GAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC;YACjE,KAAK;YACL,QAAQ,EAAE,MAAM;SAClB,CAAC,CAAA;QAEF,KAAK,SAAS,CAAC,CAAC,aAAa;YAC1B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;gBACxC,MAAM,KAAK,CAAC,IAAI,IAAI,EAAE,CAAA;YACzB,CAAC;QACJ,CAAC;QAED,OAAO,aAAa,EAAE,CAAA;IACzB,CAAC;CACH;AAxFD,sCAwFC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/ai-gemini",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"description": "AI adapter for Google Gemini",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"author": "Quatrain Développement SAS <developers@quatrain.com>",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@google/genai": "latest",
|
|
24
|
-
"@quatrain/ai": "^1.1.
|
|
25
|
-
"@quatrain/core": "^1.2.
|
|
24
|
+
"@quatrain/ai": "^1.1.4",
|
|
25
|
+
"@quatrain/core": "^1.2.17"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@tsconfig/recommended": "^1.0.1",
|
package/src/GeminiAdapter.ts
CHANGED
|
@@ -17,7 +17,7 @@ export class GeminiAdapter extends AbstractAiAdapter {
|
|
|
17
17
|
* Initializes the internal GoogleGenAI client with the provided API key.
|
|
18
18
|
*/
|
|
19
19
|
init(): void {
|
|
20
|
-
this._ai = new GoogleGenAI({ apiKey: this._apiKey })
|
|
20
|
+
this._ai = new GoogleGenAI({ apiKey: this._apiKey });
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -48,7 +48,7 @@ export class GeminiAdapter extends AbstractAiAdapter {
|
|
|
48
48
|
* @returns The parsed JSON object returned by the model.
|
|
49
49
|
* @throws {Error} If the API does not return valid text.
|
|
50
50
|
*/
|
|
51
|
-
async generateStructured(prompt:
|
|
51
|
+
async generateStructured(prompt: any, schema: any, options?: any): Promise<any> {
|
|
52
52
|
if (!this._ai) this.init()
|
|
53
53
|
|
|
54
54
|
const model = options?.model || 'gemini-2.5-flash'
|
|
@@ -67,4 +67,29 @@ export class GeminiAdapter extends AbstractAiAdapter {
|
|
|
67
67
|
|
|
68
68
|
return JSON.parse(response.text)
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Sends a textual prompt to the Gemini API and returns an async iterable of text chunks.
|
|
73
|
+
*
|
|
74
|
+
* @param prompt - The instruction or query to send to the model.
|
|
75
|
+
* @param options - Configuration options including the `model` identifier.
|
|
76
|
+
* @returns An async iterable stream of text chunks.
|
|
77
|
+
*/
|
|
78
|
+
async generateTextStream(prompt: string, options?: any): Promise<AsyncIterable<string>> {
|
|
79
|
+
if (!this._ai) this.init()
|
|
80
|
+
|
|
81
|
+
const model = options?.model || 'gemini-2.5-flash'
|
|
82
|
+
const responseStream = await this._ai!.models.generateContentStream({
|
|
83
|
+
model,
|
|
84
|
+
contents: prompt,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
async function* makeGenerator() {
|
|
88
|
+
for await (const chunk of responseStream) {
|
|
89
|
+
yield chunk.text || ''
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return makeGenerator()
|
|
94
|
+
}
|
|
70
95
|
}
|