ai-world-sdk 1.1.10 → 1.2.0
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 +109 -60
- package/dist/__tests__/example.test.js +37 -37
- package/dist/__tests__/llm.real.test.d.ts +13 -0
- package/dist/__tests__/llm.real.test.js +272 -0
- package/dist/__tests__/llm.test.d.ts +9 -0
- package/dist/__tests__/llm.test.js +157 -0
- package/dist/chat_models/anthropic.d.ts +1 -1
- package/dist/chat_models/openai.d.ts +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.js +2 -2
- package/dist/gemini-image-generation.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +15 -0
- package/dist/llm.d.ts +23 -0
- package/dist/llm.js +63 -0
- package/dist/messages.d.ts +21 -1
- package/dist/openai_video_generation.d.ts +10 -10
- package/dist/openai_video_generation.js +10 -10
- package/dist/provider_config.d.ts +12 -3
- package/dist/provider_config.js +2 -1
- package/package.json +20 -12
package/README.md
CHANGED
|
@@ -47,26 +47,26 @@ import { ChatGoogleGenerativeAI, ChatOpenAI, ChatAnthropic, HumanMessage, System
|
|
|
47
47
|
const geminiModel = new ChatGoogleGenerativeAI({
|
|
48
48
|
modelName: 'gemini-2.5-flash-image',
|
|
49
49
|
temperature: 0.7,
|
|
50
|
-
provider: 'gemini', // 或 '
|
|
50
|
+
provider: 'gemini', // 或 'api2img'
|
|
51
51
|
vertexai: false, // 可选:是否使用 VertexAI(仅当 provider 为 gemini 时有效)
|
|
52
52
|
jsonSchema: undefined, // 可选:结构化输出 JSON Schema
|
|
53
53
|
webSearch: false, // 可选:若模型支持联网搜索,设为 true 可基于实时网络信息回答
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
// GPT 模型(使用
|
|
56
|
+
// GPT 模型(使用 api2img provider)
|
|
57
57
|
const gptModel = new ChatOpenAI({
|
|
58
58
|
modelName: 'gpt-4o-mini',
|
|
59
59
|
temperature: 0.7,
|
|
60
|
-
provider: '
|
|
60
|
+
provider: 'api2img',
|
|
61
61
|
jsonSchema: undefined, // 可选:结构化输出 JSON Schema
|
|
62
62
|
webSearch: false, // 可选:若模型支持联网搜索,设为 true 可基于实时网络信息回答
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
// Claude 模型(使用
|
|
65
|
+
// Claude 模型(使用 api2img provider)
|
|
66
66
|
const claudeModel = new ChatAnthropic({
|
|
67
67
|
modelName: 'claude-3-sonnet-20240229',
|
|
68
68
|
temperature: 0.7,
|
|
69
|
-
provider: '
|
|
69
|
+
provider: 'api2img',
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
// 非流式调用
|
|
@@ -150,7 +150,7 @@ const openaiVideoClient = new OpenAIVideoGenerationClient({});
|
|
|
150
150
|
const task = await openaiVideoClient.generate({
|
|
151
151
|
prompt: 'A beautiful sunset over the ocean with waves crashing on the shore',
|
|
152
152
|
model: 'sora-2', // 或 'sora-2-pro'
|
|
153
|
-
provider: '
|
|
153
|
+
provider: 'api2img',
|
|
154
154
|
seconds: '4', // 4, 8, 或 12 秒
|
|
155
155
|
size: '1280x720' // '720x1280', '1280x720', '1024x1792', '1792x1024'
|
|
156
156
|
});
|
|
@@ -163,16 +163,16 @@ const taskWithImage = await openaiVideoClient.generate({
|
|
|
163
163
|
prompt: 'Animate this scene with gentle movements',
|
|
164
164
|
input_reference: 'data:image/png;base64,iVBORw0KGgo...', // Base64 图像或 URL
|
|
165
165
|
model: 'sora-2',
|
|
166
|
-
provider: '
|
|
166
|
+
provider: 'api2img',
|
|
167
167
|
seconds: '4'
|
|
168
168
|
});
|
|
169
169
|
|
|
170
170
|
// 查询任务状态
|
|
171
|
-
const status = await openaiVideoClient.getTask(task.id, '
|
|
171
|
+
const status = await openaiVideoClient.getTask(task.id, 'api2img');
|
|
172
172
|
console.log('当前状态:', status.status);
|
|
173
173
|
|
|
174
174
|
// 轮询等待完成
|
|
175
|
-
const result = await openaiVideoClient.waitForCompletion(task.id, '
|
|
175
|
+
const result = await openaiVideoClient.waitForCompletion(task.id, 'api2img', {
|
|
176
176
|
maxAttempts: 60,
|
|
177
177
|
interval: 5000,
|
|
178
178
|
onProgress: (status) => {
|
|
@@ -186,7 +186,7 @@ if (result.status === 'completed') {
|
|
|
186
186
|
// 流式下载视频
|
|
187
187
|
const videoBlob = await openaiVideoClient.downloadVideo(
|
|
188
188
|
result.id,
|
|
189
|
-
'
|
|
189
|
+
'api2img', // provider
|
|
190
190
|
'video' // 'video' 或 'thumbnail'
|
|
191
191
|
);
|
|
192
192
|
|
|
@@ -205,7 +205,7 @@ if (result.status === 'completed') {
|
|
|
205
205
|
const completeResult = await openaiVideoClient.generateAndWait({
|
|
206
206
|
prompt: 'A futuristic city skyline',
|
|
207
207
|
model: 'sora-2',
|
|
208
|
-
provider: '
|
|
208
|
+
provider: 'api2img',
|
|
209
209
|
seconds: '4'
|
|
210
210
|
}, {
|
|
211
211
|
maxAttempts: 60,
|
|
@@ -216,7 +216,7 @@ const completeResult = await openaiVideoClient.generateAndWait({
|
|
|
216
216
|
if (completeResult.status === 'completed') {
|
|
217
217
|
const videoBlob = await openaiVideoClient.downloadVideo(
|
|
218
218
|
completeResult.id,
|
|
219
|
-
'
|
|
219
|
+
'api2img',
|
|
220
220
|
'video'
|
|
221
221
|
);
|
|
222
222
|
console.log('一键生成完成,视频大小:', videoBlob.size);
|
|
@@ -321,7 +321,7 @@ import { createChatModel } from 'ai-world-sdk';
|
|
|
321
321
|
// 根据模型名称自动选择正确的类
|
|
322
322
|
const model = createChatModel('gemini-2.5-flash-image', {
|
|
323
323
|
temperature: 0.7,
|
|
324
|
-
provider: 'gemini', // 或 '
|
|
324
|
+
provider: 'gemini', // 或 'api2img', 'doubao'
|
|
325
325
|
});
|
|
326
326
|
```
|
|
327
327
|
|
|
@@ -332,7 +332,6 @@ const model = createChatModel('gemini-2.5-flash-image', {
|
|
|
332
332
|
- `claude-*` → `ChatAnthropic`
|
|
333
333
|
|
|
334
334
|
**Provider 参数说明:**
|
|
335
|
-
- `provider: 'aihubmix'` - 使用 aihubmix 聚合服务(推荐,支持所有模型)
|
|
336
335
|
- `provider: 'api2img'` - 使用 api2img 聚合服务(推荐,支持所有模型)
|
|
337
336
|
- `provider: 'gemini'` - 直接使用 Google Gemini API
|
|
338
337
|
- `provider: 'doubao'` - 使用豆包服务
|
|
@@ -391,12 +390,12 @@ const result2 = await client.generate({
|
|
|
391
390
|
max_output_tokens: 1000, // 可选
|
|
392
391
|
});
|
|
393
392
|
|
|
394
|
-
// 使用
|
|
395
|
-
const
|
|
396
|
-
provider: '
|
|
393
|
+
// 使用 api2img provider(通过 api2img 代理服务)
|
|
394
|
+
const api2imgClient = new GeminiImageGenerationClient({
|
|
395
|
+
provider: 'api2img', // 使用 api2img 代理
|
|
397
396
|
});
|
|
398
397
|
|
|
399
|
-
const result3 = await
|
|
398
|
+
const result3 = await api2imgClient.generate({
|
|
400
399
|
prompt: 'A beautiful landscape with mountains',
|
|
401
400
|
model: 'gemini-3-pro-image-preview',
|
|
402
401
|
aspect_ratio: '16:9',
|
|
@@ -455,7 +454,6 @@ const secondResponse = await client.chat({
|
|
|
455
454
|
**Provider 说明:**
|
|
456
455
|
|
|
457
456
|
- `provider: 'gemini'`(默认)- 直接使用 Google Gemini 官方 API
|
|
458
|
-
- `provider: 'aihubmix'` - 通过 aihubmix 代理服务调用,适合需要统一管理多个 API 的场景
|
|
459
457
|
- `provider: 'api2img'` - 通过 api2img 代理服务调用,适合需要统一管理多个 API 的场景
|
|
460
458
|
|
|
461
459
|
**模型对比:**
|
|
@@ -508,7 +506,7 @@ const client = new OpenAIVideoGenerationClient({});
|
|
|
508
506
|
const task = await client.generate({
|
|
509
507
|
prompt: 'A beautiful sunset',
|
|
510
508
|
model: 'sora-2', // 可选: sora-2, sora-2-pro
|
|
511
|
-
provider: 'openai', // 可选: openai,
|
|
509
|
+
provider: 'openai', // 可选: openai, api2img
|
|
512
510
|
seconds: '4', // 可选: 4, 8, 12
|
|
513
511
|
size: '1280x720', // 可选: 720x1280, 1280x720, 1024x1792, 1792x1024
|
|
514
512
|
});
|
|
@@ -738,42 +736,76 @@ const multimodalMsg = new HumanMessage([
|
|
|
738
736
|
{ type: 'image_url', image_url: 'data:image/jpeg;base64,...' },
|
|
739
737
|
]);
|
|
740
738
|
|
|
739
|
+
// 音频消息(需要模型支持音频输入,如 Gemini)
|
|
740
|
+
const audioMsg = new HumanMessage([
|
|
741
|
+
{ type: 'text', text: '这段音频说了什么?' },
|
|
742
|
+
{ type: 'audio', base64: '<base64 encoded audio data>', mime_type: 'audio/wav' },
|
|
743
|
+
]);
|
|
744
|
+
|
|
745
|
+
// 音频消息(URL 方式)
|
|
746
|
+
const audioUrlMsg = new HumanMessage([
|
|
747
|
+
{ type: 'text', text: '请描述这段音频' },
|
|
748
|
+
{ type: 'audio', url: 'https://example.com/audio.wav', mime_type: 'audio/wav' },
|
|
749
|
+
]);
|
|
750
|
+
|
|
751
|
+
// 视频消息(需要模型支持视频输入,如 Gemini)
|
|
752
|
+
const videoMsg = new HumanMessage([
|
|
753
|
+
{ type: 'text', text: '这段视频里发生了什么?' },
|
|
754
|
+
{ type: 'video', base64: '<base64 encoded video data>', mime_type: 'video/mp4' },
|
|
755
|
+
]);
|
|
756
|
+
|
|
757
|
+
// 视频消息(URL 方式)
|
|
758
|
+
const videoUrlMsg = new HumanMessage([
|
|
759
|
+
{ type: 'text', text: '请描述这段视频' },
|
|
760
|
+
{ type: 'video', url: 'https://example.com/video.mp4', mime_type: 'video/mp4' },
|
|
761
|
+
]);
|
|
762
|
+
|
|
741
763
|
// AIMessageChunk 属性
|
|
742
764
|
// - text: 获取文本内容(自动处理 string 或 MessageContent[] 类型)
|
|
743
765
|
// - reasoning: 获取推理/思考内容(如果模型支持)
|
|
744
766
|
// - content: 原始内容
|
|
745
767
|
```
|
|
746
768
|
|
|
769
|
+
**音频/视频消息说明:**
|
|
770
|
+
- `type`: `"audio"` 或 `"video"`
|
|
771
|
+
- `base64`: base64 编码的媒体数据(与 `url` 二选一)
|
|
772
|
+
- `url`: 媒体文件的 URL(与 `base64` 二选一)
|
|
773
|
+
- `mime_type`: MIME 类型,使用 `base64` 时必填。常见值:
|
|
774
|
+
- 音频:`audio/wav`, `audio/mp3`, `audio/ogg`, `audio/flac`, `audio/aac`
|
|
775
|
+
- 视频:`video/mp4`, `video/webm`, `video/mpeg`
|
|
776
|
+
- 音频输入支持:Gemini 模型、OpenAI(通过 `input_audio` 格式,需要模型支持)
|
|
777
|
+
- 视频输入支持:Gemini 模型(OpenAI 暂不支持视频输入)
|
|
778
|
+
|
|
747
779
|
## Provider 调用示例
|
|
748
780
|
|
|
749
781
|
SDK 支持多个 provider,每个 provider 对应不同的服务提供商。以下是各 provider 的使用示例:
|
|
750
782
|
|
|
751
|
-
###
|
|
783
|
+
### api2img Provider
|
|
752
784
|
|
|
753
|
-
`
|
|
785
|
+
`api2img` 是一个多模型聚合服务,支持多种模型(OpenAI、Gemini、Claude 等)。
|
|
754
786
|
|
|
755
787
|
```typescript
|
|
756
788
|
import { ChatOpenAI, ChatGoogleGenerativeAI, ChatAnthropic, HumanMessage } from 'ai-world-sdk';
|
|
757
789
|
|
|
758
|
-
// OpenAI 模型(通过
|
|
790
|
+
// OpenAI 模型(通过 api2img)
|
|
759
791
|
const gptModel = new ChatOpenAI({
|
|
760
792
|
modelName: 'gpt-4o-mini',
|
|
761
793
|
temperature: 0.7,
|
|
762
|
-
provider: '
|
|
794
|
+
provider: 'api2img',
|
|
763
795
|
});
|
|
764
796
|
|
|
765
|
-
// Gemini 模型(通过
|
|
797
|
+
// Gemini 模型(通过 api2img)
|
|
766
798
|
const geminiModel = new ChatGoogleGenerativeAI({
|
|
767
799
|
modelName: 'gemini-2.5-flash',
|
|
768
800
|
temperature: 0.7,
|
|
769
|
-
provider: '
|
|
801
|
+
provider: 'api2img',
|
|
770
802
|
});
|
|
771
803
|
|
|
772
|
-
// Gemini 图像生成(通过
|
|
804
|
+
// Gemini 图像生成(通过 api2img)
|
|
773
805
|
import { GeminiImageGenerationClient } from 'ai-world-sdk';
|
|
774
806
|
|
|
775
807
|
const geminiImageClient = new GeminiImageGenerationClient({
|
|
776
|
-
provider: '
|
|
808
|
+
provider: 'api2img',
|
|
777
809
|
});
|
|
778
810
|
|
|
779
811
|
const imageResult = await geminiImageClient.generate({
|
|
@@ -784,11 +816,11 @@ const imageResult = await geminiImageClient.generate({
|
|
|
784
816
|
response_modalities: ['IMAGE'],
|
|
785
817
|
});
|
|
786
818
|
|
|
787
|
-
// Claude 模型(通过
|
|
819
|
+
// Claude 模型(通过 api2img)
|
|
788
820
|
const claudeModel = new ChatAnthropic({
|
|
789
821
|
modelName: 'claude-3-sonnet-20240229',
|
|
790
822
|
temperature: 0.7,
|
|
791
|
-
provider: '
|
|
823
|
+
provider: 'api2img',
|
|
792
824
|
});
|
|
793
825
|
|
|
794
826
|
// 使用示例
|
|
@@ -838,12 +870,11 @@ const response = await doubaoModel.invoke([
|
|
|
838
870
|
|
|
839
871
|
| Provider | 适用场景 | 支持的模型 |
|
|
840
872
|
|----------|----------|------------|
|
|
841
|
-
| `aihubmix` | 多模型聚合,统一接口 | GPT、Gemini、Claude、Doubao 等 |
|
|
842
873
|
| `gemini` | 直接使用 Google Gemini API | 所有 Gemini 模型 |
|
|
843
874
|
| `api2img` | 使用 api2img 聚合服务 | 所有模型 |
|
|
844
875
|
| `doubao` | 使用豆包服务 | Doubao 系列模型 |
|
|
845
876
|
|
|
846
|
-
**推荐使用 `
|
|
877
|
+
**推荐使用 `api2img` provider**,因为它提供了统一的接口和更好的模型选择灵活性。
|
|
847
878
|
|
|
848
879
|
## 完整示例
|
|
849
880
|
|
|
@@ -883,7 +914,7 @@ import { ChatOpenAI, HumanMessage, AIMessageChunk } from 'ai-world-sdk';
|
|
|
883
914
|
const model = new ChatOpenAI({
|
|
884
915
|
modelName: 'gpt-5.2',
|
|
885
916
|
temperature: 0.7,
|
|
886
|
-
provider: '
|
|
917
|
+
provider: 'api2img',
|
|
887
918
|
reasoning: {
|
|
888
919
|
effort: 'high', // 'low' | 'medium' | 'high'
|
|
889
920
|
summary: 'detailed', // 'detailed' | 'auto'(可选)
|
|
@@ -935,7 +966,7 @@ import { ChatAnthropic, HumanMessage } from 'ai-world-sdk';
|
|
|
935
966
|
const model = new ChatAnthropic({
|
|
936
967
|
modelName: 'claude-3-5-sonnet-20241022',
|
|
937
968
|
temperature: 0.7,
|
|
938
|
-
provider: '
|
|
969
|
+
provider: 'api2img',
|
|
939
970
|
reasoning: {
|
|
940
971
|
type: 'enabled',
|
|
941
972
|
budget_tokens: 5000, // 思考预算(token 数量)
|
|
@@ -983,7 +1014,7 @@ import { ChatOpenAI, ChatGoogleGenerativeAI, HumanMessage, createChatModel } fro
|
|
|
983
1014
|
const openaiModel = new ChatOpenAI({
|
|
984
1015
|
modelName: 'gpt-4o-mini',
|
|
985
1016
|
temperature: 0.7,
|
|
986
|
-
provider: '
|
|
1017
|
+
provider: 'api2img',
|
|
987
1018
|
jsonSchema: {
|
|
988
1019
|
type: 'object',
|
|
989
1020
|
properties: {
|
|
@@ -1039,7 +1070,7 @@ const response = await geminiModel.invoke([
|
|
|
1039
1070
|
```typescript
|
|
1040
1071
|
const model = createChatModel('gpt-4o-mini', {
|
|
1041
1072
|
temperature: 0.7,
|
|
1042
|
-
provider: '
|
|
1073
|
+
provider: 'api2img',
|
|
1043
1074
|
jsonSchema: {
|
|
1044
1075
|
type: 'object',
|
|
1045
1076
|
properties: {
|
|
@@ -1139,7 +1170,7 @@ const geminiModel = createChatModel('gemini-2.0-flash-exp', {
|
|
|
1139
1170
|
|
|
1140
1171
|
// OpenAI 兼容模型(使用 web_search 工具)
|
|
1141
1172
|
const openaiModel = createChatModel('gpt-4o-mini', {
|
|
1142
|
-
provider: '
|
|
1173
|
+
provider: 'api2img',
|
|
1143
1174
|
webSearch: true,
|
|
1144
1175
|
});
|
|
1145
1176
|
|
|
@@ -1399,7 +1430,7 @@ const client = new OpenAIVideoGenerationClient({});
|
|
|
1399
1430
|
const task = await client.generate({
|
|
1400
1431
|
prompt: 'A serene mountain landscape with a flowing river',
|
|
1401
1432
|
model: 'sora-2', // 'sora-2' 或 'sora-2-pro'
|
|
1402
|
-
provider: '
|
|
1433
|
+
provider: 'api2img', // 'api2img' 或 'api2img'
|
|
1403
1434
|
seconds: '4', // '4', '8', 或 '12'
|
|
1404
1435
|
size: '1280x720' // '720x1280', '1280x720', '1024x1792', '1792x1024'
|
|
1405
1436
|
});
|
|
@@ -1408,13 +1439,13 @@ console.log('任务已创建:', task.id);
|
|
|
1408
1439
|
console.log('任务状态:', task.status);
|
|
1409
1440
|
|
|
1410
1441
|
// 2. 查询任务状态
|
|
1411
|
-
const status = await client.getTask(task.id, '
|
|
1442
|
+
const status = await client.getTask(task.id, 'api2img');
|
|
1412
1443
|
console.log('当前状态:', status.status);
|
|
1413
1444
|
|
|
1414
1445
|
// 3. 轮询等待完成
|
|
1415
1446
|
const result = await client.waitForCompletion(
|
|
1416
1447
|
task.id,
|
|
1417
|
-
'
|
|
1448
|
+
'api2img', // provider 参数
|
|
1418
1449
|
{
|
|
1419
1450
|
maxAttempts: 60,
|
|
1420
1451
|
interval: 5000,
|
|
@@ -1433,7 +1464,7 @@ if (result.status === 'completed') {
|
|
|
1433
1464
|
// 4. 流式下载视频
|
|
1434
1465
|
const videoBlob = await client.downloadVideo(
|
|
1435
1466
|
result.id,
|
|
1436
|
-
'
|
|
1467
|
+
'api2img', // provider
|
|
1437
1468
|
'video' // 'video' 或 'thumbnail'
|
|
1438
1469
|
);
|
|
1439
1470
|
|
|
@@ -1451,7 +1482,7 @@ if (result.status === 'completed') {
|
|
|
1451
1482
|
// 也可以下载缩略图
|
|
1452
1483
|
const thumbnail = await client.downloadVideo(
|
|
1453
1484
|
result.id,
|
|
1454
|
-
'
|
|
1485
|
+
'api2img',
|
|
1455
1486
|
'thumbnail'
|
|
1456
1487
|
);
|
|
1457
1488
|
console.log('缩略图大小:', (thumbnail.size / 1024).toFixed(2), 'KB');
|
|
@@ -1464,7 +1495,7 @@ try {
|
|
|
1464
1495
|
const result2 = await client.generateAndWait({
|
|
1465
1496
|
prompt: 'A futuristic city with flying cars at night',
|
|
1466
1497
|
model: 'sora-2',
|
|
1467
|
-
provider: '
|
|
1498
|
+
provider: 'api2img',
|
|
1468
1499
|
seconds: '8',
|
|
1469
1500
|
size: '1280x720'
|
|
1470
1501
|
}, {
|
|
@@ -1478,7 +1509,7 @@ try {
|
|
|
1478
1509
|
// 流式下载
|
|
1479
1510
|
const video = await client.downloadVideo(
|
|
1480
1511
|
result2.id,
|
|
1481
|
-
'
|
|
1512
|
+
'api2img',
|
|
1482
1513
|
'video'
|
|
1483
1514
|
);
|
|
1484
1515
|
console.log('视频大小:', (video.size / 1024 / 1024).toFixed(2), 'MB');
|
|
@@ -1491,13 +1522,13 @@ const imageToVideoTask = await client.generate({
|
|
|
1491
1522
|
prompt: 'Make this scene come alive with gentle movements',
|
|
1492
1523
|
input_reference: 'data:image/png;base64,iVBORw0KGgo...', // 图像 base64 或 URL
|
|
1493
1524
|
model: 'sora-2',
|
|
1494
|
-
provider: '
|
|
1525
|
+
provider: 'api2img',
|
|
1495
1526
|
seconds: '4'
|
|
1496
1527
|
});
|
|
1497
1528
|
|
|
1498
1529
|
const imageToVideoResult = await client.waitForCompletion(
|
|
1499
1530
|
imageToVideoTask.id,
|
|
1500
|
-
'
|
|
1531
|
+
'api2img'
|
|
1501
1532
|
);
|
|
1502
1533
|
|
|
1503
1534
|
if (imageToVideoResult.status === 'completed') {
|
|
@@ -1506,7 +1537,7 @@ if (imageToVideoResult.status === 'completed') {
|
|
|
1506
1537
|
// 下载视频
|
|
1507
1538
|
const videoBlob = await client.downloadVideo(
|
|
1508
1539
|
imageToVideoResult.id,
|
|
1509
|
-
'
|
|
1540
|
+
'api2img',
|
|
1510
1541
|
'video'
|
|
1511
1542
|
);
|
|
1512
1543
|
console.log('视频已下载,大小:', videoBlob.size);
|
|
@@ -1648,16 +1679,16 @@ for await (const chunk of client.streamDownload({
|
|
|
1648
1679
|
|
|
1649
1680
|
| 提供商 | Provider | 模型示例 | 模型类 | 支持推理 |
|
|
1650
1681
|
|--------|----------|----------|--------|---------|
|
|
1651
|
-
| OpenAI | `
|
|
1652
|
-
| OpenAI | `
|
|
1653
|
-
| Google Gemini | `gemini` 或 `
|
|
1654
|
-
| Google Gemini | `gemini` 或 `
|
|
1655
|
-
| Anthropic Claude | `
|
|
1656
|
-
| Anthropic Claude | `
|
|
1657
|
-
| Doubao | `doubao` 或 `
|
|
1682
|
+
| OpenAI | `api2img` | `gpt-4o-mini`, `gpt-4` | `ChatOpenAI` | ❌ |
|
|
1683
|
+
| OpenAI | `api2img` | `o1-preview`, `o1-mini`, `gpt-5.2` | `ChatOpenAI` | ✅ |
|
|
1684
|
+
| Google Gemini | `gemini` 或 `api2img` | `gemini-2.5-flash-image` | `ChatGoogleGenerativeAI` | ❌ |
|
|
1685
|
+
| Google Gemini | `gemini` 或 `api2img` | `gemini-3-pro-preview` | `ChatGoogleGenerativeAI` | ✅ |
|
|
1686
|
+
| Anthropic Claude | `api2img` | `claude-3-sonnet-20240229` | `ChatAnthropic` | ❌ |
|
|
1687
|
+
| Anthropic Claude | `api2img` | `claude-3-5-sonnet-20241022` | `ChatAnthropic` | ✅ |
|
|
1688
|
+
| Doubao | `doubao` 或 `api2img` | `doubao-pro-4k`, `doubao-seedream-4-5-251128` | `ChatOpenAI` | ❌ |
|
|
1658
1689
|
|
|
1659
1690
|
**注意:**
|
|
1660
|
-
- 使用 `
|
|
1691
|
+
- 使用 `api2img` 或 `api2img` provider 可以访问所有模型,推荐用于多模型场景
|
|
1661
1692
|
- 使用特定 provider(如 `gemini`、`doubao`)会直接调用对应的官方 API
|
|
1662
1693
|
- 支持推理的模型可以通过 `reasoning` 参数启用思考/推理功能
|
|
1663
1694
|
|
|
@@ -1689,15 +1720,15 @@ for await (const chunk of client.streamDownload({
|
|
|
1689
1720
|
|
|
1690
1721
|
| 模型 | Provider | 说明 | 参数 |
|
|
1691
1722
|
|------|----------|------|------|
|
|
1692
|
-
| `sora-2` | `
|
|
1693
|
-
| `sora-2-pro` | `
|
|
1723
|
+
| `sora-2` | `api2img` | 标准模型(默认) | 时长: 4/8/12秒,分辨率: 720x1280, 1280x720, 1024x1792, 1792x1024 |
|
|
1724
|
+
| `sora-2-pro` | `api2img` | 专业版模型 | 时长: 4/8/12秒,分辨率: 720x1280, 1280x720, 1024x1792, 1792x1024 |
|
|
1694
1725
|
|
|
1695
1726
|
**特性说明:**
|
|
1696
1727
|
- **豆包 Seedance**: 支持文本生成视频和图像生成视频,URL 直接返回
|
|
1697
1728
|
- **OpenAI Sora**: 支持文本生成视频和图像生成视频(Base64/URL),需要流式下载
|
|
1698
1729
|
- **Provider 选择**:
|
|
1699
1730
|
- 豆包: 仅支持 `doubao` provider
|
|
1700
|
-
- OpenAI: 支持 `
|
|
1731
|
+
- OpenAI: 支持 `api2img` provider
|
|
1701
1732
|
|
|
1702
1733
|
## 错误处理
|
|
1703
1734
|
|
|
@@ -1726,15 +1757,30 @@ npm run build
|
|
|
1726
1757
|
### 测试
|
|
1727
1758
|
|
|
1728
1759
|
```bash
|
|
1729
|
-
npm test
|
|
1730
|
-
#
|
|
1760
|
+
npm test # 运行所有单元测试
|
|
1761
|
+
npm run test:llm # 运行 llm.ts 单元测试(mock,不需要后端)
|
|
1762
|
+
npm run test:llm-real # 运行 llm.ts 真实集成测试(需要运行中的后端 + AUTH_TOKEN)
|
|
1763
|
+
|
|
1764
|
+
# 其他特定测试
|
|
1731
1765
|
npm run test:stream
|
|
1732
1766
|
npm run test:image-generation
|
|
1733
1767
|
npm run test:video-generation
|
|
1734
1768
|
```
|
|
1735
1769
|
|
|
1770
|
+
#### 真实集成测试
|
|
1771
|
+
|
|
1772
|
+
`llm.real.test.ts` 通过运行中的后端代理测试 `createProvider` 和 `checkModel`:
|
|
1773
|
+
|
|
1774
|
+
1. 确保后端运行在 `http://localhost:8000`
|
|
1775
|
+
2. 在 `ai-world-sdk/.env` 中配置 `AUTH_TOKEN=your_jwt_token`
|
|
1776
|
+
3. 运行 `npm run test:llm-real`
|
|
1777
|
+
|
|
1778
|
+
测试覆盖 OpenAI (api2img)、Gemini、Anthropic 的非流式和流式文本生成。
|
|
1779
|
+
图像生成请手动运行 `example.test.ts` 中的相关用例。
|
|
1780
|
+
|
|
1736
1781
|
## 参考链接
|
|
1737
1782
|
|
|
1783
|
+
- [Vercel AI SDK](https://ai-sdk.dev/docs) - `createProvider` 基于此构建,推荐使用 `generateText`、`streamText`、`generateImage` 等标准函数
|
|
1738
1784
|
- [LangChain.js](https://github.com/langchain-ai/langchainjs) - 设计灵感来源
|
|
1739
1785
|
- [火山引擎方舟平台](https://www.volcengine.com/docs/82379) - 图像/视频生成 API 文档
|
|
1740
1786
|
|
|
@@ -1744,6 +1790,9 @@ MIT
|
|
|
1744
1790
|
|
|
1745
1791
|
## 更新日志
|
|
1746
1792
|
|
|
1793
|
+
### 1.2.1
|
|
1794
|
+
- ✨ 导出 `AIEndpointType` 类型,方便外部使用 `createProvider` 时引用端点类型
|
|
1795
|
+
|
|
1747
1796
|
### 1.0.3
|
|
1748
1797
|
- ✨ 新增 Google Gemini 图像生成客户端
|
|
1749
1798
|
- ✨ 全局配置支持自动从浏览器环境获取
|