@aigne/gemini 0.9.9 → 0.10.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 +27 -0
- package/lib/cjs/gemini-image-model.d.ts +53 -0
- package/lib/cjs/gemini-image-model.js +95 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/dts/gemini-image-model.d.ts +53 -0
- package/lib/dts/index.d.ts +1 -0
- package/lib/esm/gemini-image-model.d.ts +53 -0
- package/lib/esm/gemini-image-model.js +91 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.10.0](https://github.com/AIGNE-io/aigne-framework/compare/gemini-v0.9.10...gemini-v0.10.0) (2025-08-27)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **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))
|
|
9
|
+
* **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))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* The following workspace dependencies were updated
|
|
15
|
+
* dependencies
|
|
16
|
+
* @aigne/openai bumped to 0.13.0
|
|
17
|
+
|
|
18
|
+
## [0.9.10](https://github.com/AIGNE-io/aigne-framework/compare/gemini-v0.9.9...gemini-v0.9.10) (2025-08-26)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Dependencies
|
|
22
|
+
|
|
23
|
+
* The following workspace dependencies were updated
|
|
24
|
+
* dependencies
|
|
25
|
+
* @aigne/openai bumped to 0.12.4
|
|
26
|
+
* devDependencies
|
|
27
|
+
* @aigne/core bumped to 1.55.1
|
|
28
|
+
* @aigne/test-utils bumped to 0.5.36
|
|
29
|
+
|
|
3
30
|
## [0.9.9](https://github.com/AIGNE-io/aigne-framework/compare/gemini-v0.9.8...gemini-v0.9.9) (2025-08-25)
|
|
4
31
|
|
|
5
32
|
|
|
@@ -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
|
+
?.filter((image) => image.image?.imageBytes)
|
|
86
|
+
.map((image) => ({ base64: image.image?.imageBytes })) || [],
|
|
87
|
+
usage: {
|
|
88
|
+
inputTokens: 0,
|
|
89
|
+
outputTokens: 0,
|
|
90
|
+
},
|
|
91
|
+
model,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.GeminiImageModel = GeminiImageModel;
|
package/lib/cjs/index.d.ts
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -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
|
+
}
|
package/lib/dts/index.d.ts
CHANGED
|
@@ -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, 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
|
+
?.filter((image) => image.image?.imageBytes)
|
|
83
|
+
.map((image) => ({ base64: image.image?.imageBytes })) || [],
|
|
84
|
+
usage: {
|
|
85
|
+
inputTokens: 0,
|
|
86
|
+
outputTokens: 0,
|
|
87
|
+
},
|
|
88
|
+
model,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
package/lib/esm/index.d.ts
CHANGED
package/lib/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/gemini",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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
|
-
"@
|
|
38
|
+
"@google/genai": "^1.15.0",
|
|
39
|
+
"zod": "^3.25.67",
|
|
40
|
+
"@aigne/openai": "^0.13.0"
|
|
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/
|
|
47
|
-
"@aigne/
|
|
48
|
+
"@aigne/core": "^1.55.1",
|
|
49
|
+
"@aigne/test-utils": "^0.5.36"
|
|
48
50
|
},
|
|
49
51
|
"scripts": {
|
|
50
52
|
"lint": "tsc --noEmit",
|