@aigne/gemini 0.11.4 → 0.11.6

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,34 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.11.6](https://github.com/AIGNE-io/aigne-framework/compare/gemini-v0.11.5...gemini-v0.11.6) (2025-09-01)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **transport:** improve HTTP client option handling and error serialization ([#445](https://github.com/AIGNE-io/aigne-framework/issues/445)) ([d3bcdd2](https://github.com/AIGNE-io/aigne-framework/commit/d3bcdd23ab8011a7d40fc157fd61eb240494c7a5))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/openai bumped to 0.13.7
16
+ * devDependencies
17
+ * @aigne/core bumped to 1.57.5
18
+ * @aigne/test-utils bumped to 0.5.43
19
+
20
+ ## [0.11.5](https://github.com/AIGNE-io/aigne-framework/compare/gemini-v0.11.4...gemini-v0.11.5) (2025-08-30)
21
+
22
+
23
+ ### Dependencies
24
+
25
+ * The following workspace dependencies were updated
26
+ * dependencies
27
+ * @aigne/openai bumped to 0.13.6
28
+ * devDependencies
29
+ * @aigne/core bumped to 1.57.4
30
+ * @aigne/test-utils bumped to 0.5.42
31
+
3
32
  ## [0.11.4](https://github.com/AIGNE-io/aigne-framework/compare/gemini-v0.11.3...gemini-v0.11.4) (2025-08-30)
4
33
 
5
34
 
package/README.md CHANGED
@@ -23,13 +23,14 @@ AIGNE Gemini SDK for integrating with Google's Gemini AI models within the [AIGN
23
23
  <picture>
24
24
  <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/assets/aigne-gemini-dark.png" media="(prefers-color-scheme: dark)">
25
25
  <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/assets/aigne-gemini.png" media="(prefers-color-scheme: light)">
26
- <img src="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/aigne-gemini.png" alt="AIGNE Arch" />
26
+ <img src="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/assets/aigne-gemini.png" alt="AIGNE Arch" />
27
27
  </picture>
28
28
 
29
29
  ## Features
30
30
 
31
31
  * **Google Gemini API Integration**: Direct connection to Google's Gemini API services
32
32
  * **Chat Completions**: Support for Gemini's chat completions API with all available models
33
+ * **Image Generation**: Support for both Imagen and Gemini image generation models
33
34
  * **Multimodal Support**: Built-in support for handling both text and image inputs
34
35
  * **Function Calling**: Support for function calling capabilities
35
36
  * **Streaming Responses**: Support for streaming responses for more responsive applications
@@ -60,6 +61,8 @@ pnpm add @aigne/gemini @aigne/core
60
61
 
61
62
  ## Basic Usage
62
63
 
64
+ ### Chat Model
65
+
63
66
  ```typescript file="test/gemini-chat-model.test.ts" region="example-gemini-chat-model"
64
67
  import { GeminiChatModel } from "@aigne/gemini";
65
68
 
@@ -86,6 +89,38 @@ console.log(result);
86
89
  */
87
90
  ```
88
91
 
92
+ ### Image Generation Model
93
+
94
+ ```typescript
95
+ import { GeminiImageModel } from "@aigne/gemini";
96
+
97
+ const model = new GeminiImageModel({
98
+ apiKey: "your-api-key", // Optional if set in env variables
99
+ model: "imagen-4.0-generate-001", // Default Imagen model
100
+ });
101
+
102
+ const result = await model.invoke({
103
+ prompt: "A serene mountain landscape at sunset with golden light",
104
+ n: 1,
105
+ });
106
+
107
+ console.log(result);
108
+ /* Output:
109
+ {
110
+ images: [
111
+ {
112
+ base64: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
113
+ }
114
+ ],
115
+ usage: {
116
+ inputTokens: 0,
117
+ outputTokens: 0
118
+ },
119
+ model: "imagen-4.0-generate-001"
120
+ }
121
+ */
122
+ ```
123
+
89
124
  ## Streaming Responses
90
125
 
91
126
  ```typescript file="test/gemini-chat-model.test.ts" region="example-gemini-chat-model-streaming"
@@ -119,6 +154,90 @@ console.log(fullText); // Output: "Hello from Gemini! I'm Google's helpful AI as
119
154
  console.log(json); // { model: "gemini-1.5-flash" }
120
155
  ```
121
156
 
157
+ ## Image Generation Parameters
158
+
159
+ The `GeminiImageModel` supports different parameters depending on the model type:
160
+
161
+ ### Imagen Models (e.g., `imagen-4.0-generate-001`)
162
+
163
+ - **`prompt`** (string): The text description of the image you want to generate
164
+ - **`n`** (number): Number of images to generate (defaults to 1)
165
+ - **`seed`** (number): Random seed for reproducible generation
166
+ - **`safetyFilterLevel`** (string): Safety filter level for content moderation
167
+ - **`personGeneration`** (string): Person generation settings
168
+ - **`outputMimeType`** (string): Output image format (e.g., "image/png", "image/jpeg")
169
+ - **`outputGcsUri`** (string): Google Cloud Storage URI for output
170
+ - **`outputCompressionQuality`** (number): JPEG compression quality (1-100)
171
+ - **`negativePrompt`** (string): Description of what to exclude from the image
172
+ - **`language`** (string): Language for the prompt
173
+ - **`includeSafetyAttributes`** (boolean): Include safety attributes in response
174
+ - **`includeRaiReason`** (boolean): Include RAI reasoning in response
175
+ - **`imageSize`** (string): Size of the generated image
176
+ - **`guidanceScale`** (number): Guidance scale for generation
177
+ - **`aspectRatio`** (string): Aspect ratio of the image
178
+ - **`addWatermark`** (boolean): Add watermark to generated images
179
+
180
+ ### Gemini Models (e.g., `gemini-1.5-pro`)
181
+
182
+ - **`prompt`** (string): The text description of the image you want to generate
183
+ - **`n`** (number): Number of images to generate (defaults to 1)
184
+ - **`temperature`** (number): Controls randomness in generation (0.0 to 1.0)
185
+ - **`maxOutputTokens`** (number): Maximum number of tokens in response
186
+ - **`topP`** (number): Nucleus sampling parameter
187
+ - **`topK`** (number): Top-k sampling parameter
188
+ - **`safetySettings`** (array): Safety settings for content generation
189
+ - **`seed`** (number): Random seed for reproducible generation
190
+ - **`stopSequences`** (array): Sequences that stop generation
191
+ - **`systemInstruction`** (string): System-level instructions
192
+
193
+ ### Advanced Image Generation Example
194
+
195
+ ```typescript
196
+ const result = await model.invoke({
197
+ prompt: "A futuristic cityscape with neon lights and flying cars",
198
+ model: "imagen-4.0-generate-001",
199
+ n: 2,
200
+ imageSize: "1024x1024",
201
+ aspectRatio: "1:1",
202
+ guidanceScale: 7.5,
203
+ negativePrompt: "blurry, low quality, distorted",
204
+ seed: 12345,
205
+ includeSafetyAttributes: true,
206
+ outputMimeType: "image/png"
207
+ });
208
+ ```
209
+
210
+ ## Model Options
211
+
212
+ You can also set default options when creating the model:
213
+
214
+ ```typescript
215
+ const model = new GeminiImageModel({
216
+ apiKey: "your-api-key",
217
+ model: "imagen-4.0-generate-001",
218
+ modelOptions: {
219
+ safetyFilterLevel: "BLOCK_MEDIUM_AND_ABOVE",
220
+ includeSafetyAttributes: true,
221
+ outputMimeType: "image/png"
222
+ }
223
+ });
224
+ ```
225
+
226
+ ## Environment Variables
227
+
228
+ Set the following environment variable for automatic API key detection:
229
+
230
+ ```bash
231
+ export GEMINI_API_KEY="your-gemini-api-key"
232
+ ```
233
+
234
+ ## API Reference
235
+
236
+ For complete parameter details and advanced features:
237
+
238
+ - **Imagen Models**: Refer to [Google GenAI Models.generateImages()](https://googleapis.github.io/js-genai/release_docs/classes/models.Models.html#generateimages)
239
+ - **Gemini Models**: Refer to [Google GenAI Models.generateContent()](https://googleapis.github.io/js-genai/release_docs/classes/models.Models.html#generatecontent)
240
+
122
241
  ## License
123
242
 
124
243
  Elastic-2.0
@@ -142,8 +142,8 @@ class GeminiImageModel extends core_1.ImageModel {
142
142
  });
143
143
  const allImages = (response.candidates ?? [])
144
144
  .flatMap((candidate) => candidate.content?.parts ?? [])
145
- .filter((part) => part?.inlineData?.data)
146
- .map((part) => ({ base64: part.inlineData.data }));
145
+ .map((part) => (part.inlineData?.data ? { base64: part.inlineData?.data } : null))
146
+ .filter(type_utils_js_1.isNonNullable);
147
147
  return {
148
148
  images: allImages,
149
149
  usage: {
@@ -139,8 +139,8 @@ export class GeminiImageModel extends ImageModel {
139
139
  });
140
140
  const allImages = (response.candidates ?? [])
141
141
  .flatMap((candidate) => candidate.content?.parts ?? [])
142
- .filter((part) => part?.inlineData?.data)
143
- .map((part) => ({ base64: part.inlineData.data }));
142
+ .map((part) => (part.inlineData?.data ? { base64: part.inlineData?.data } : null))
143
+ .filter(isNonNullable);
144
144
  return {
145
145
  images: allImages,
146
146
  usage: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/gemini",
3
- "version": "0.11.4",
3
+ "version": "0.11.6",
4
4
  "description": "AIGNE Gemini SDK for integrating with Google's Gemini AI models",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@google/genai": "^1.15.0",
39
39
  "zod": "^3.25.67",
40
- "@aigne/openai": "^0.13.5"
40
+ "@aigne/openai": "^0.13.7"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/bun": "^1.2.18",
@@ -45,8 +45,8 @@
45
45
  "npm-run-all": "^4.1.5",
46
46
  "rimraf": "^6.0.1",
47
47
  "typescript": "^5.8.3",
48
- "@aigne/core": "^1.57.3",
49
- "@aigne/test-utils": "^0.5.41"
48
+ "@aigne/test-utils": "^0.5.43",
49
+ "@aigne/core": "^1.57.5"
50
50
  },
51
51
  "scripts": {
52
52
  "lint": "tsc --noEmit",