ai-world-sdk 1.0.13 → 1.0.15
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.
|
@@ -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?:
|
|
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?:
|
|
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
package/package.json
CHANGED