ai-world-sdk 1.0.5 → 1.0.7

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/README.md CHANGED
@@ -98,7 +98,10 @@ console.log('图像 URL:', result.data[0]?.url);
98
98
  const geminiClient = new GeminiImageGenerationClient({});
99
99
  const geminiResult = await geminiClient.generate({
100
100
  prompt: 'A futuristic city',
101
+ model: 'gemini-3-pro-image-preview', // 使用 Gemini 3 Pro 模型
101
102
  aspect_ratio: '16:9',
103
+ image_size: '2K', // 仅适用于 gemini-3-pro-image-preview
104
+ response_modalities: ['IMAGE'], // 仅返回图片,不返回文本
102
105
  });
103
106
  console.log('图像 URL:', geminiResult.data[0]?.url);
104
107
  ```
@@ -211,15 +214,49 @@ const result = await client.generate({
211
214
  ```typescript
212
215
  const client = new GeminiImageGenerationClient({});
213
216
 
217
+ // 基础用法(使用 Gemini 2.5 Flash - 快速模型)
214
218
  const result = await client.generate({
215
219
  prompt: 'A beautiful landscape', // 必需
216
- model: 'gemini-2.0-flash-exp-image-generation', // 可选,默认值
217
- number_of_images: 1, // 可选
218
- aspect_ratio: '16:9', // 可选: 1:1, 9:16, 16:9, 4:3, 3:4
219
- temperature: 0.7, // 可选
220
+ model: 'gemini-2.5-flash-image', // 推荐:快速、高效
221
+ aspect_ratio: '16:9', // 可选: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
222
+ number_of_images: 1, // 可选: 1-4
223
+ });
224
+
225
+ // 高级用法(使用 Gemini 3 Pro - 专业模型,支持高分辨率)
226
+ const result2 = await client.generate({
227
+ prompt: 'A futuristic city at sunset',
228
+ model: 'gemini-3-pro-image-preview', // 专业级模型
229
+ aspect_ratio: '16:9',
230
+ image_size: '2K', // 可选: 1K, 2K, 4K(仅适用于 gemini-3-pro-image-preview)
231
+ number_of_images: 1,
232
+ response_modalities: ['IMAGE'], // 仅返回图片,不返回文本
233
+ temperature: 0.7, // 可选: 0.0-2.0
234
+ max_output_tokens: 1000, // 可选
220
235
  });
221
236
  ```
222
237
 
238
+ **参数说明:**
239
+
240
+ | 参数 | 类型 | 说明 | 默认值 |
241
+ |------|------|------|--------|
242
+ | `prompt` | `string` | 图像生成提示词(必需) | - |
243
+ | `model` | `string` | 模型名称 | `gemini-2.0-flash-exp-image-generation` |
244
+ | `aspect_ratio` | `string` | 宽高比 | - |
245
+ | `image_size` | `string` | 图片大小(仅 gemini-3-pro-image-preview) | - |
246
+ | `number_of_images` | `number` | 生成图片数量 | `1` |
247
+ | `response_modalities` | `array` | 响应模态 | `['TEXT', 'IMAGE']` |
248
+ | `temperature` | `number` | 温度参数 | `0.7` |
249
+ | `max_output_tokens` | `number` | 最大输出 token 数 | `1000` |
250
+
251
+ **支持的宽高比:** `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9`
252
+
253
+ **模型对比:**
254
+
255
+ | 模型 | 分辨率 | 特点 | 适用场景 |
256
+ |------|--------|------|----------|
257
+ | `gemini-2.5-flash-image` | 1024px | 快速、高效、成本低 | 日常使用、批量生成 |
258
+ | `gemini-3-pro-image-preview` | 1K/2K/4K | 专业级、高分辨率、高级功能 | 专业设计、高分辨率需求 |
259
+
223
260
  ### 视频生成
224
261
 
225
262
  #### VideoGenerationClient
@@ -444,6 +481,8 @@ const response = await modelWithTools.invoke([
444
481
 
445
482
  ### 图像生成工作流
446
483
 
484
+ #### 豆包图像生成
485
+
447
486
  ```typescript
448
487
  import { DoubaoImageGenerationClient } from 'ai-world-sdk';
449
488
 
@@ -470,6 +509,38 @@ multiResult.data.forEach((image, index) => {
470
509
  });
471
510
  ```
472
511
 
512
+ #### Gemini 图像生成
513
+
514
+ ```typescript
515
+ import { GeminiImageGenerationClient } from 'ai-world-sdk';
516
+
517
+ const client = new GeminiImageGenerationClient({});
518
+
519
+ // 使用 Gemini 2.5 Flash(快速模型)
520
+ const result = await client.generate({
521
+ prompt: 'A beautiful sunset over the ocean',
522
+ model: 'gemini-2.5-flash-image',
523
+ aspect_ratio: '16:9',
524
+ number_of_images: 1,
525
+ });
526
+
527
+ console.log('图像 URL:', result.data[0]?.url || 'Base64 编码');
528
+ if (result.text) {
529
+ console.log('图像描述:', result.text);
530
+ }
531
+
532
+ // 使用 Gemini 3 Pro(专业模型,支持高分辨率)
533
+ const result2 = await client.generate({
534
+ prompt: 'A futuristic city at night',
535
+ model: 'gemini-3-pro-image-preview',
536
+ aspect_ratio: '21:9', // 超宽屏
537
+ image_size: '4K', // 4K 分辨率
538
+ response_modalities: ['IMAGE'], // 仅返回图片
539
+ });
540
+
541
+ console.log('4K 图像:', result2.data[0]?.b64_json ? 'Base64 编码' : result2.data[0]?.url);
542
+ ```
543
+
473
544
  ### 视频生成工作流
474
545
 
475
546
  ```typescript
@@ -519,7 +590,14 @@ if (result.status === 'succeeded') {
519
590
  ### 图像生成模型
520
591
 
521
592
  - **豆包 Seedream**: `doubao-seedream-4-5-251128` (默认)
522
- - **Google Gemini**: `gemini-2.0-flash-exp-image-generation` (默认)
593
+ - **Google Gemini**:
594
+ - `gemini-2.5-flash-image` (Nano Banana) - **推荐**,快速、高效,1024px 分辨率,支持所有宽高比
595
+ - `gemini-3-pro-image-preview` (Nano Banana Pro) - 专业级,支持 1K/2K/4K 分辨率,支持 Google 搜索、思考模式,最多 14 张参考图片
596
+ - `gemini-2.0-flash-exp-image-generation` (已弃用,建议使用 `gemini-2.5-flash-image`)
597
+
598
+ **模型选择建议:**
599
+ - **日常使用**: `gemini-2.5-flash-image` - 速度快,成本低
600
+ - **专业需求**: `gemini-3-pro-image-preview` - 高分辨率、高级功能(需要 `image_size` 参数)
523
601
 
524
602
  ### 视频生成模型
525
603
 
@@ -589,10 +589,12 @@ describe("Langchain SDK Tests", () => {
589
589
  test("GeminiImageGenerationClient - 基础图像生成", async () => {
590
590
  const imageClient = new index_1.GeminiImageGenerationClient({});
591
591
  const result = await imageClient.generate({
592
- prompt: "A beautiful sunset over the ocean with vibrant colors",
593
- model: "gemini-2.0-flash-exp-image-generation",
592
+ prompt: 'A beautiful sunset over the ocean',
593
+ model: 'gemini-3-pro-image-preview',
594
+ aspect_ratio: '16:9',
595
+ image_size: '2K', // 仅适用于 gemini-3-pro-image-preview
594
596
  number_of_images: 1,
595
- aspect_ratio: "16:9",
597
+ response_modalities: ['IMAGE'], // 仅返回图片
596
598
  });
597
599
  expect(result).toBeDefined();
598
600
  expect(result.created).toBeDefined();
@@ -606,7 +608,7 @@ describe("Langchain SDK Tests", () => {
606
608
  });
607
609
  console.log("✅ GeminiImageGenerationClient 基础测试成功");
608
610
  console.log(`生成图像数量: ${result.data.length}`);
609
- console.log("图像 URL:", result.data[0]?.url || "Base64 编码");
611
+ console.log("图像 URL:", result.data[0]?.url || ("Base64 编码" + result.data[0]?.b64_json));
610
612
  if (result.text) {
611
613
  console.log("图像描述:", result.text);
612
614
  }
@@ -10,9 +10,11 @@ export interface GeminiImageGenerationRequest {
10
10
  prompt: string;
11
11
  model?: string;
12
12
  number_of_images?: number;
13
- aspect_ratio?: "1:1" | "9:16" | "16:9" | "4:3" | "3:4";
13
+ aspect_ratio?: "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4" | "9:16" | "16:9" | "21:9";
14
+ image_size?: "1K" | "2K" | "4K";
14
15
  temperature?: number;
15
16
  max_output_tokens?: number;
17
+ response_modalities?: ("TEXT" | "IMAGE")[];
16
18
  user?: string;
17
19
  }
18
20
  export interface GeminiImageData {
@@ -31,6 +33,12 @@ export declare class GeminiImageGenerationClient {
31
33
  /**
32
34
  * Generate images
33
35
  * 生成图像
36
+ *
37
+ * 支持的参数:
38
+ * - aspect_ratio: 宽高比,支持 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
39
+ * - image_size: 图片大小(仅 gemini-3-pro-image-preview),支持 1K, 2K, 4K
40
+ * - response_modalities: 响应模态,["TEXT", "IMAGE"] 或 ["IMAGE"]
41
+ * - number_of_images: 生成图片数量(1-4)
34
42
  */
35
43
  generate(request: GeminiImageGenerationRequest): Promise<GeminiImageGenerationResponse>;
36
44
  }
@@ -22,6 +22,12 @@ class GeminiImageGenerationClient {
22
22
  /**
23
23
  * Generate images
24
24
  * 生成图像
25
+ *
26
+ * 支持的参数:
27
+ * - aspect_ratio: 宽高比,支持 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
28
+ * - image_size: 图片大小(仅 gemini-3-pro-image-preview),支持 1K, 2K, 4K
29
+ * - response_modalities: 响应模态,["TEXT", "IMAGE"] 或 ["IMAGE"]
30
+ * - number_of_images: 生成图片数量(1-4)
25
31
  */
26
32
  async generate(request) {
27
33
  const requestBody = {
@@ -33,12 +39,18 @@ class GeminiImageGenerationClient {
33
39
  if (request.aspect_ratio) {
34
40
  requestBody.aspect_ratio = request.aspect_ratio;
35
41
  }
42
+ if (request.image_size) {
43
+ requestBody.image_size = request.image_size;
44
+ }
36
45
  if (request.temperature !== undefined) {
37
46
  requestBody.temperature = request.temperature;
38
47
  }
39
48
  if (request.max_output_tokens) {
40
49
  requestBody.max_output_tokens = request.max_output_tokens;
41
50
  }
51
+ if (request.response_modalities) {
52
+ requestBody.response_modalities = request.response_modalities;
53
+ }
42
54
  if (request.user) {
43
55
  requestBody.user = request.user;
44
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-world-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "TypeScript SDK for AI World Platform - Chat Models, Image Generation, and Video Generation",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",