ai-world-sdk 1.0.9 → 1.0.10
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 +84 -7
- package/dist/__tests__/example.test.js +5 -2
- package/dist/doubao-image-generation.d.ts +11 -3
- package/dist/doubao-image-generation.js +28 -8
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ import { DoubaoImageGenerationClient, GeminiImageGenerationClient } from 'ai-wor
|
|
|
88
88
|
const doubaoClient = new DoubaoImageGenerationClient({});
|
|
89
89
|
const result = await doubaoClient.generate({
|
|
90
90
|
prompt: 'A beautiful sunset over the ocean',
|
|
91
|
-
size: '2K',
|
|
91
|
+
size: '2K', // 或使用 '2K', '4K' 等
|
|
92
92
|
quality: 'hd',
|
|
93
93
|
n: 1,
|
|
94
94
|
});
|
|
@@ -200,7 +200,7 @@ const client = new DoubaoImageGenerationClient({});
|
|
|
200
200
|
const result = await client.generate({
|
|
201
201
|
prompt: 'A beautiful landscape', // 必需
|
|
202
202
|
model: 'doubao-seedream-4-5-251128', // 可选,默认值
|
|
203
|
-
size: '2K',
|
|
203
|
+
size: '2K', // 可选: 像素值(2048x2048, 2560x1440等)或K值(1K, 2K, 4K)
|
|
204
204
|
quality: 'hd', // 可选: standard, hd
|
|
205
205
|
n: 1, // 可选: 1-10
|
|
206
206
|
response_format: 'url', // 可选: url, b64_json
|
|
@@ -556,6 +556,27 @@ const response = await modelWithTools.invoke([
|
|
|
556
556
|
|
|
557
557
|
#### 豆包图像生成
|
|
558
558
|
|
|
559
|
+
豆包 Seedream 支持多种图像生成模式:
|
|
560
|
+
|
|
561
|
+
**支持的尺寸选项:**
|
|
562
|
+
|
|
563
|
+
- **像素值(宽x高)**:
|
|
564
|
+
- `2048x2048` (1:1 正方形)
|
|
565
|
+
- `2304x1728` (4:3 横屏)
|
|
566
|
+
- `1728x2304` (3:4 竖屏)
|
|
567
|
+
- `2560x1440` (16:9 横屏)
|
|
568
|
+
- `1440x2560` (9:16 竖屏)
|
|
569
|
+
- `2496x1664` (3:2 横屏)
|
|
570
|
+
- `1664x2496` (2:3 竖屏)
|
|
571
|
+
- `3024x1296` (21:9 超宽屏)
|
|
572
|
+
|
|
573
|
+
- **K 值(根据模型版本)**:
|
|
574
|
+
- `1K` - 仅 4.0 版本支持
|
|
575
|
+
- `2K` - 4.0 和 4.5 版本支持
|
|
576
|
+
- `4K` - 4.0 和 4.5 版本支持
|
|
577
|
+
|
|
578
|
+
**1. 文生图(文本生成图像)**
|
|
579
|
+
|
|
559
580
|
```typescript
|
|
560
581
|
import { DoubaoImageGenerationClient } from 'ai-world-sdk';
|
|
561
582
|
|
|
@@ -564,17 +585,58 @@ const client = new DoubaoImageGenerationClient({});
|
|
|
564
585
|
// 生成单张图像
|
|
565
586
|
const result = await client.generate({
|
|
566
587
|
prompt: 'A futuristic city skyline at sunset',
|
|
567
|
-
size: '2K',
|
|
588
|
+
size: '2048x2048', // 1:1 正方形,或使用 '2K', '4K' 等
|
|
568
589
|
quality: 'hd',
|
|
569
590
|
});
|
|
570
591
|
|
|
571
592
|
console.log('图像 URL:', result.data[0]?.url);
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
**2. 图文生图(单图输入单图输出)**
|
|
596
|
+
|
|
597
|
+
基于一张参考图片生成新图像:
|
|
598
|
+
|
|
599
|
+
```typescript
|
|
600
|
+
// 使用单张图片作为输入
|
|
601
|
+
const result = await client.generate({
|
|
602
|
+
prompt: '将这张图片转换为水彩画风格',
|
|
603
|
+
image: 'data:image/png;base64,iVBORw0KGgo...', // base64 编码的图片或 data URL
|
|
604
|
+
size: '2560x1440', // 16:9 横屏
|
|
605
|
+
quality: 'hd',
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
console.log('生成的图像 URL:', result.data[0]?.url);
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
**3. 多图融合(多图输入单图输出)**
|
|
612
|
+
|
|
613
|
+
融合多张参考图片生成新图像:
|
|
572
614
|
|
|
573
|
-
|
|
615
|
+
```typescript
|
|
616
|
+
// 使用多张图片作为输入
|
|
617
|
+
const result = await client.generate({
|
|
618
|
+
prompt: '将图1的服装换为图2的服装风格',
|
|
619
|
+
image: [
|
|
620
|
+
'data:image/png;base64,iVBORw0KGgo...', // 第一张图片
|
|
621
|
+
'data:image/png;base64,iVBORw0KGgo...', // 第二张图片
|
|
622
|
+
],
|
|
623
|
+
size: '2048x2048', // 1:1 正方形
|
|
624
|
+
quality: 'hd',
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
console.log('融合后的图像 URL:', result.data[0]?.url);
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
**4. 组图输出(多图输出)**
|
|
631
|
+
|
|
632
|
+
一次生成多张不同风格的图像:
|
|
633
|
+
|
|
634
|
+
```typescript
|
|
635
|
+
// 生成多张图像(组图输出)
|
|
574
636
|
const multiResult = await client.generate({
|
|
575
637
|
prompt: 'A beautiful landscape',
|
|
576
|
-
n: 3,
|
|
577
|
-
size: '
|
|
638
|
+
n: 3, // 生成 3 张图像
|
|
639
|
+
size: '2560x1440', // 16:9 横屏
|
|
578
640
|
});
|
|
579
641
|
|
|
580
642
|
multiResult.data.forEach((image, index) => {
|
|
@@ -582,6 +644,19 @@ multiResult.data.forEach((image, index) => {
|
|
|
582
644
|
});
|
|
583
645
|
```
|
|
584
646
|
|
|
647
|
+
**组合使用示例**
|
|
648
|
+
|
|
649
|
+
```typescript
|
|
650
|
+
// 图文生图 + 组图输出:基于一张图片生成多张不同风格的图像
|
|
651
|
+
const result = await client.generate({
|
|
652
|
+
prompt: '生成不同风格的艺术作品',
|
|
653
|
+
image: 'data:image/png;base64,iVBORw0KGgo...',
|
|
654
|
+
n: 4, // 生成 4 张不同风格的图像
|
|
655
|
+
size: '2048x2048', // 1:1 正方形
|
|
656
|
+
quality: 'hd',
|
|
657
|
+
});
|
|
658
|
+
```
|
|
659
|
+
|
|
585
660
|
#### Gemini 图像生成
|
|
586
661
|
|
|
587
662
|
```typescript
|
|
@@ -662,7 +737,9 @@ if (result.status === 'succeeded') {
|
|
|
662
737
|
|
|
663
738
|
### 图像生成模型
|
|
664
739
|
|
|
665
|
-
- **豆包 Seedream**:
|
|
740
|
+
- **豆包 Seedream**:
|
|
741
|
+
- `doubao-seedream-4-5-251128` (4.5版本,默认) - 支持 2K、4K 和像素值尺寸
|
|
742
|
+
- `doubao-seedream-4-0` (4.0版本) - 支持 1K、2K、4K 和像素值尺寸
|
|
666
743
|
- **Google Gemini**:
|
|
667
744
|
- `gemini-2.5-flash-image` (Nano Banana) - **推荐**,快速、高效,1024px 分辨率,支持所有宽高比
|
|
668
745
|
- `gemini-3-pro-image-preview` (Nano Banana Pro) - 专业级,支持 1K/2K/4K 分辨率,支持 Google 搜索、思考模式,最多 14 张参考图片
|
|
@@ -267,7 +267,7 @@ describe("Langchain SDK Tests", () => {
|
|
|
267
267
|
expect(result.data).toBeDefined();
|
|
268
268
|
expect(Array.isArray(result.data)).toBe(true);
|
|
269
269
|
expect(result.data.length).toBe(2);
|
|
270
|
-
console.log("✅
|
|
270
|
+
console.log("✅ 多图像生成测试成功(组图输出)");
|
|
271
271
|
console.log(`生成图像数量: ${result.data.length}`);
|
|
272
272
|
result.data.forEach((item, index) => {
|
|
273
273
|
console.log(`图像 ${index + 1}:`, item.url || "Base64 编码");
|
|
@@ -275,7 +275,10 @@ describe("Langchain SDK Tests", () => {
|
|
|
275
275
|
}, 120000);
|
|
276
276
|
test("DoubaoImageGenerationClient - 不同尺寸测试", async () => {
|
|
277
277
|
const imageClient = new index_1.DoubaoImageGenerationClient({});
|
|
278
|
-
const sizes = [
|
|
278
|
+
const sizes = [
|
|
279
|
+
"2K",
|
|
280
|
+
"4K",
|
|
281
|
+
];
|
|
279
282
|
for (const size of sizes) {
|
|
280
283
|
const result = await imageClient.generate({
|
|
281
284
|
prompt: "A futuristic city skyline at sunset",
|
|
@@ -6,16 +6,24 @@ export interface DoubaoImageGenerationConfig {
|
|
|
6
6
|
baseUrl?: string;
|
|
7
7
|
headers?: Record<string, string>;
|
|
8
8
|
}
|
|
9
|
+
export type DoubaoImageSize = "2048x2048" | "2304x1728" | "1728x2304" | "2560x1440" | "1440x2560" | "2496x1664" | "1664x2496" | "3024x1296" | "1K" | "2K" | "4K";
|
|
9
10
|
export interface DoubaoImageGenerationRequest {
|
|
10
11
|
model?: string;
|
|
11
12
|
prompt: string;
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
background?: "transparent" | "opaque" | "auto";
|
|
14
|
+
moderation?: "low" | "auto";
|
|
14
15
|
n?: number;
|
|
15
|
-
|
|
16
|
+
output_compression?: number;
|
|
17
|
+
output_format?: "png" | "jpeg" | "webp";
|
|
18
|
+
partial_images?: number;
|
|
19
|
+
quality?: "standard" | "hd" | "low" | "medium" | "high" | "auto";
|
|
16
20
|
response_format?: "url" | "b64_json";
|
|
21
|
+
size?: DoubaoImageSize;
|
|
22
|
+
stream?: false;
|
|
17
23
|
style?: "vivid" | "natural";
|
|
24
|
+
image?: string | string[];
|
|
18
25
|
user?: string;
|
|
26
|
+
watermark?: boolean;
|
|
19
27
|
}
|
|
20
28
|
export interface DoubaoImageData {
|
|
21
29
|
url?: string;
|
|
@@ -27,25 +27,45 @@ class DoubaoImageGenerationClient {
|
|
|
27
27
|
const requestBody = {
|
|
28
28
|
model: request.model || "doubao-seedream-4-5-251128",
|
|
29
29
|
prompt: request.prompt,
|
|
30
|
-
size: request.size || "
|
|
30
|
+
size: request.size || "2048x2048",
|
|
31
31
|
n: request.n || 1,
|
|
32
32
|
};
|
|
33
|
-
//
|
|
34
|
-
if (request.
|
|
35
|
-
requestBody.
|
|
33
|
+
// 添加可选参数(按照 OpenAI SDK 参数顺序)
|
|
34
|
+
if (request.background !== undefined) {
|
|
35
|
+
requestBody.background = request.background;
|
|
36
36
|
}
|
|
37
|
-
if (request.
|
|
37
|
+
if (request.moderation !== undefined) {
|
|
38
|
+
requestBody.moderation = request.moderation;
|
|
39
|
+
}
|
|
40
|
+
if (request.output_compression !== undefined) {
|
|
41
|
+
requestBody.output_compression = request.output_compression;
|
|
42
|
+
}
|
|
43
|
+
if (request.output_format !== undefined) {
|
|
44
|
+
requestBody.output_format = request.output_format;
|
|
45
|
+
}
|
|
46
|
+
if (request.partial_images !== undefined) {
|
|
47
|
+
requestBody.partial_images = request.partial_images;
|
|
48
|
+
}
|
|
49
|
+
if (request.quality !== undefined) {
|
|
38
50
|
requestBody.quality = request.quality;
|
|
39
51
|
}
|
|
40
|
-
if (request.response_format) {
|
|
52
|
+
if (request.response_format !== undefined) {
|
|
41
53
|
requestBody.response_format = request.response_format;
|
|
42
54
|
}
|
|
43
|
-
if (request.
|
|
55
|
+
if (request.stream !== undefined) {
|
|
56
|
+
requestBody.stream = request.stream;
|
|
57
|
+
}
|
|
58
|
+
if (request.style !== undefined) {
|
|
44
59
|
requestBody.style = request.style;
|
|
45
60
|
}
|
|
46
|
-
if (request.user) {
|
|
61
|
+
if (request.user !== undefined) {
|
|
47
62
|
requestBody.user = request.user;
|
|
48
63
|
}
|
|
64
|
+
// 添加图片输入参数(图文生图或多图融合)
|
|
65
|
+
if (request.image !== undefined) {
|
|
66
|
+
requestBody.image = request.image;
|
|
67
|
+
}
|
|
68
|
+
requestBody.watermark = request.watermark || false;
|
|
49
69
|
const url = `${config_1.sdkConfig.getServerUrl()}/api/doubao-image-proxy/generate`;
|
|
50
70
|
(0, log_1.logRequest)("POST", url, this.headers, requestBody);
|
|
51
71
|
const response = await fetch(url, {
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @see https://github.com/langchain-ai/langchainjs
|
|
6
6
|
*/
|
|
7
7
|
import { BaseChatModel, BaseChatModelParams } from "./base";
|
|
8
|
-
import { DoubaoImageGenerationClient, type DoubaoImageGenerationConfig, type DoubaoImageGenerationRequest, type DoubaoImageGenerationResponse } from "./doubao-image-generation";
|
|
8
|
+
import { DoubaoImageGenerationClient, DoubaoImageSize, type DoubaoImageGenerationConfig, type DoubaoImageGenerationRequest, type DoubaoImageGenerationResponse } from "./doubao-image-generation";
|
|
9
9
|
import { GeminiImageGenerationClient, type GeminiImageGenerationConfig, type GeminiImageGenerationRequest, type GeminiImageGenerationResponse } from "./gemini-image-generation";
|
|
10
10
|
import { VideoGenerationClient, type VideoGenerationConfig, type VideoGenerationRequest, type ContentGenerationTaskID, type ContentGenerationTask } from "./video_generation";
|
|
11
11
|
import { sdkConfig } from "./config";
|
|
@@ -19,9 +19,8 @@ export interface LangchainClientConfig {
|
|
|
19
19
|
token?: string;
|
|
20
20
|
headers?: Record<string, string>;
|
|
21
21
|
}
|
|
22
|
-
export { DoubaoImageGenerationClient, type DoubaoImageGenerationConfig, type DoubaoImageGenerationRequest, type DoubaoImageGenerationResponse, };
|
|
22
|
+
export { DoubaoImageGenerationClient, type DoubaoImageGenerationConfig, type DoubaoImageGenerationRequest, type DoubaoImageGenerationResponse, type DoubaoImageSize, };
|
|
23
23
|
export { GeminiImageGenerationClient, type GeminiImageGenerationConfig, type GeminiImageGenerationRequest, type GeminiImageGenerationResponse, };
|
|
24
|
-
export { DoubaoImageGenerationClient as ImageGenerationClient, type DoubaoImageGenerationConfig as ImageGenerationConfig, type DoubaoImageGenerationRequest as ImageGenerationRequest, type DoubaoImageGenerationResponse as ImageGenerationResponse, };
|
|
25
24
|
export { VideoGenerationClient, type VideoGenerationConfig, type VideoGenerationRequest, type ContentGenerationTaskID, type ContentGenerationTask, };
|
|
26
25
|
export { sdkConfig };
|
|
27
26
|
/**
|
package/dist/index.js
CHANGED
|
@@ -6,13 +6,12 @@
|
|
|
6
6
|
* @see https://github.com/langchain-ai/langchainjs
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.sdkConfig = exports.VideoGenerationClient = exports.
|
|
9
|
+
exports.sdkConfig = exports.VideoGenerationClient = exports.GeminiImageGenerationClient = exports.DoubaoImageGenerationClient = exports.ChatAnthropic = exports.ChatGoogleGenerativeAI = exports.ChatOpenAI = exports.BaseChatModel = exports.AIMessageChunk = exports.SystemMessage = exports.AIMessage = exports.HumanMessage = void 0;
|
|
10
10
|
exports.createChatModel = createChatModel;
|
|
11
11
|
const openai_1 = require("./chat_models/openai");
|
|
12
12
|
const google_1 = require("./chat_models/google");
|
|
13
13
|
const doubao_image_generation_1 = require("./doubao-image-generation");
|
|
14
14
|
Object.defineProperty(exports, "DoubaoImageGenerationClient", { enumerable: true, get: function () { return doubao_image_generation_1.DoubaoImageGenerationClient; } });
|
|
15
|
-
Object.defineProperty(exports, "ImageGenerationClient", { enumerable: true, get: function () { return doubao_image_generation_1.DoubaoImageGenerationClient; } });
|
|
16
15
|
const gemini_image_generation_1 = require("./gemini-image-generation");
|
|
17
16
|
Object.defineProperty(exports, "GeminiImageGenerationClient", { enumerable: true, get: function () { return gemini_image_generation_1.GeminiImageGenerationClient; } });
|
|
18
17
|
const video_generation_1 = require("./video_generation");
|
package/package.json
CHANGED