@aigne/gemini 1.74.0-beta.8 → 1.74.0-beta.9

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,65 @@
1
+ let _aigne_model_base = require("@aigne/model-base");
2
+ let _aigne_model_base_utils_type_utils = require("@aigne/model-base/utils/type-utils");
3
+ let _google_genai = require("@google/genai");
4
+ let zod = require("zod");
5
+
6
+ //#region src/gemini-embedding-model.ts
7
+ const DEFAULT_MODEL = "text-embedding-004";
8
+ const geminiEmbeddingModelInputSchema = _aigne_model_base.embeddingModelInputSchema.extend({});
9
+ const geminiEmbeddingModelOptionsSchema = zod.z.object({
10
+ apiKey: zod.z.string().optional(),
11
+ baseURL: zod.z.string().optional(),
12
+ model: zod.z.string().optional(),
13
+ modelOptions: zod.z.object({}).optional(),
14
+ clientOptions: zod.z.object({}).optional()
15
+ });
16
+ var GeminiEmbeddingModel = class extends _aigne_model_base.EmbeddingModel {
17
+ constructor(options) {
18
+ super({
19
+ ...options,
20
+ inputSchema: geminiEmbeddingModelInputSchema,
21
+ description: options?.description ?? "Generate embeddings by Gemini embedding models"
22
+ });
23
+ this.options = options;
24
+ if (options) (0, _aigne_model_base_utils_type_utils.checkArguments)(this.name, geminiEmbeddingModelOptionsSchema, options);
25
+ }
26
+ _client;
27
+ apiKeyEnvName = "GEMINI_API_KEY";
28
+ get client() {
29
+ if (this._client) return this._client;
30
+ const { apiKey } = this.credential;
31
+ if (!apiKey) throw new Error(`${this.name} requires an API key. Please provide it via \`options.apiKey\`, or set the \`${this.apiKeyEnvName}\` environment variable`);
32
+ this._client ??= new _google_genai.GoogleGenAI({ apiKey });
33
+ return this._client;
34
+ }
35
+ get credential() {
36
+ return {
37
+ url: this.options?.baseURL || process.env.GEMINI_BASE_URL,
38
+ apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName],
39
+ model: this.options?.model || DEFAULT_MODEL
40
+ };
41
+ }
42
+ async process(input, _options) {
43
+ const model = input.modelOptions?.model || this.credential.model;
44
+ const contents = Array.isArray(input.input) ? input.input : [input.input];
45
+ const config = {
46
+ ...input.dimensions ? { outputDimensionality: input.dimensions } : {},
47
+ ...input.modelOptions?.taskType ? { taskType: input.modelOptions.taskType } : {}
48
+ };
49
+ return {
50
+ embeddings: (await this.client.models.embedContent({
51
+ model,
52
+ contents,
53
+ config
54
+ })).embeddings?.map((e) => e.values ?? []) ?? [],
55
+ usage: {
56
+ inputTokens: 0,
57
+ outputTokens: 0
58
+ },
59
+ model
60
+ };
61
+ }
62
+ };
63
+
64
+ //#endregion
65
+ exports.GeminiEmbeddingModel = GeminiEmbeddingModel;
@@ -0,0 +1,28 @@
1
+ import { EmbeddingModel, EmbeddingModelInput, EmbeddingModelOptions, EmbeddingModelOutput, ModelInvokeOptions } from "@aigne/model-base";
2
+ import { GoogleGenAI } from "@google/genai";
3
+
4
+ //#region src/gemini-embedding-model.d.ts
5
+ interface GeminiEmbeddingModelInput extends EmbeddingModelInput {}
6
+ interface GeminiEmbeddingModelOutput extends EmbeddingModelOutput {}
7
+ interface GeminiEmbeddingModelOptions extends EmbeddingModelOptions<GeminiEmbeddingModelInput, GeminiEmbeddingModelOutput> {
8
+ apiKey?: string;
9
+ baseURL?: string;
10
+ model?: string;
11
+ clientOptions?: Record<string, any>;
12
+ }
13
+ declare class GeminiEmbeddingModel extends EmbeddingModel<GeminiEmbeddingModelInput, GeminiEmbeddingModelOutput> {
14
+ options?: GeminiEmbeddingModelOptions | undefined;
15
+ constructor(options?: GeminiEmbeddingModelOptions | undefined);
16
+ protected _client?: GoogleGenAI;
17
+ protected apiKeyEnvName: string;
18
+ get client(): GoogleGenAI;
19
+ get credential(): {
20
+ url: string | undefined;
21
+ apiKey: string | undefined;
22
+ model: string;
23
+ };
24
+ process(input: GeminiEmbeddingModelInput, _options: ModelInvokeOptions): Promise<GeminiEmbeddingModelOutput>;
25
+ }
26
+ //#endregion
27
+ export { GeminiEmbeddingModel, GeminiEmbeddingModelInput, GeminiEmbeddingModelOptions, GeminiEmbeddingModelOutput };
28
+ //# sourceMappingURL=gemini-embedding-model.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini-embedding-model.d.cts","names":[],"sources":["../src/gemini-embedding-model.ts"],"mappings":";;;;UAciB,yBAAA,SAAkC,mBAAA;AAAA,UAClC,0BAAA,SAAmC,oBAAA;AAAA,UAEnC,2BAAA,SACP,qBAAA,CAAsB,yBAAA,EAA2B,0BAAA;EACzD,MAAA;EACA,OAAA;EACA,KAAA;EACA,aAAA,GAAgB,MAAA;AAAA;AAAA,cAaL,oBAAA,SAA6B,cAAA,CACxC,yBAAA,EACA,0BAAA;EAE4B,OAAA,GAAU,2BAAA;cAAV,OAAA,GAAU,2BAAA;EAAA,UAS5B,OAAA,GAAU,WAAA;EAAA,UAEV,aAAA;EAAA,IAEN,MAAA,CAAA,GAAM,WAAA;EAAA,IAeG,UAAA,CAAA;;;;;EAQE,OAAA,CACb,KAAA,EAAO,yBAAA,EACP,QAAA,EAAU,kBAAA,GACT,OAAA,CAAQ,0BAAA;AAAA"}
@@ -0,0 +1,28 @@
1
+ import { EmbeddingModel, EmbeddingModelInput, EmbeddingModelOptions, EmbeddingModelOutput, ModelInvokeOptions } from "@aigne/model-base";
2
+ import { GoogleGenAI } from "@google/genai";
3
+
4
+ //#region src/gemini-embedding-model.d.ts
5
+ interface GeminiEmbeddingModelInput extends EmbeddingModelInput {}
6
+ interface GeminiEmbeddingModelOutput extends EmbeddingModelOutput {}
7
+ interface GeminiEmbeddingModelOptions extends EmbeddingModelOptions<GeminiEmbeddingModelInput, GeminiEmbeddingModelOutput> {
8
+ apiKey?: string;
9
+ baseURL?: string;
10
+ model?: string;
11
+ clientOptions?: Record<string, any>;
12
+ }
13
+ declare class GeminiEmbeddingModel extends EmbeddingModel<GeminiEmbeddingModelInput, GeminiEmbeddingModelOutput> {
14
+ options?: GeminiEmbeddingModelOptions | undefined;
15
+ constructor(options?: GeminiEmbeddingModelOptions | undefined);
16
+ protected _client?: GoogleGenAI;
17
+ protected apiKeyEnvName: string;
18
+ get client(): GoogleGenAI;
19
+ get credential(): {
20
+ url: string | undefined;
21
+ apiKey: string | undefined;
22
+ model: string;
23
+ };
24
+ process(input: GeminiEmbeddingModelInput, _options: ModelInvokeOptions): Promise<GeminiEmbeddingModelOutput>;
25
+ }
26
+ //#endregion
27
+ export { GeminiEmbeddingModel, GeminiEmbeddingModelInput, GeminiEmbeddingModelOptions, GeminiEmbeddingModelOutput };
28
+ //# sourceMappingURL=gemini-embedding-model.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini-embedding-model.d.mts","names":[],"sources":["../src/gemini-embedding-model.ts"],"mappings":";;;;UAciB,yBAAA,SAAkC,mBAAA;AAAA,UAClC,0BAAA,SAAmC,oBAAA;AAAA,UAEnC,2BAAA,SACP,qBAAA,CAAsB,yBAAA,EAA2B,0BAAA;EACzD,MAAA;EACA,OAAA;EACA,KAAA;EACA,aAAA,GAAgB,MAAA;AAAA;AAAA,cAaL,oBAAA,SAA6B,cAAA,CACxC,yBAAA,EACA,0BAAA;EAE4B,OAAA,GAAU,2BAAA;cAAV,OAAA,GAAU,2BAAA;EAAA,UAS5B,OAAA,GAAU,WAAA;EAAA,UAEV,aAAA;EAAA,IAEN,MAAA,CAAA,GAAM,WAAA;EAAA,IAeG,UAAA,CAAA;;;;;EAQE,OAAA,CACb,KAAA,EAAO,yBAAA,EACP,QAAA,EAAU,kBAAA,GACT,OAAA,CAAQ,0BAAA;AAAA"}
@@ -0,0 +1,66 @@
1
+ import { EmbeddingModel, embeddingModelInputSchema } from "@aigne/model-base";
2
+ import { checkArguments } from "@aigne/model-base/utils/type-utils";
3
+ import { GoogleGenAI } from "@google/genai";
4
+ import { z } from "zod";
5
+
6
+ //#region src/gemini-embedding-model.ts
7
+ const DEFAULT_MODEL = "text-embedding-004";
8
+ const geminiEmbeddingModelInputSchema = embeddingModelInputSchema.extend({});
9
+ const geminiEmbeddingModelOptionsSchema = z.object({
10
+ apiKey: z.string().optional(),
11
+ baseURL: z.string().optional(),
12
+ model: z.string().optional(),
13
+ modelOptions: z.object({}).optional(),
14
+ clientOptions: z.object({}).optional()
15
+ });
16
+ var GeminiEmbeddingModel = class extends EmbeddingModel {
17
+ constructor(options) {
18
+ super({
19
+ ...options,
20
+ inputSchema: geminiEmbeddingModelInputSchema,
21
+ description: options?.description ?? "Generate embeddings by Gemini embedding models"
22
+ });
23
+ this.options = options;
24
+ if (options) checkArguments(this.name, geminiEmbeddingModelOptionsSchema, options);
25
+ }
26
+ _client;
27
+ apiKeyEnvName = "GEMINI_API_KEY";
28
+ get client() {
29
+ if (this._client) return this._client;
30
+ const { apiKey } = this.credential;
31
+ if (!apiKey) throw new Error(`${this.name} requires an API key. Please provide it via \`options.apiKey\`, or set the \`${this.apiKeyEnvName}\` environment variable`);
32
+ this._client ??= new GoogleGenAI({ apiKey });
33
+ return this._client;
34
+ }
35
+ get credential() {
36
+ return {
37
+ url: this.options?.baseURL || process.env.GEMINI_BASE_URL,
38
+ apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName],
39
+ model: this.options?.model || DEFAULT_MODEL
40
+ };
41
+ }
42
+ async process(input, _options) {
43
+ const model = input.modelOptions?.model || this.credential.model;
44
+ const contents = Array.isArray(input.input) ? input.input : [input.input];
45
+ const config = {
46
+ ...input.dimensions ? { outputDimensionality: input.dimensions } : {},
47
+ ...input.modelOptions?.taskType ? { taskType: input.modelOptions.taskType } : {}
48
+ };
49
+ return {
50
+ embeddings: (await this.client.models.embedContent({
51
+ model,
52
+ contents,
53
+ config
54
+ })).embeddings?.map((e) => e.values ?? []) ?? [],
55
+ usage: {
56
+ inputTokens: 0,
57
+ outputTokens: 0
58
+ },
59
+ model
60
+ };
61
+ }
62
+ };
63
+
64
+ //#endregion
65
+ export { GeminiEmbeddingModel };
66
+ //# sourceMappingURL=gemini-embedding-model.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini-embedding-model.mjs","names":[],"sources":["../src/gemini-embedding-model.ts"],"sourcesContent":["import {\n EmbeddingModel,\n type EmbeddingModelInput,\n type EmbeddingModelOptions,\n type EmbeddingModelOutput,\n embeddingModelInputSchema,\n type ModelInvokeOptions,\n} from \"@aigne/model-base\";\nimport { checkArguments } from \"@aigne/model-base/utils/type-utils\";\nimport { type EmbedContentConfig, GoogleGenAI } from \"@google/genai\";\nimport { z } from \"zod\";\n\nconst DEFAULT_MODEL = \"text-embedding-004\";\n\nexport interface GeminiEmbeddingModelInput extends EmbeddingModelInput {}\nexport interface GeminiEmbeddingModelOutput extends EmbeddingModelOutput {}\n\nexport interface GeminiEmbeddingModelOptions\n extends EmbeddingModelOptions<GeminiEmbeddingModelInput, GeminiEmbeddingModelOutput> {\n apiKey?: string;\n baseURL?: string;\n model?: string;\n clientOptions?: Record<string, any>;\n}\n\nconst geminiEmbeddingModelInputSchema = embeddingModelInputSchema.extend({});\n\nconst geminiEmbeddingModelOptionsSchema = z.object({\n apiKey: z.string().optional(),\n baseURL: z.string().optional(),\n model: z.string().optional(),\n modelOptions: z.object({}).optional(),\n clientOptions: z.object({}).optional(),\n});\n\nexport class GeminiEmbeddingModel extends EmbeddingModel<\n GeminiEmbeddingModelInput,\n GeminiEmbeddingModelOutput\n> {\n constructor(public override options?: GeminiEmbeddingModelOptions) {\n super({\n ...options,\n inputSchema: geminiEmbeddingModelInputSchema,\n description: options?.description ?? \"Generate embeddings by Gemini embedding models\",\n });\n if (options) checkArguments(this.name, geminiEmbeddingModelOptionsSchema, options);\n }\n\n protected _client?: GoogleGenAI;\n\n protected apiKeyEnvName = \"GEMINI_API_KEY\";\n\n get client() {\n if (this._client) return this._client;\n\n const { apiKey } = this.credential;\n\n if (!apiKey)\n throw new Error(\n `${this.name} requires an API key. Please provide it via \\`options.apiKey\\`, or set the \\`${this.apiKeyEnvName}\\` environment variable`,\n );\n\n this._client ??= new GoogleGenAI({ apiKey });\n\n return this._client;\n }\n\n override get credential() {\n return {\n url: this.options?.baseURL || process.env.GEMINI_BASE_URL,\n apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName],\n model: this.options?.model || DEFAULT_MODEL,\n };\n }\n\n override async process(\n input: GeminiEmbeddingModelInput,\n _options: ModelInvokeOptions,\n ): Promise<GeminiEmbeddingModelOutput> {\n const model = input.modelOptions?.model || this.credential.model;\n\n const contents = Array.isArray(input.input) ? input.input : [input.input];\n\n const config: EmbedContentConfig = {\n ...(input.dimensions ? { outputDimensionality: input.dimensions } : {}),\n ...(input.modelOptions?.taskType\n ? { taskType: input.modelOptions.taskType as string }\n : {}),\n };\n\n const response = await this.client.models.embedContent({\n model,\n contents,\n config,\n });\n\n return {\n embeddings: response.embeddings?.map((e) => e.values ?? []) ?? [],\n usage: {\n inputTokens: 0,\n outputTokens: 0,\n },\n model,\n };\n }\n}\n"],"mappings":";;;;;;AAYA,MAAM,gBAAgB;AAatB,MAAM,kCAAkC,0BAA0B,OAAO,EAAE,CAAC;AAE5E,MAAM,oCAAoC,EAAE,OAAO;CACjD,QAAQ,EAAE,QAAQ,CAAC,UAAU;CAC7B,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU;CAC5B,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC,UAAU;CACrC,eAAe,EAAE,OAAO,EAAE,CAAC,CAAC,UAAU;CACvC,CAAC;AAEF,IAAa,uBAAb,cAA0C,eAGxC;CACA,YAAY,AAAgB,SAAuC;AACjE,QAAM;GACJ,GAAG;GACH,aAAa;GACb,aAAa,SAAS,eAAe;GACtC,CAAC;EALwB;AAM1B,MAAI,QAAS,gBAAe,KAAK,MAAM,mCAAmC,QAAQ;;CAGpF,AAAU;CAEV,AAAU,gBAAgB;CAE1B,IAAI,SAAS;AACX,MAAI,KAAK,QAAS,QAAO,KAAK;EAE9B,MAAM,EAAE,WAAW,KAAK;AAExB,MAAI,CAAC,OACH,OAAM,IAAI,MACR,GAAG,KAAK,KAAK,+EAA+E,KAAK,cAAc,yBAChH;AAEH,OAAK,YAAY,IAAI,YAAY,EAAE,QAAQ,CAAC;AAE5C,SAAO,KAAK;;CAGd,IAAa,aAAa;AACxB,SAAO;GACL,KAAK,KAAK,SAAS,WAAW,QAAQ,IAAI;GAC1C,QAAQ,KAAK,SAAS,UAAU,QAAQ,IAAI,KAAK;GACjD,OAAO,KAAK,SAAS,SAAS;GAC/B;;CAGH,MAAe,QACb,OACA,UACqC;EACrC,MAAM,QAAQ,MAAM,cAAc,SAAS,KAAK,WAAW;EAE3D,MAAM,WAAW,MAAM,QAAQ,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,MAAM;EAEzE,MAAM,SAA6B;GACjC,GAAI,MAAM,aAAa,EAAE,sBAAsB,MAAM,YAAY,GAAG,EAAE;GACtE,GAAI,MAAM,cAAc,WACpB,EAAE,UAAU,MAAM,aAAa,UAAoB,GACnD,EAAE;GACP;AAQD,SAAO;GACL,aAPe,MAAM,KAAK,OAAO,OAAO,aAAa;IACrD;IACA;IACA;IACD,CAAC,EAGqB,YAAY,KAAK,MAAM,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE;GACjE,OAAO;IACL,aAAa;IACb,cAAc;IACf;GACD;GACD"}
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  const require_gemini_chat_model = require('./gemini-chat-model.cjs');
2
+ const require_gemini_embedding_model = require('./gemini-embedding-model.cjs');
2
3
  const require_gemini_image_model = require('./gemini-image-model.cjs');
3
4
  const require_gemini_video_model = require('./gemini-video-model.cjs');
4
5
 
5
6
  exports.GeminiChatModel = require_gemini_chat_model.GeminiChatModel;
7
+ exports.GeminiEmbeddingModel = require_gemini_embedding_model.GeminiEmbeddingModel;
6
8
  exports.GeminiImageModel = require_gemini_image_model.GeminiImageModel;
7
9
  exports.GeminiVideoModel = require_gemini_video_model.GeminiVideoModel;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { GeminiChatModel, GeminiChatModelOptions } from "./gemini-chat-model.cjs";
2
+ import { GeminiEmbeddingModel, GeminiEmbeddingModelInput, GeminiEmbeddingModelOptions, GeminiEmbeddingModelOutput } from "./gemini-embedding-model.cjs";
2
3
  import { GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput } from "./gemini-image-model.cjs";
3
4
  import { GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput } from "./gemini-video-model.cjs";
4
- export { GeminiChatModel, GeminiChatModelOptions, GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput, GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput };
5
+ export { GeminiChatModel, GeminiChatModelOptions, GeminiEmbeddingModel, GeminiEmbeddingModelInput, GeminiEmbeddingModelOptions, GeminiEmbeddingModelOutput, GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput, GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { GeminiChatModel, GeminiChatModelOptions } from "./gemini-chat-model.mjs";
2
+ import { GeminiEmbeddingModel, GeminiEmbeddingModelInput, GeminiEmbeddingModelOptions, GeminiEmbeddingModelOutput } from "./gemini-embedding-model.mjs";
2
3
  import { GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput } from "./gemini-image-model.mjs";
3
4
  import { GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput } from "./gemini-video-model.mjs";
4
- export { GeminiChatModel, GeminiChatModelOptions, GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput, GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput };
5
+ export { GeminiChatModel, GeminiChatModelOptions, GeminiEmbeddingModel, GeminiEmbeddingModelInput, GeminiEmbeddingModelOptions, GeminiEmbeddingModelOutput, GeminiImageModel, GeminiImageModelInput, GeminiImageModelOptions, GeminiImageModelOutput, GeminiVideoModel, GeminiVideoModelInput, GeminiVideoModelOptions, GeminiVideoModelOutput };
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { GeminiChatModel } from "./gemini-chat-model.mjs";
2
+ import { GeminiEmbeddingModel } from "./gemini-embedding-model.mjs";
2
3
  import { GeminiImageModel } from "./gemini-image-model.mjs";
3
4
  import { GeminiVideoModel } from "./gemini-video-model.mjs";
4
5
 
5
- export { GeminiChatModel, GeminiImageModel, GeminiVideoModel };
6
+ export { GeminiChatModel, GeminiEmbeddingModel, GeminiImageModel, GeminiVideoModel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/gemini",
3
- "version": "1.74.0-beta.8",
3
+ "version": "1.74.0-beta.9",
4
4
  "description": "AIGNE Gemini SDK for integrating with Google's Gemini AI models",
5
5
  "license": "Elastic-2.0",
6
6
  "publishConfig": {
@@ -38,7 +38,7 @@
38
38
  "yaml": "^2.8.1",
39
39
  "zod": "^3.25.67",
40
40
  "zod-to-json-schema": "^3.24.6",
41
- "@aigne/model-base": "^1.74.0-beta.8"
41
+ "@aigne/model-base": "^1.74.0-beta.9"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/bun": "^1.3.6",