@quatrain/ai-gemini 1.1.1

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.
@@ -0,0 +1,11 @@
1
+ import { AbstractAiAdapter } from '@quatrain/ai';
2
+ import { GoogleGenAI } from '@google/genai';
3
+ export declare class GeminiAdapter extends AbstractAiAdapter {
4
+ protected _ai: GoogleGenAI | null;
5
+ protected _apiKey: string;
6
+ constructor(apiKey: string);
7
+ init(): void;
8
+ generateText(prompt: string, options?: any): Promise<string>;
9
+ generateStructured(prompt: string, schema: any, options?: any): Promise<any>;
10
+ }
11
+ //# sourceMappingURL=GeminiAdapter.d.ts.map
@@ -0,0 +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;AAE3C,qBAAa,aAAc,SAAQ,iBAAiB;IACjD,SAAS,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAAO;IACxC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;gBAEb,MAAM,EAAE,MAAM;IAK1B,IAAI,IAAI,IAAI;IAIN,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAY5D,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAmBpF"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeminiAdapter = void 0;
4
+ const ai_1 = require("@quatrain/ai");
5
+ const genai_1 = require("@google/genai");
6
+ class GeminiAdapter extends ai_1.AbstractAiAdapter {
7
+ _ai = null;
8
+ _apiKey;
9
+ constructor(apiKey) {
10
+ super();
11
+ this._apiKey = apiKey;
12
+ }
13
+ init() {
14
+ this._ai = new genai_1.GoogleGenAI({ apiKey: this._apiKey });
15
+ }
16
+ async generateText(prompt, options) {
17
+ if (!this._ai)
18
+ this.init();
19
+ const model = options?.model || 'gemini-2.5-flash';
20
+ const response = await this._ai.models.generateContent({
21
+ model,
22
+ contents: prompt,
23
+ });
24
+ return response.text || '';
25
+ }
26
+ async generateStructured(prompt, schema, options) {
27
+ if (!this._ai)
28
+ this.init();
29
+ const model = options?.model || 'gemini-2.5-flash';
30
+ const response = await this._ai.models.generateContent({
31
+ model,
32
+ contents: prompt,
33
+ config: {
34
+ responseMimeType: 'application/json',
35
+ responseSchema: schema,
36
+ }
37
+ });
38
+ if (!response.text) {
39
+ throw new Error('No text returned from Gemini API');
40
+ }
41
+ return JSON.parse(response.text);
42
+ }
43
+ }
44
+ exports.GeminiAdapter = GeminiAdapter;
45
+ //# sourceMappingURL=GeminiAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeminiAdapter.js","sourceRoot":"","sources":["../src/GeminiAdapter.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AAChD,yCAA2C;AAE3C,MAAa,aAAc,SAAQ,sBAAiB;IACvC,GAAG,GAAuB,IAAI,CAAA;IAC9B,OAAO,CAAQ;IAEzB,YAAY,MAAc;QACvB,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,IAAI;QACD,IAAI,CAAC,GAAG,GAAG,IAAI,mBAAW,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IACvD,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAAc,EAAE,OAAa;QAC7C,IAAI,CAAC,IAAI,CAAC,GAAG;YAAE,IAAI,CAAC,IAAI,EAAE,CAAA;QAE1B,MAAM,KAAK,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;SAClB,CAAC,CAAA;QAEF,OAAO,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAA;IAC7B,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,MAAc,EAAE,MAAW,EAAE,OAAa;QAChE,IAAI,CAAC,IAAI,CAAC,GAAG;YAAE,IAAI,CAAC,IAAI,EAAE,CAAA;QAE1B,MAAM,KAAK,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;CACH;AA5CD,sCA4CC"}
@@ -0,0 +1,2 @@
1
+ export { GeminiAdapter } from './GeminiAdapter';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeminiAdapter = void 0;
4
+ var GeminiAdapter_1 = require("./GeminiAdapter");
5
+ Object.defineProperty(exports, "GeminiAdapter", { enumerable: true, get: function () { return GeminiAdapter_1.GeminiAdapter; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAAtC,8GAAA,aAAa,OAAA"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@quatrain/ai-gemini",
3
+ "version": "1.1.1",
4
+ "license": "AGPL-3.0-only",
5
+ "description": "AI adapter for Google Gemini",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bun": "src/index.ts",
9
+ "files": [
10
+ "LICENSE.md",
11
+ "src/",
12
+ "dist/",
13
+ "README.md",
14
+ "NOTICE.md"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Quatrain/Core.git",
19
+ "directory": "packages/ai-gemini"
20
+ },
21
+ "author": "Quatrain Développement SAS <developers@quatrain.com>",
22
+ "dependencies": {
23
+ "@google/genai": "latest",
24
+ "@quatrain/ai": "^1.1.1",
25
+ "@quatrain/core": "^1.1.52"
26
+ },
27
+ "devDependencies": {
28
+ "@tsconfig/recommended": "^1.0.1",
29
+ "@types/jest": "^29.5.12",
30
+ "@types/node": "^22.10.1",
31
+ "jest": "^29.7.0",
32
+ "jest-node-exports-resolver": "^1.1.6",
33
+ "jest-serial-runner": "^1.2.1",
34
+ "trace-unhandled": "^2.0.1",
35
+ "ts-jest": "^29.4.6",
36
+ "ts-node": "^10.9.1",
37
+ "typescript": "^5.1.5"
38
+ },
39
+ "scripts": {
40
+ "test-ci": "jest --runInBand",
41
+ "build": "tsc",
42
+ "wbuild": "tsc --watch",
43
+ "bump-to": "yarn version"
44
+ },
45
+ "typedoc": {
46
+ "entryPoint": "src/index.ts"
47
+ }
48
+ }
@@ -0,0 +1,48 @@
1
+ import { AbstractAiAdapter } from '@quatrain/ai'
2
+ import { GoogleGenAI } from '@google/genai'
3
+
4
+ export class GeminiAdapter extends AbstractAiAdapter {
5
+ protected _ai: GoogleGenAI | null = null
6
+ protected _apiKey: string
7
+
8
+ constructor(apiKey: string) {
9
+ super()
10
+ this._apiKey = apiKey
11
+ }
12
+
13
+ init(): void {
14
+ this._ai = new GoogleGenAI({ apiKey: this._apiKey })
15
+ }
16
+
17
+ async generateText(prompt: string, options?: any): Promise<string> {
18
+ if (!this._ai) this.init()
19
+
20
+ const model = options?.model || 'gemini-2.5-flash'
21
+ const response = await this._ai!.models.generateContent({
22
+ model,
23
+ contents: prompt,
24
+ })
25
+
26
+ return response.text || ''
27
+ }
28
+
29
+ async generateStructured(prompt: string, schema: any, options?: any): Promise<any> {
30
+ if (!this._ai) this.init()
31
+
32
+ const model = options?.model || 'gemini-2.5-flash'
33
+ const response = await this._ai!.models.generateContent({
34
+ model,
35
+ contents: prompt,
36
+ config: {
37
+ responseMimeType: 'application/json',
38
+ responseSchema: schema,
39
+ }
40
+ })
41
+
42
+ if (!response.text) {
43
+ throw new Error('No text returned from Gemini API')
44
+ }
45
+
46
+ return JSON.parse(response.text)
47
+ }
48
+ }
@@ -0,0 +1,22 @@
1
+ import { GeminiAdapter } from '../GeminiAdapter'
2
+
3
+ jest.mock('@google/genai', () => ({
4
+ GoogleGenAI: jest.fn().mockImplementation(() => ({
5
+ models: {
6
+ generateContent: jest.fn().mockResolvedValue({ text: 'mock AI response' })
7
+ }
8
+ }))
9
+ }))
10
+
11
+ describe('GeminiAdapter', () => {
12
+ let adapter: GeminiAdapter
13
+
14
+ beforeEach(() => {
15
+ adapter = new GeminiAdapter('fake-api-key')
16
+ })
17
+
18
+ it('should instantiate and generate text', async () => {
19
+ const response = await adapter.generateText('Hello')
20
+ expect(response).toBe('mock AI response')
21
+ })
22
+ })
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { GeminiAdapter } from './GeminiAdapter'