ai-world-sdk 1.0.2 → 1.0.3
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/dist/__tests__/example.test.js +6 -6
- package/dist/doubao-image-generation.d.ts +36 -0
- package/dist/{image_generation.js → doubao-image-generation.js} +7 -7
- package/dist/gemini-image-generation.d.ts +36 -0
- package/dist/gemini-image-generation.js +62 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -3
- package/package.json +1 -1
- package/dist/image_generation.d.ts +0 -36
|
@@ -279,8 +279,8 @@ describe("Langchain SDK Tests", () => {
|
|
|
279
279
|
console.log("响应内容:", content);
|
|
280
280
|
}
|
|
281
281
|
}, 60000);
|
|
282
|
-
test("
|
|
283
|
-
const imageClient = new index_1.
|
|
282
|
+
test("DoubaoImageGenerationClient - 基础图像生成", async () => {
|
|
283
|
+
const imageClient = new index_1.DoubaoImageGenerationClient({});
|
|
284
284
|
const result = await imageClient.generate({
|
|
285
285
|
prompt: "充满活力的特写编辑肖像,模特眼神犀利,头戴雕塑感帽子,色彩拼接丰富,眼部焦点锐利,景深较浅,具有Vogue杂志封面的美学风格,采用中画幅拍摄,工作室灯光效果强烈。",
|
|
286
286
|
model: "doubao-seedream-4-5-251128",
|
|
@@ -306,8 +306,8 @@ describe("Langchain SDK Tests", () => {
|
|
|
306
306
|
console.log("图像 URL:", result.data[0]?.url || "Base64 编码");
|
|
307
307
|
console.log("创建时间:", new Date(result.created * 1000).toISOString());
|
|
308
308
|
}, 120000);
|
|
309
|
-
test("
|
|
310
|
-
const imageClient = new index_1.
|
|
309
|
+
test("DoubaoImageGenerationClient - 多图像生成 (n=2)", async () => {
|
|
310
|
+
const imageClient = new index_1.DoubaoImageGenerationClient({});
|
|
311
311
|
const result = await imageClient.generate({
|
|
312
312
|
prompt: "A beautiful sunset over the ocean with vibrant colors",
|
|
313
313
|
model: "doubao-seedream-4-5-251128",
|
|
@@ -324,8 +324,8 @@ describe("Langchain SDK Tests", () => {
|
|
|
324
324
|
console.log(`图像 ${index + 1}:`, item.url || "Base64 编码");
|
|
325
325
|
});
|
|
326
326
|
}, 120000);
|
|
327
|
-
test("
|
|
328
|
-
const imageClient = new index_1.
|
|
327
|
+
test("DoubaoImageGenerationClient - 不同尺寸测试", async () => {
|
|
328
|
+
const imageClient = new index_1.DoubaoImageGenerationClient({});
|
|
329
329
|
const sizes = ["1K", "2K", "4K"];
|
|
330
330
|
for (const size of sizes) {
|
|
331
331
|
const result = await imageClient.generate({
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Doubao Image Generation Client
|
|
3
|
+
* 豆包图像生成客户端
|
|
4
|
+
*/
|
|
5
|
+
export interface DoubaoImageGenerationConfig {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export interface DoubaoImageGenerationRequest {
|
|
10
|
+
model?: string;
|
|
11
|
+
prompt: string;
|
|
12
|
+
size?: string;
|
|
13
|
+
watermark?: boolean;
|
|
14
|
+
n?: number;
|
|
15
|
+
quality?: "standard" | "hd";
|
|
16
|
+
response_format?: "url" | "b64_json";
|
|
17
|
+
style?: "vivid" | "natural";
|
|
18
|
+
user?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DoubaoImageData {
|
|
21
|
+
url?: string;
|
|
22
|
+
b64_json?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface DoubaoImageGenerationResponse {
|
|
25
|
+
created: number;
|
|
26
|
+
data: DoubaoImageData[];
|
|
27
|
+
}
|
|
28
|
+
export declare class DoubaoImageGenerationClient {
|
|
29
|
+
private headers;
|
|
30
|
+
constructor(config?: DoubaoImageGenerationConfig);
|
|
31
|
+
/**
|
|
32
|
+
* Generate images
|
|
33
|
+
* 生成图像
|
|
34
|
+
*/
|
|
35
|
+
generate(request: DoubaoImageGenerationRequest): Promise<DoubaoImageGenerationResponse>;
|
|
36
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Image Generation Client
|
|
4
|
-
*
|
|
3
|
+
* Doubao Image Generation Client
|
|
4
|
+
* 豆包图像生成客户端
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.DoubaoImageGenerationClient = void 0;
|
|
8
8
|
const config_1 = require("./config");
|
|
9
9
|
const log_1 = require("./log");
|
|
10
|
-
class
|
|
10
|
+
class DoubaoImageGenerationClient {
|
|
11
11
|
constructor(config) {
|
|
12
12
|
// 合并全局 headers 和配置 headers
|
|
13
13
|
const globalHeaders = config_1.sdkConfig.getHeaders();
|
|
@@ -46,7 +46,7 @@ class ImageGenerationClient {
|
|
|
46
46
|
if (request.user) {
|
|
47
47
|
requestBody.user = request.user;
|
|
48
48
|
}
|
|
49
|
-
const url = `${config_1.sdkConfig.getServerUrl()}/api/image-proxy/generate`;
|
|
49
|
+
const url = `${config_1.sdkConfig.getServerUrl()}/api/doubao-image-proxy/generate`;
|
|
50
50
|
(0, log_1.logRequest)("POST", url, this.headers, requestBody);
|
|
51
51
|
const response = await fetch(url, {
|
|
52
52
|
method: "POST",
|
|
@@ -56,11 +56,11 @@ class ImageGenerationClient {
|
|
|
56
56
|
if (!response.ok) {
|
|
57
57
|
const errorText = await response.text();
|
|
58
58
|
(0, log_1.logResponse)(response.status, response.statusText, response.headers, errorText);
|
|
59
|
-
throw new Error(`
|
|
59
|
+
throw new Error(`Doubao image generation API error: ${response.status} ${errorText}`);
|
|
60
60
|
}
|
|
61
61
|
const data = (await response.json());
|
|
62
62
|
(0, log_1.logResponse)(response.status, response.statusText, response.headers, data);
|
|
63
63
|
return data;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
exports.
|
|
66
|
+
exports.DoubaoImageGenerationClient = DoubaoImageGenerationClient;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gemini Image Generation Client
|
|
3
|
+
* Google Gemini 图像生成客户端
|
|
4
|
+
*/
|
|
5
|
+
export interface GeminiImageGenerationConfig {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export interface GeminiImageGenerationRequest {
|
|
10
|
+
prompt: string;
|
|
11
|
+
model?: string;
|
|
12
|
+
number_of_images?: number;
|
|
13
|
+
aspect_ratio?: "1:1" | "9:16" | "16:9" | "4:3" | "3:4";
|
|
14
|
+
temperature?: number;
|
|
15
|
+
max_output_tokens?: number;
|
|
16
|
+
user?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface GeminiImageData {
|
|
19
|
+
url?: string;
|
|
20
|
+
b64_json?: string;
|
|
21
|
+
text?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface GeminiImageGenerationResponse {
|
|
24
|
+
created: number;
|
|
25
|
+
data: GeminiImageData[];
|
|
26
|
+
text?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class GeminiImageGenerationClient {
|
|
29
|
+
private headers;
|
|
30
|
+
constructor(config?: GeminiImageGenerationConfig);
|
|
31
|
+
/**
|
|
32
|
+
* Generate images
|
|
33
|
+
* 生成图像
|
|
34
|
+
*/
|
|
35
|
+
generate(request: GeminiImageGenerationRequest): Promise<GeminiImageGenerationResponse>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Gemini Image Generation Client
|
|
4
|
+
* Google Gemini 图像生成客户端
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.GeminiImageGenerationClient = void 0;
|
|
8
|
+
const config_1 = require("./config");
|
|
9
|
+
const log_1 = require("./log");
|
|
10
|
+
class GeminiImageGenerationClient {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
// 合并全局 headers 和配置 headers
|
|
13
|
+
const globalHeaders = config_1.sdkConfig.getHeaders();
|
|
14
|
+
this.headers = {
|
|
15
|
+
"Content-Type": "application/json",
|
|
16
|
+
"Authorization": `Bearer ${config_1.sdkConfig.getToken()}`,
|
|
17
|
+
"X-Base-Url": config?.baseUrl || "",
|
|
18
|
+
...globalHeaders,
|
|
19
|
+
...config?.headers,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Generate images
|
|
24
|
+
* 生成图像
|
|
25
|
+
*/
|
|
26
|
+
async generate(request) {
|
|
27
|
+
const requestBody = {
|
|
28
|
+
prompt: request.prompt,
|
|
29
|
+
model: request.model || "gemini-2.0-flash-exp-image-generation",
|
|
30
|
+
number_of_images: request.number_of_images || 1,
|
|
31
|
+
};
|
|
32
|
+
// 添加可选参数
|
|
33
|
+
if (request.aspect_ratio) {
|
|
34
|
+
requestBody.aspect_ratio = request.aspect_ratio;
|
|
35
|
+
}
|
|
36
|
+
if (request.temperature !== undefined) {
|
|
37
|
+
requestBody.temperature = request.temperature;
|
|
38
|
+
}
|
|
39
|
+
if (request.max_output_tokens) {
|
|
40
|
+
requestBody.max_output_tokens = request.max_output_tokens;
|
|
41
|
+
}
|
|
42
|
+
if (request.user) {
|
|
43
|
+
requestBody.user = request.user;
|
|
44
|
+
}
|
|
45
|
+
const url = `${config_1.sdkConfig.getServerUrl()}/api/gemini-image-proxy/generate`;
|
|
46
|
+
(0, log_1.logRequest)("POST", url, this.headers, requestBody);
|
|
47
|
+
const response = await fetch(url, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: this.headers,
|
|
50
|
+
body: JSON.stringify(requestBody),
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const errorText = await response.text();
|
|
54
|
+
(0, log_1.logResponse)(response.status, response.statusText, response.headers, errorText);
|
|
55
|
+
throw new Error(`Gemini image generation API error: ${response.status} ${errorText}`);
|
|
56
|
+
}
|
|
57
|
+
const data = (await response.json());
|
|
58
|
+
(0, log_1.logResponse)(response.status, response.statusText, response.headers, data);
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.GeminiImageGenerationClient = GeminiImageGenerationClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* @see https://github.com/langchain-ai/langchainjs
|
|
6
6
|
*/
|
|
7
7
|
import { BaseChatModel, BaseChatModelParams } from "./base";
|
|
8
|
-
import {
|
|
8
|
+
import { DoubaoImageGenerationClient, type DoubaoImageGenerationConfig, type DoubaoImageGenerationRequest, type DoubaoImageGenerationResponse } from "./doubao-image-generation";
|
|
9
|
+
import { GeminiImageGenerationClient, type GeminiImageGenerationConfig, type GeminiImageGenerationRequest, type GeminiImageGenerationResponse } from "./gemini-image-generation";
|
|
9
10
|
import { VideoGenerationClient, type VideoGenerationConfig, type VideoGenerationRequest, type ContentGenerationTaskID, type ContentGenerationTask } from "./video_generation";
|
|
10
11
|
import { sdkConfig } from "./config";
|
|
11
12
|
export { BaseMessage, HumanMessage, AIMessage, SystemMessage, AIMessageChunk, type MessageContent, type AIMessageChunkData, } from "./messages";
|
|
@@ -18,7 +19,9 @@ export interface LangchainClientConfig {
|
|
|
18
19
|
token?: string;
|
|
19
20
|
headers?: Record<string, string>;
|
|
20
21
|
}
|
|
21
|
-
export {
|
|
22
|
+
export { DoubaoImageGenerationClient, type DoubaoImageGenerationConfig, type DoubaoImageGenerationRequest, type DoubaoImageGenerationResponse, };
|
|
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, };
|
|
22
25
|
export { VideoGenerationClient, type VideoGenerationConfig, type VideoGenerationRequest, type ContentGenerationTaskID, type ContentGenerationTask, };
|
|
23
26
|
export { sdkConfig };
|
|
24
27
|
/**
|
package/dist/index.js
CHANGED
|
@@ -6,13 +6,16 @@
|
|
|
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.ImageGenerationClient = exports.ChatAnthropic = exports.ChatGoogleGenerativeAI = exports.ChatOpenAI = exports.BaseChatModel = exports.AIMessageChunk = exports.SystemMessage = exports.AIMessage = exports.HumanMessage = void 0;
|
|
9
|
+
exports.sdkConfig = exports.VideoGenerationClient = exports.ImageGenerationClient = 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 anthropic_1 = require("./chat_models/anthropic");
|
|
14
|
-
const
|
|
15
|
-
Object.defineProperty(exports, "
|
|
14
|
+
const doubao_image_generation_1 = require("./doubao-image-generation");
|
|
15
|
+
Object.defineProperty(exports, "DoubaoImageGenerationClient", { enumerable: true, get: function () { return doubao_image_generation_1.DoubaoImageGenerationClient; } });
|
|
16
|
+
Object.defineProperty(exports, "ImageGenerationClient", { enumerable: true, get: function () { return doubao_image_generation_1.DoubaoImageGenerationClient; } });
|
|
17
|
+
const gemini_image_generation_1 = require("./gemini-image-generation");
|
|
18
|
+
Object.defineProperty(exports, "GeminiImageGenerationClient", { enumerable: true, get: function () { return gemini_image_generation_1.GeminiImageGenerationClient; } });
|
|
16
19
|
const video_generation_1 = require("./video_generation");
|
|
17
20
|
Object.defineProperty(exports, "VideoGenerationClient", { enumerable: true, get: function () { return video_generation_1.VideoGenerationClient; } });
|
|
18
21
|
const config_1 = require("./config");
|
package/package.json
CHANGED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Image Generation Client
|
|
3
|
-
* 图像生成客户端
|
|
4
|
-
*/
|
|
5
|
-
export interface ImageGenerationConfig {
|
|
6
|
-
baseUrl?: string;
|
|
7
|
-
headers?: Record<string, string>;
|
|
8
|
-
}
|
|
9
|
-
export interface ImageGenerationRequest {
|
|
10
|
-
model?: string;
|
|
11
|
-
prompt: string;
|
|
12
|
-
size?: string;
|
|
13
|
-
watermark?: boolean;
|
|
14
|
-
n?: number;
|
|
15
|
-
quality?: "standard" | "hd";
|
|
16
|
-
response_format?: "url" | "b64_json";
|
|
17
|
-
style?: "vivid" | "natural";
|
|
18
|
-
user?: string;
|
|
19
|
-
}
|
|
20
|
-
export interface ImageData {
|
|
21
|
-
url?: string;
|
|
22
|
-
b64_json?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface ImageGenerationResponse {
|
|
25
|
-
created: number;
|
|
26
|
-
data: ImageData[];
|
|
27
|
-
}
|
|
28
|
-
export declare class ImageGenerationClient {
|
|
29
|
-
private headers;
|
|
30
|
-
constructor(config?: ImageGenerationConfig);
|
|
31
|
-
/**
|
|
32
|
-
* Generate images
|
|
33
|
-
* 生成图像
|
|
34
|
-
*/
|
|
35
|
-
generate(request: ImageGenerationRequest): Promise<ImageGenerationResponse>;
|
|
36
|
-
}
|