@aigne/gemini 0.9.10 → 0.11.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/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.11.0](https://github.com/AIGNE-io/aigne-framework/compare/gemini-v0.10.0...gemini-v0.11.0) (2025-08-27)
4
+
5
+
6
+ ### Features
7
+
8
+ * **models:** support aigne hub models ([#416](https://github.com/AIGNE-io/aigne-framework/issues/416)) ([b4f014c](https://github.com/AIGNE-io/aigne-framework/commit/b4f014cf5ed08ef930d3ddfc278d3610e64c6af3))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/openai bumped to 0.13.1
16
+ * devDependencies
17
+ * @aigne/core bumped to 1.56.0
18
+ * @aigne/test-utils bumped to 0.5.37
19
+
20
+ ## [0.10.0](https://github.com/AIGNE-io/aigne-framework/compare/gemini-v0.9.10...gemini-v0.10.0) (2025-08-27)
21
+
22
+
23
+ ### Features
24
+
25
+ * **models:** support gemini and ideogram images models ([#412](https://github.com/AIGNE-io/aigne-framework/issues/412)) ([6534fec](https://github.com/AIGNE-io/aigne-framework/commit/6534fecb0bdfb4b0a4440d44c0e563b9a029a68f))
26
+ * **models:** support gemini and ideogram images models ([#412](https://github.com/AIGNE-io/aigne-framework/issues/412)) ([6534fec](https://github.com/AIGNE-io/aigne-framework/commit/6534fecb0bdfb4b0a4440d44c0e563b9a029a68f))
27
+
28
+
29
+ ### Dependencies
30
+
31
+ * The following workspace dependencies were updated
32
+ * dependencies
33
+ * @aigne/openai bumped to 0.13.0
34
+
3
35
  ## [0.9.10](https://github.com/AIGNE-io/aigne-framework/compare/gemini-v0.9.9...gemini-v0.9.10) (2025-08-26)
4
36
 
5
37
 
@@ -0,0 +1,53 @@
1
+ import { ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
2
+ import { type GenerateImagesConfig, GoogleGenAI } from "@google/genai";
3
+ export interface GeminiImageModelInput extends ImageModelInput, GenerateImagesConfig {
4
+ }
5
+ export interface GeminiImageModelOutput extends ImageModelOutput {
6
+ }
7
+ export interface GeminiImageModelOptions extends ImageModelOptions<GeminiImageModelInput, GeminiImageModelOutput> {
8
+ /**
9
+ * API key for Gemini API
10
+ *
11
+ * If not provided, will look for GEMINI_API_KEY in environment variables
12
+ */
13
+ apiKey?: string;
14
+ /**
15
+ * Base URL for Gemini API
16
+ *
17
+ * Useful for proxies or alternate endpoints
18
+ */
19
+ baseURL?: string;
20
+ /**
21
+ * Gemini model to use
22
+ *
23
+ * Defaults to 'gemini-2.0-flash'
24
+ */
25
+ model?: string;
26
+ /**
27
+ * Additional model options to control behavior
28
+ */
29
+ modelOptions?: Omit<Partial<GeminiImageModelInput>, "model">;
30
+ /**
31
+ * Client options for Gemini API
32
+ */
33
+ clientOptions?: Record<string, any>;
34
+ }
35
+ export declare class GeminiImageModel extends ImageModel<GeminiImageModelInput, GeminiImageModelOutput> {
36
+ options?: GeminiImageModelOptions | undefined;
37
+ constructor(options?: GeminiImageModelOptions | undefined);
38
+ protected _client?: GoogleGenAI;
39
+ protected apiKeyEnvName: string;
40
+ get client(): GoogleGenAI;
41
+ get credential(): {
42
+ url: string | undefined;
43
+ apiKey: string | undefined;
44
+ model: string;
45
+ };
46
+ get modelOptions(): Omit<Partial<GeminiImageModelInput>, "model"> | undefined;
47
+ /**
48
+ * Process the input and generate a response
49
+ * @param input The input to process
50
+ * @returns The generated response
51
+ */
52
+ process(input: GeminiImageModelInput): Promise<ImageModelOutput>;
53
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeminiImageModel = void 0;
4
+ const core_1 = require("@aigne/core");
5
+ const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
6
+ const genai_1 = require("@google/genai");
7
+ const zod_1 = require("zod");
8
+ const DEFAULT_MODEL = "imagen-4.0-generate-001";
9
+ const geminiImageModelInputSchema = core_1.imageModelInputSchema.extend({});
10
+ const geminiImageModelOptionsSchema = zod_1.z.object({
11
+ apiKey: zod_1.z.string().optional(),
12
+ baseURL: zod_1.z.string().optional(),
13
+ model: zod_1.z.string().optional(),
14
+ modelOptions: zod_1.z.object({}).optional(),
15
+ clientOptions: zod_1.z.object({}).optional(),
16
+ });
17
+ class GeminiImageModel extends core_1.ImageModel {
18
+ options;
19
+ constructor(options) {
20
+ super({
21
+ ...options,
22
+ inputSchema: geminiImageModelInputSchema,
23
+ description: options?.description ?? "Draw or edit image by Gemini image models",
24
+ });
25
+ this.options = options;
26
+ if (options)
27
+ (0, type_utils_js_1.checkArguments)(this.name, geminiImageModelOptionsSchema, options);
28
+ }
29
+ _client;
30
+ apiKeyEnvName = "GEMINI_API_KEY";
31
+ get client() {
32
+ if (this._client)
33
+ return this._client;
34
+ const { apiKey } = this.credential;
35
+ if (!apiKey)
36
+ throw new Error(`${this.name} requires an API key. Please provide it via \`options.apiKey\`, or set the \`${this.apiKeyEnvName}\` environment variable`);
37
+ this._client ??= new genai_1.GoogleGenAI({ apiKey });
38
+ return this._client;
39
+ }
40
+ get credential() {
41
+ return {
42
+ url: this.options?.baseURL || process.env.GEMINI_BASE_URL,
43
+ apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName],
44
+ model: this.options?.model || DEFAULT_MODEL,
45
+ };
46
+ }
47
+ get modelOptions() {
48
+ return this.options?.modelOptions;
49
+ }
50
+ /**
51
+ * Process the input and generate a response
52
+ * @param input The input to process
53
+ * @returns The generated response
54
+ */
55
+ async process(input) {
56
+ const model = input.model || this.credential.model;
57
+ const responseFormat = input.responseFormat || "base64";
58
+ if (responseFormat === "url") {
59
+ throw new Error("Gemini image models currently only support base64 format");
60
+ }
61
+ const mergedInput = { ...this.modelOptions, ...input };
62
+ const inputKeys = [
63
+ "seed",
64
+ "safetyFilterLevel",
65
+ "personGeneration",
66
+ "outputMimeType",
67
+ "outputGcsUri",
68
+ "outputCompressionQuality",
69
+ "negativePrompt",
70
+ "language",
71
+ "includeSafetyAttributes",
72
+ "includeRaiReason",
73
+ "imageSize",
74
+ "guidanceScale",
75
+ "aspectRatio",
76
+ "addWatermark",
77
+ ];
78
+ const response = await this.client.models.generateImages({
79
+ model: model,
80
+ prompt: mergedInput.prompt,
81
+ config: { numberOfImages: mergedInput.n || 1, ...(0, type_utils_js_1.pick)(mergedInput, inputKeys) },
82
+ });
83
+ return {
84
+ images: response.generatedImages
85
+ ?.map(({ image }) => (image?.imageBytes ? { base64: image.imageBytes } : undefined))
86
+ .filter(type_utils_js_1.isNonNullable) || [],
87
+ usage: {
88
+ inputTokens: 0,
89
+ outputTokens: 0,
90
+ },
91
+ model,
92
+ };
93
+ }
94
+ }
95
+ exports.GeminiImageModel = GeminiImageModel;
@@ -1 +1,2 @@
1
1
  export * from "./gemini-chat-model.js";
2
+ export * from "./gemini-image-model.js";
package/lib/cjs/index.js CHANGED
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./gemini-chat-model.js"), exports);
18
+ __exportStar(require("./gemini-image-model.js"), exports);
@@ -0,0 +1,53 @@
1
+ import { ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
2
+ import { type GenerateImagesConfig, GoogleGenAI } from "@google/genai";
3
+ export interface GeminiImageModelInput extends ImageModelInput, GenerateImagesConfig {
4
+ }
5
+ export interface GeminiImageModelOutput extends ImageModelOutput {
6
+ }
7
+ export interface GeminiImageModelOptions extends ImageModelOptions<GeminiImageModelInput, GeminiImageModelOutput> {
8
+ /**
9
+ * API key for Gemini API
10
+ *
11
+ * If not provided, will look for GEMINI_API_KEY in environment variables
12
+ */
13
+ apiKey?: string;
14
+ /**
15
+ * Base URL for Gemini API
16
+ *
17
+ * Useful for proxies or alternate endpoints
18
+ */
19
+ baseURL?: string;
20
+ /**
21
+ * Gemini model to use
22
+ *
23
+ * Defaults to 'gemini-2.0-flash'
24
+ */
25
+ model?: string;
26
+ /**
27
+ * Additional model options to control behavior
28
+ */
29
+ modelOptions?: Omit<Partial<GeminiImageModelInput>, "model">;
30
+ /**
31
+ * Client options for Gemini API
32
+ */
33
+ clientOptions?: Record<string, any>;
34
+ }
35
+ export declare class GeminiImageModel extends ImageModel<GeminiImageModelInput, GeminiImageModelOutput> {
36
+ options?: GeminiImageModelOptions | undefined;
37
+ constructor(options?: GeminiImageModelOptions | undefined);
38
+ protected _client?: GoogleGenAI;
39
+ protected apiKeyEnvName: string;
40
+ get client(): GoogleGenAI;
41
+ get credential(): {
42
+ url: string | undefined;
43
+ apiKey: string | undefined;
44
+ model: string;
45
+ };
46
+ get modelOptions(): Omit<Partial<GeminiImageModelInput>, "model"> | undefined;
47
+ /**
48
+ * Process the input and generate a response
49
+ * @param input The input to process
50
+ * @returns The generated response
51
+ */
52
+ process(input: GeminiImageModelInput): Promise<ImageModelOutput>;
53
+ }
@@ -1 +1,2 @@
1
1
  export * from "./gemini-chat-model.js";
2
+ export * from "./gemini-image-model.js";
@@ -0,0 +1,53 @@
1
+ import { ImageModel, type ImageModelInput, type ImageModelOptions, type ImageModelOutput } from "@aigne/core";
2
+ import { type GenerateImagesConfig, GoogleGenAI } from "@google/genai";
3
+ export interface GeminiImageModelInput extends ImageModelInput, GenerateImagesConfig {
4
+ }
5
+ export interface GeminiImageModelOutput extends ImageModelOutput {
6
+ }
7
+ export interface GeminiImageModelOptions extends ImageModelOptions<GeminiImageModelInput, GeminiImageModelOutput> {
8
+ /**
9
+ * API key for Gemini API
10
+ *
11
+ * If not provided, will look for GEMINI_API_KEY in environment variables
12
+ */
13
+ apiKey?: string;
14
+ /**
15
+ * Base URL for Gemini API
16
+ *
17
+ * Useful for proxies or alternate endpoints
18
+ */
19
+ baseURL?: string;
20
+ /**
21
+ * Gemini model to use
22
+ *
23
+ * Defaults to 'gemini-2.0-flash'
24
+ */
25
+ model?: string;
26
+ /**
27
+ * Additional model options to control behavior
28
+ */
29
+ modelOptions?: Omit<Partial<GeminiImageModelInput>, "model">;
30
+ /**
31
+ * Client options for Gemini API
32
+ */
33
+ clientOptions?: Record<string, any>;
34
+ }
35
+ export declare class GeminiImageModel extends ImageModel<GeminiImageModelInput, GeminiImageModelOutput> {
36
+ options?: GeminiImageModelOptions | undefined;
37
+ constructor(options?: GeminiImageModelOptions | undefined);
38
+ protected _client?: GoogleGenAI;
39
+ protected apiKeyEnvName: string;
40
+ get client(): GoogleGenAI;
41
+ get credential(): {
42
+ url: string | undefined;
43
+ apiKey: string | undefined;
44
+ model: string;
45
+ };
46
+ get modelOptions(): Omit<Partial<GeminiImageModelInput>, "model"> | undefined;
47
+ /**
48
+ * Process the input and generate a response
49
+ * @param input The input to process
50
+ * @returns The generated response
51
+ */
52
+ process(input: GeminiImageModelInput): Promise<ImageModelOutput>;
53
+ }
@@ -0,0 +1,91 @@
1
+ import { ImageModel, imageModelInputSchema, } from "@aigne/core";
2
+ import { checkArguments, isNonNullable, pick } from "@aigne/core/utils/type-utils.js";
3
+ import { GoogleGenAI } from "@google/genai";
4
+ import { z } from "zod";
5
+ const DEFAULT_MODEL = "imagen-4.0-generate-001";
6
+ const geminiImageModelInputSchema = imageModelInputSchema.extend({});
7
+ const geminiImageModelOptionsSchema = z.object({
8
+ apiKey: z.string().optional(),
9
+ baseURL: z.string().optional(),
10
+ model: z.string().optional(),
11
+ modelOptions: z.object({}).optional(),
12
+ clientOptions: z.object({}).optional(),
13
+ });
14
+ export class GeminiImageModel extends ImageModel {
15
+ options;
16
+ constructor(options) {
17
+ super({
18
+ ...options,
19
+ inputSchema: geminiImageModelInputSchema,
20
+ description: options?.description ?? "Draw or edit image by Gemini image models",
21
+ });
22
+ this.options = options;
23
+ if (options)
24
+ checkArguments(this.name, geminiImageModelOptionsSchema, options);
25
+ }
26
+ _client;
27
+ apiKeyEnvName = "GEMINI_API_KEY";
28
+ get client() {
29
+ if (this._client)
30
+ return this._client;
31
+ const { apiKey } = this.credential;
32
+ if (!apiKey)
33
+ throw new Error(`${this.name} requires an API key. Please provide it via \`options.apiKey\`, or set the \`${this.apiKeyEnvName}\` environment variable`);
34
+ this._client ??= new GoogleGenAI({ apiKey });
35
+ return this._client;
36
+ }
37
+ get credential() {
38
+ return {
39
+ url: this.options?.baseURL || process.env.GEMINI_BASE_URL,
40
+ apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName],
41
+ model: this.options?.model || DEFAULT_MODEL,
42
+ };
43
+ }
44
+ get modelOptions() {
45
+ return this.options?.modelOptions;
46
+ }
47
+ /**
48
+ * Process the input and generate a response
49
+ * @param input The input to process
50
+ * @returns The generated response
51
+ */
52
+ async process(input) {
53
+ const model = input.model || this.credential.model;
54
+ const responseFormat = input.responseFormat || "base64";
55
+ if (responseFormat === "url") {
56
+ throw new Error("Gemini image models currently only support base64 format");
57
+ }
58
+ const mergedInput = { ...this.modelOptions, ...input };
59
+ const inputKeys = [
60
+ "seed",
61
+ "safetyFilterLevel",
62
+ "personGeneration",
63
+ "outputMimeType",
64
+ "outputGcsUri",
65
+ "outputCompressionQuality",
66
+ "negativePrompt",
67
+ "language",
68
+ "includeSafetyAttributes",
69
+ "includeRaiReason",
70
+ "imageSize",
71
+ "guidanceScale",
72
+ "aspectRatio",
73
+ "addWatermark",
74
+ ];
75
+ const response = await this.client.models.generateImages({
76
+ model: model,
77
+ prompt: mergedInput.prompt,
78
+ config: { numberOfImages: mergedInput.n || 1, ...pick(mergedInput, inputKeys) },
79
+ });
80
+ return {
81
+ images: response.generatedImages
82
+ ?.map(({ image }) => (image?.imageBytes ? { base64: image.imageBytes } : undefined))
83
+ .filter(isNonNullable) || [],
84
+ usage: {
85
+ inputTokens: 0,
86
+ outputTokens: 0,
87
+ },
88
+ model,
89
+ };
90
+ }
91
+ }
@@ -1 +1,2 @@
1
1
  export * from "./gemini-chat-model.js";
2
+ export * from "./gemini-image-model.js";
package/lib/esm/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./gemini-chat-model.js";
2
+ export * from "./gemini-image-model.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/gemini",
3
- "version": "0.9.10",
3
+ "version": "0.11.0",
4
4
  "description": "AIGNE Gemini SDK for integrating with Google's Gemini AI models",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -35,7 +35,9 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@aigne/openai": "^0.12.4"
38
+ "@google/genai": "^1.15.0",
39
+ "zod": "^3.25.67",
40
+ "@aigne/openai": "^0.13.1"
39
41
  },
40
42
  "devDependencies": {
41
43
  "@types/bun": "^1.2.18",
@@ -43,8 +45,8 @@
43
45
  "npm-run-all": "^4.1.5",
44
46
  "rimraf": "^6.0.1",
45
47
  "typescript": "^5.8.3",
46
- "@aigne/core": "^1.55.1",
47
- "@aigne/test-utils": "^0.5.36"
48
+ "@aigne/core": "^1.56.0",
49
+ "@aigne/test-utils": "^0.5.37"
48
50
  },
49
51
  "scripts": {
50
52
  "lint": "tsc --noEmit",