ai-world-sdk 1.0.13 → 1.0.16

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
@@ -46,21 +46,21 @@ import { ChatGoogleGenerativeAI, ChatOpenAI, ChatAnthropic, HumanMessage, System
46
46
  const geminiModel = new ChatGoogleGenerativeAI({
47
47
  modelName: 'gemini-2.5-flash-image',
48
48
  temperature: 0.7,
49
- provider: 'gemini', // 或 'aihubmix'
49
+ provider: 'gemini', // 或 'aihubmix', 'api2img'
50
50
  });
51
51
 
52
52
  // GPT 模型(使用 aihubmix provider)
53
53
  const gptModel = new ChatOpenAI({
54
54
  modelName: 'gpt-4o-mini',
55
55
  temperature: 0.7,
56
- provider: 'aihubmix',
56
+ provider: 'aihubmix', // 或 'api2img'
57
57
  });
58
58
 
59
59
  // Claude 模型(使用 aihubmix provider)
60
60
  const claudeModel = new ChatAnthropic({
61
61
  modelName: 'claude-3-sonnet-20240229',
62
62
  temperature: 0.7,
63
- provider: 'aihubmix',
63
+ provider: 'aihubmix', // 或 'api2img'
64
64
  });
65
65
 
66
66
  // 非流式调用
@@ -208,7 +208,7 @@ import { createChatModel } from 'ai-world-sdk';
208
208
  // 根据模型名称自动选择正确的类
209
209
  const model = createChatModel('gemini-2.5-flash-image', {
210
210
  temperature: 0.7,
211
- provider: 'gemini', // 或 'aihubmix', 'doubao'
211
+ provider: 'gemini', // 或 'aihubmix', 'api2img', 'doubao'
212
212
  });
213
213
  ```
214
214
 
@@ -220,6 +220,7 @@ const model = createChatModel('gemini-2.5-flash-image', {
220
220
 
221
221
  **Provider 参数说明:**
222
222
  - `provider: 'aihubmix'` - 使用 aihubmix 聚合服务(推荐,支持所有模型)
223
+ - `provider: 'api2img'` - 使用 api2img 聚合服务(推荐,支持所有模型)
223
224
  - `provider: 'gemini'` - 直接使用 Google Gemini API
224
225
  - `provider: 'doubao'` - 使用豆包服务
225
226
 
@@ -330,6 +331,7 @@ const secondResponse = await client.chat({
330
331
 
331
332
  - `provider: 'gemini'`(默认)- 直接使用 Google Gemini 官方 API
332
333
  - `provider: 'aihubmix'` - 通过 aihubmix 代理服务调用,适合需要统一管理多个 API 的场景
334
+ - `provider: 'api2img'` - 通过 api2img 代理服务调用,适合需要统一管理多个 API 的场景
333
335
 
334
336
  **模型对比:**
335
337
 
@@ -661,6 +663,7 @@ const response = await doubaoModel.invoke([
661
663
  |----------|----------|------------|
662
664
  | `aihubmix` | 多模型聚合,统一接口 | GPT、Gemini、Claude、Doubao 等 |
663
665
  | `gemini` | 直接使用 Google Gemini API | 所有 Gemini 模型 |
666
+ | `api2img` | 使用 api2img 聚合服务 | 所有模型 |
664
667
  | `doubao` | 使用豆包服务 | Doubao 系列模型 |
665
668
 
666
669
  **推荐使用 `aihubmix` provider**,因为它提供了统一的接口和更好的模型选择灵活性。
@@ -1025,7 +1028,7 @@ for await (const chunk of client.streamDownload({
1025
1028
  | Doubao | `doubao` 或 `aihubmix` | `doubao-pro-4k`, `doubao-seedream-4-5-251128` | `ChatOpenAI` |
1026
1029
 
1027
1030
  **注意:**
1028
- - 使用 `aihubmix` provider 可以访问所有模型,推荐用于多模型场景
1031
+ - 使用 `aihubmix` 或 `api2img` provider 可以访问所有模型,推荐用于多模型场景
1029
1032
  - 使用特定 provider(如 `gemini`、`doubao`)会直接调用对应的官方 API
1030
1033
 
1031
1034
  ### 图像生成模型
@@ -670,6 +670,68 @@ describe("Langchain SDK Tests", () => {
670
670
  console.log("图像描述:", result.text);
671
671
  }
672
672
  }, 120000);
673
+ test("ChatGoogleGenerativeAI - api2img.com no stream", async () => {
674
+ const gemini = new index_1.ChatGoogleGenerativeAI({
675
+ modelName: "gemini-2.5-flash-image",
676
+ temperature: 0.7,
677
+ provider: "api2img",
678
+ });
679
+ const response = await gemini.invoke([
680
+ new index_1.HumanMessage("api2img.com是做什么的"),
681
+ ]);
682
+ expect(response).toBeDefined();
683
+ expect(response.content).toBeDefined();
684
+ expect(typeof response.content).toBe("string");
685
+ console.log("✅ api2img.com no stream 测试成功");
686
+ console.log("AI:", response.content);
687
+ }, 30000);
688
+ test("ChatGoogleGenerativeAI - api2img.com stream", async () => {
689
+ const gemini = new index_1.ChatGoogleGenerativeAI({
690
+ modelName: "gemini-2.5-flash-image",
691
+ temperature: 0.7,
692
+ provider: "api2img",
693
+ });
694
+ let fullText = "";
695
+ for await (const chunk of gemini.stream([
696
+ new index_1.HumanMessage("api2img.com是做什么的"),
697
+ ])) {
698
+ fullText += extractTextFromChunk(chunk);
699
+ console.log("AI stream chunk:", chunk);
700
+ console.log("AI stream text:", fullText);
701
+ }
702
+ expect(fullText.length).toBeGreaterThan(0);
703
+ console.log("✅ api2img.com stream 测试成功");
704
+ console.log("AI:", fullText);
705
+ console.log(`完整回复长度: ${fullText.length} 字符`);
706
+ }, 30000);
707
+ test("GeminiImageGenerationClient - 使用 api2img provider", async () => {
708
+ const imageClient = new index_1.GeminiImageGenerationClient({
709
+ provider: "api2img",
710
+ });
711
+ const result = await imageClient.generate({
712
+ prompt: 'A beautiful sunset over the ocean',
713
+ model: 'gemini-3-pro-image-preview',
714
+ aspect_ratio: '16:9',
715
+ image_size: '1K',
716
+ response_modalities: ['IMAGE'], // 仅返回图片
717
+ });
718
+ expect(result).toBeDefined();
719
+ expect(result.created).toBeDefined();
720
+ expect(typeof result.created).toBe("number");
721
+ expect(result.data).toBeDefined();
722
+ expect(Array.isArray(result.data)).toBe(true);
723
+ expect(result.data.length).toBeGreaterThan(0);
724
+ result.data.forEach((item) => {
725
+ expect(item).toBeDefined();
726
+ expect(item.url || item.b64_json).toBeDefined();
727
+ });
728
+ console.log("✅ GeminiImageGenerationClient (api2img provider) 测试成功");
729
+ console.log(`生成图像数量: ${result.data.length}`);
730
+ console.log("图像 URL:", result.data[0]?.url || ("Base64 编码" + result.data[0]?.b64_json));
731
+ if (result.text) {
732
+ console.log("图像描述:", result.text);
733
+ }
734
+ }, 120000);
673
735
  test("GeminiImageGenerationClient - 多轮图片修改", async () => {
674
736
  const imageClient = new index_1.GeminiImageGenerationClient({});
675
737
  // 第一轮:创建初始图片
package/dist/base.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Similar to LangChain.js BaseChatModel
4
4
  */
5
5
  import { BaseMessage, AIMessage, AIMessageChunk } from "./messages";
6
- export type AIModelProvider = "aihubmix" | "doubao" | "gemini";
6
+ export type AIModelProvider = "aihubmix" | "api2img" | "doubao" | "gemini";
7
7
  export interface BaseChatModelParams {
8
8
  provider: AIModelProvider;
9
9
  baseUrl?: string;
@@ -2,8 +2,9 @@
2
2
  * Gemini Image Generation Client
3
3
  * Google Gemini 图像生成客户端
4
4
  */
5
+ export type GeminiImageGenerationProvider = "aihubmix" | "api2img" | "gemini";
5
6
  export interface GeminiImageGenerationConfig {
6
- provider?: "aihubmix" | "gemini";
7
+ provider?: GeminiImageGenerationProvider;
7
8
  baseUrl?: string;
8
9
  headers?: Record<string, string>;
9
10
  }
@@ -32,7 +33,7 @@ export interface GeminiImageChatRequest {
32
33
  message: string;
33
34
  chat_id?: string;
34
35
  model?: string;
35
- provider?: "aihubmix" | "gemini";
36
+ provider?: GeminiImageGenerationProvider;
36
37
  aspect_ratio?: "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4" | "9:16" | "16:9" | "21:9";
37
38
  image_size?: "1K" | "2K" | "4K";
38
39
  response_modalities?: ("TEXT" | "IMAGE")[];
package/dist/index.js CHANGED
@@ -52,6 +52,7 @@ function createChatModel(model, config) {
52
52
  switch (config.provider) {
53
53
  case "doubao":
54
54
  case "aihubmix":
55
+ case "api2img":
55
56
  return new openai_1.ChatOpenAI({
56
57
  modelName: model,
57
58
  ...finalConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-world-sdk",
3
- "version": "1.0.13",
3
+ "version": "1.0.16",
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",