@weisiren000/oiiai 0.2.1 → 0.2.2
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 +137 -2
- package/dist/index.d.mts +162 -4
- package/dist/index.d.ts +162 -4
- package/dist/index.js +199 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +198 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[](LICENSE)
|
|
10
10
|
[](https://www.npmjs.com/package/@weisiren000/oiiai)
|
|
11
11
|
|
|
12
|
-
支持 **OpenRouter** · **Gemini** · **Groq** · **HuggingFace** · **ModelScope** · **DeepSeek** · **Poe** · **Nova** · **Zhipu**
|
|
12
|
+
支持 **OpenRouter** · **Gemini** · **Groq** · **HuggingFace** · **ModelScope** · **DeepSeek** · **Poe** · **Nova** · **Zhipu** · **SiliconFlow**
|
|
13
13
|
|
|
14
14
|
[📖 详细文档](./docs/providers.md) · [🚀 快速开始](#快速开始) · [💡 示例](#使用示例) · [🔗 Fluent API](#-fluent-api-新)
|
|
15
15
|
|
|
@@ -95,7 +95,14 @@ const provider = createProvider({
|
|
|
95
95
|
预配置的 Provider 实例,开箱即用:
|
|
96
96
|
|
|
97
97
|
```typescript
|
|
98
|
-
import {
|
|
98
|
+
import {
|
|
99
|
+
deepseek,
|
|
100
|
+
openrouter,
|
|
101
|
+
gemini,
|
|
102
|
+
groq,
|
|
103
|
+
zhipu,
|
|
104
|
+
siliconflow,
|
|
105
|
+
} from '@weisiren000/oiiai';
|
|
99
106
|
|
|
100
107
|
// 配置 API Key(二选一)
|
|
101
108
|
deepseek.configure({ apiKey: 'your-key' }); // 显式配置
|
|
@@ -186,6 +193,79 @@ const answer = await builder
|
|
|
186
193
|
.ask('写一首关于春天的诗');
|
|
187
194
|
```
|
|
188
195
|
|
|
196
|
+
### 多模态支持
|
|
197
|
+
|
|
198
|
+
Fluent API 链式构建器原生支持多模态输入(图像、视频、音频),提供简洁的链式调用接口:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { oiiai, siliconflow } from '@weisiren000/oiiai';
|
|
202
|
+
|
|
203
|
+
// 配置
|
|
204
|
+
siliconflow.configure({ apiKey: 'your-key' });
|
|
205
|
+
|
|
206
|
+
// 图像分析
|
|
207
|
+
const answer = await oiiai
|
|
208
|
+
.use('siliconflow')
|
|
209
|
+
.key('your-key')
|
|
210
|
+
.model('Qwen/Qwen2.5-VL-72B-Instruct')
|
|
211
|
+
.image('https://example.com/image.jpg', { detail: 'high' })
|
|
212
|
+
.ask('描述这张图片');
|
|
213
|
+
|
|
214
|
+
// 多图对比
|
|
215
|
+
const answer = await oiiai
|
|
216
|
+
.use('siliconflow')
|
|
217
|
+
.key('your-key')
|
|
218
|
+
.model('Qwen/Qwen2.5-VL-72B-Instruct')
|
|
219
|
+
.image('https://example.com/image1.jpg')
|
|
220
|
+
.image('https://example.com/image2.jpg')
|
|
221
|
+
.ask('比较这两张图片');
|
|
222
|
+
|
|
223
|
+
// 视频分析
|
|
224
|
+
const answer = await oiiai
|
|
225
|
+
.use('siliconflow')
|
|
226
|
+
.key('your-key')
|
|
227
|
+
.model('Qwen/Qwen3-Omni-30B-A3B-Instruct')
|
|
228
|
+
.video('https://example.com/video.mp4', { maxFrames: 4, fps: 1 })
|
|
229
|
+
.ask('视频里发生了什么?');
|
|
230
|
+
|
|
231
|
+
// 音频理解
|
|
232
|
+
const answer = await oiiai
|
|
233
|
+
.use('siliconflow')
|
|
234
|
+
.key('your-key')
|
|
235
|
+
.model('Qwen/Qwen3-Omni-30B-A3B-Instruct')
|
|
236
|
+
.audio('https://example.com/audio.mp3')
|
|
237
|
+
.ask('这段音频说了什么?');
|
|
238
|
+
|
|
239
|
+
// 混合多模态 + 流式输出
|
|
240
|
+
for await (const chunk of oiiai
|
|
241
|
+
.use('siliconflow')
|
|
242
|
+
.key('your-key')
|
|
243
|
+
.model('Qwen/Qwen3-Omni-30B-A3B-Instruct')
|
|
244
|
+
.image('https://example.com/image.jpg')
|
|
245
|
+
.audio('https://example.com/audio.mp3')
|
|
246
|
+
.stream()
|
|
247
|
+
.ask('分析这张图片和音频')) {
|
|
248
|
+
process.stdout.write(chunk.text);
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
#### 多模态方法说明
|
|
253
|
+
|
|
254
|
+
- **`image(url, options?)`** - 添加图像内容
|
|
255
|
+
- `url`: 图像 URL 或 Base64 (`data:image/jpeg;base64,...`)
|
|
256
|
+
- `options.detail`: `'auto' | 'low' | 'high'` - 分析精度
|
|
257
|
+
|
|
258
|
+
- **`video(url, options?)`** - 添加视频内容
|
|
259
|
+
- `url`: 视频 URL 或 Base64 (`data:video/mp4;base64,...`)
|
|
260
|
+
- `options.maxFrames`: 最大提取帧数(默认取决于模型)
|
|
261
|
+
- `options.fps`: 每秒提取帧数
|
|
262
|
+
- `options.detail`: `'auto' | 'low' | 'high'` - 分析精度
|
|
263
|
+
|
|
264
|
+
- **`audio(url)`** - 添加音频内容
|
|
265
|
+
- `url`: 音频 URL 或 Base64 (`data:audio/mp3;base64,...`)
|
|
266
|
+
|
|
267
|
+
**注意**: 多模态功能需要使用支持多模态的模型(如 SiliconFlow 的 Qwen VL 系列)。
|
|
268
|
+
|
|
189
269
|
### 多轮对话
|
|
190
270
|
|
|
191
271
|
内置对话会话管理,自动维护上下文:
|
|
@@ -285,6 +365,52 @@ console.log('思考过程:', result.reasoning);
|
|
|
285
365
|
console.log('最终答案:', result.content);
|
|
286
366
|
```
|
|
287
367
|
|
|
368
|
+
### 多模态图像理解(SiliconFlow)
|
|
369
|
+
|
|
370
|
+
SiliconFlow 支持多模态输入,可以处理图像、视频、音频:
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
import { siliconflow } from '@weisiren000/oiiai';
|
|
374
|
+
|
|
375
|
+
siliconflow.configure({ apiKey: 'your-key' });
|
|
376
|
+
|
|
377
|
+
// 分析图片
|
|
378
|
+
const answer = await siliconflow.chat('Qwen/Qwen2.5-VL-72B-Instruct', {
|
|
379
|
+
messages: [
|
|
380
|
+
{
|
|
381
|
+
role: 'user',
|
|
382
|
+
content: [
|
|
383
|
+
{
|
|
384
|
+
type: 'image_url',
|
|
385
|
+
image_url: { url: 'https://example.com/image.jpg' },
|
|
386
|
+
},
|
|
387
|
+
{ type: 'text', text: '描述这张图片' },
|
|
388
|
+
],
|
|
389
|
+
},
|
|
390
|
+
],
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// 分析视频
|
|
394
|
+
const answer2 = await siliconflow.chat('Qwen/Qwen3-Omni-30B-A3B-Instruct', {
|
|
395
|
+
messages: [
|
|
396
|
+
{
|
|
397
|
+
role: 'user',
|
|
398
|
+
content: [
|
|
399
|
+
{
|
|
400
|
+
type: 'video_url',
|
|
401
|
+
video_url: {
|
|
402
|
+
url: 'data:video/mp4;base64,...',
|
|
403
|
+
max_frames: 4,
|
|
404
|
+
fps: 1,
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
{ type: 'text', text: '视频里发生了什么?' },
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
});
|
|
412
|
+
```
|
|
413
|
+
|
|
288
414
|
## 🔧 支持的 Provider
|
|
289
415
|
|
|
290
416
|
| Provider | 服务商 | Reasoning 参数 | 支持思考模型 | 环境变量 |
|
|
@@ -298,6 +424,7 @@ console.log('最终答案:', result.content);
|
|
|
298
424
|
| `poe` | Poe | `reasoning_effort` | ✅ | `POE_API_KEY` |
|
|
299
425
|
| `nova` | AWS Nova | `reasoningConfig.type` | ✅ | `NOVA_API_KEY` |
|
|
300
426
|
| `zhipu` | 智谱AI | 暂不支持 | ❌ | `ZHIPU_API_KEY` |
|
|
427
|
+
| `siliconflow` | SiliconFlow | `thinking_budget` | ✅ | `SILICONFLOW_API_KEY` |
|
|
301
428
|
|
|
302
429
|
## 📝 常用模型
|
|
303
430
|
|
|
@@ -333,6 +460,14 @@ console.log('最终答案:', result.content);
|
|
|
333
460
|
'glm-4-flash'; // 快速响应模型
|
|
334
461
|
'glm-4-air'; // 轻量级模型
|
|
335
462
|
'glm-4-long'; // 长文本处理模型
|
|
463
|
+
|
|
464
|
+
// SiliconFlow
|
|
465
|
+
'deepseek-ai/DeepSeek-V3'; // 通用对话
|
|
466
|
+
'deepseek-ai/DeepSeek-R1'; // 推理模型
|
|
467
|
+
'Qwen/Qwen2.5-VL-72B-Instruct'; // 视觉理解
|
|
468
|
+
'Qwen/Qwen3-Omni-30B-A3B-Instruct'; // 多模态全能
|
|
469
|
+
'Qwen/Qwen3-VL-7B-Instruct'; // 视觉模型
|
|
470
|
+
'zai-org/GLM-4.6V'; // 视觉对话
|
|
336
471
|
```
|
|
337
472
|
|
|
338
473
|
## 🌍 环境变量
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AI Provider 统一类型定义
|
|
3
3
|
*/
|
|
4
|
+
/**
|
|
5
|
+
* 文本内容部分
|
|
6
|
+
*/
|
|
7
|
+
interface TextContentPart {
|
|
8
|
+
type: 'text';
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 图像 URL 配置
|
|
13
|
+
*/
|
|
14
|
+
interface ImageUrlConfig {
|
|
15
|
+
/** 图像 URL 或 base64 编码数据 */
|
|
16
|
+
url: string;
|
|
17
|
+
/** 细节级别 */
|
|
18
|
+
detail?: 'auto' | 'low' | 'high';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 图像内容部分
|
|
22
|
+
*/
|
|
23
|
+
interface ImageContentPart {
|
|
24
|
+
type: 'image_url';
|
|
25
|
+
image_url: ImageUrlConfig;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 视频 URL 配置
|
|
29
|
+
*/
|
|
30
|
+
interface VideoUrlConfig {
|
|
31
|
+
/** 视频 URL 或 base64 编码数据 */
|
|
32
|
+
url: string;
|
|
33
|
+
/** 细节级别 */
|
|
34
|
+
detail?: 'auto' | 'low' | 'high';
|
|
35
|
+
/** 最大提取帧数 */
|
|
36
|
+
max_frames?: number;
|
|
37
|
+
/** 每秒提取帧数 */
|
|
38
|
+
fps?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 视频内容部分
|
|
42
|
+
*/
|
|
43
|
+
interface VideoContentPart {
|
|
44
|
+
type: 'video_url';
|
|
45
|
+
video_url: VideoUrlConfig;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 音频 URL 配置
|
|
49
|
+
*/
|
|
50
|
+
interface AudioUrlConfig {
|
|
51
|
+
/** 音频 URL 或 base64 编码数据 */
|
|
52
|
+
url: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 音频内容部分
|
|
56
|
+
*/
|
|
57
|
+
interface AudioContentPart {
|
|
58
|
+
type: 'audio_url';
|
|
59
|
+
audio_url: AudioUrlConfig;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 多模态内容部分联合类型
|
|
63
|
+
*/
|
|
64
|
+
type ContentPart = TextContentPart | ImageContentPart | VideoContentPart | AudioContentPart;
|
|
65
|
+
/**
|
|
66
|
+
* 消息内容类型 - 支持纯文本或多模态内容数组
|
|
67
|
+
*/
|
|
68
|
+
type MessageContent = string | ContentPart[];
|
|
4
69
|
interface ChatMessage {
|
|
5
70
|
role: 'system' | 'user' | 'assistant';
|
|
6
|
-
content:
|
|
71
|
+
content: MessageContent;
|
|
7
72
|
}
|
|
8
73
|
/**
|
|
9
74
|
* 统一的思考努力程度
|
|
@@ -282,7 +347,7 @@ declare abstract class BaseProvider implements AIProvider {
|
|
|
282
347
|
/**
|
|
283
348
|
* Provider 类型
|
|
284
349
|
*/
|
|
285
|
-
type ProviderType$2 = 'openrouter' | 'gemini' | 'groq' | 'huggingface' | 'modelscope' | 'deepseek' | 'poe' | 'nova' | 'zhipu';
|
|
350
|
+
type ProviderType$2 = 'openrouter' | 'gemini' | 'groq' | 'huggingface' | 'modelscope' | 'deepseek' | 'poe' | 'nova' | 'zhipu' | 'siliconflow';
|
|
286
351
|
/**
|
|
287
352
|
* 统一的 Provider 配置格式
|
|
288
353
|
* 用于配置各种 AI Provider 的连接和行为
|
|
@@ -437,6 +502,7 @@ declare const ai: {
|
|
|
437
502
|
poe: (apiKey: string, baseUrl?: string) => AIProvider;
|
|
438
503
|
nova: (apiKey: string, baseUrl?: string) => AIProvider;
|
|
439
504
|
zhipu: (apiKey: string, baseUrl?: string) => AIProvider;
|
|
505
|
+
siliconflow: (apiKey: string, baseUrl?: string) => AIProvider;
|
|
440
506
|
};
|
|
441
507
|
|
|
442
508
|
/**
|
|
@@ -1148,7 +1214,7 @@ declare class HttpProviderClient implements ProviderClient {
|
|
|
1148
1214
|
* Provider 类型枚举
|
|
1149
1215
|
* 支持的所有 Provider 类型
|
|
1150
1216
|
*/
|
|
1151
|
-
type ProviderType = 'openrouter' | 'gemini' | 'groq' | 'huggingface' | 'modelscope' | 'deepseek' | 'poe' | 'nova' | 'zhipu';
|
|
1217
|
+
type ProviderType = 'openrouter' | 'gemini' | 'groq' | 'huggingface' | 'modelscope' | 'deepseek' | 'poe' | 'nova' | 'zhipu' | 'siliconflow';
|
|
1152
1218
|
/**
|
|
1153
1219
|
* 适配器配置
|
|
1154
1220
|
* 用于创建适配器实例时的配置
|
|
@@ -1799,6 +1865,32 @@ declare function createBuiltInAdapters(): Map<ProviderType, ProviderAdapter>;
|
|
|
1799
1865
|
* 提供链式调用和预设实例的类型支持
|
|
1800
1866
|
*/
|
|
1801
1867
|
|
|
1868
|
+
/**
|
|
1869
|
+
* 图像配置选项
|
|
1870
|
+
*/
|
|
1871
|
+
interface ImageOptions {
|
|
1872
|
+
/** 细节级别 */
|
|
1873
|
+
detail?: 'auto' | 'low' | 'high';
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* 视频配置选项
|
|
1877
|
+
*/
|
|
1878
|
+
interface VideoOptions {
|
|
1879
|
+
/** 细节级别 */
|
|
1880
|
+
detail?: 'auto' | 'low' | 'high';
|
|
1881
|
+
/** 最大提取帧数 */
|
|
1882
|
+
maxFrames?: number;
|
|
1883
|
+
/** 每秒提取帧数 */
|
|
1884
|
+
fps?: number;
|
|
1885
|
+
}
|
|
1886
|
+
/**
|
|
1887
|
+
* 多模态内容项(内部使用)
|
|
1888
|
+
*/
|
|
1889
|
+
interface MultimodalItem {
|
|
1890
|
+
type: 'image' | 'video' | 'audio';
|
|
1891
|
+
url: string;
|
|
1892
|
+
options?: ImageOptions | VideoOptions;
|
|
1893
|
+
}
|
|
1802
1894
|
/**
|
|
1803
1895
|
* 问答选项
|
|
1804
1896
|
* 用于配置单次 AI 调用的参数
|
|
@@ -1892,6 +1984,8 @@ interface BuilderConfig {
|
|
|
1892
1984
|
reasoning?: ReasoningConfig;
|
|
1893
1985
|
/** 是否流式请求 */
|
|
1894
1986
|
isStream?: boolean;
|
|
1987
|
+
/** 多模态内容列表 */
|
|
1988
|
+
multimodal?: MultimodalItem[];
|
|
1895
1989
|
}
|
|
1896
1990
|
/**
|
|
1897
1991
|
* 链式调用构建器接口
|
|
@@ -1899,12 +1993,21 @@ interface BuilderConfig {
|
|
|
1899
1993
|
*
|
|
1900
1994
|
* @example
|
|
1901
1995
|
* ```typescript
|
|
1996
|
+
* // 纯文本请求
|
|
1902
1997
|
* const answer = await oiiai
|
|
1903
1998
|
* .use('deepseek')
|
|
1904
1999
|
* .key('your-api-key')
|
|
1905
2000
|
* .model('deepseek-chat')
|
|
1906
2001
|
* .system('你是助手')
|
|
1907
2002
|
* .ask('你好');
|
|
2003
|
+
*
|
|
2004
|
+
* // 多模态请求
|
|
2005
|
+
* const answer = await oiiai
|
|
2006
|
+
* .use('siliconflow')
|
|
2007
|
+
* .key('your-api-key')
|
|
2008
|
+
* .model('Qwen/Qwen2.5-VL-72B-Instruct')
|
|
2009
|
+
* .image('https://example.com/image.jpg', { detail: 'high' })
|
|
2010
|
+
* .ask('描述这张图片');
|
|
1908
2011
|
* ```
|
|
1909
2012
|
*/
|
|
1910
2013
|
interface OiiaiBuilder {
|
|
@@ -1956,6 +2059,55 @@ interface OiiaiBuilder {
|
|
|
1956
2059
|
* @returns this 支持链式调用
|
|
1957
2060
|
*/
|
|
1958
2061
|
baseUrl(url: string): this;
|
|
2062
|
+
/**
|
|
2063
|
+
* 添加图像内容(多模态)
|
|
2064
|
+
* 支持 URL 或 base64 编码的图像数据
|
|
2065
|
+
* @param url - 图像 URL 或 base64 data URL
|
|
2066
|
+
* @param options - 图像配置选项
|
|
2067
|
+
* @returns this 支持链式调用
|
|
2068
|
+
*
|
|
2069
|
+
* @example
|
|
2070
|
+
* ```typescript
|
|
2071
|
+
* // 使用 URL
|
|
2072
|
+
* builder.image('https://example.com/image.jpg')
|
|
2073
|
+
*
|
|
2074
|
+
* // 使用 base64
|
|
2075
|
+
* builder.image('data:image/jpeg;base64,...', { detail: 'high' })
|
|
2076
|
+
*
|
|
2077
|
+
* // 多张图片
|
|
2078
|
+
* builder.image(url1).image(url2).ask('比较这两张图片')
|
|
2079
|
+
* ```
|
|
2080
|
+
*/
|
|
2081
|
+
image(url: string, options?: ImageOptions): this;
|
|
2082
|
+
/**
|
|
2083
|
+
* 添加视频内容(多模态)
|
|
2084
|
+
* 支持 URL 或 base64 编码的视频数据
|
|
2085
|
+
* @param url - 视频 URL 或 base64 data URL
|
|
2086
|
+
* @param options - 视频配置选项
|
|
2087
|
+
* @returns this 支持链式调用
|
|
2088
|
+
*
|
|
2089
|
+
* @example
|
|
2090
|
+
* ```typescript
|
|
2091
|
+
* builder
|
|
2092
|
+
* .video('https://example.com/video.mp4', { maxFrames: 8, fps: 1 })
|
|
2093
|
+
* .ask('描述这个视频的内容')
|
|
2094
|
+
* ```
|
|
2095
|
+
*/
|
|
2096
|
+
video(url: string, options?: VideoOptions): this;
|
|
2097
|
+
/**
|
|
2098
|
+
* 添加音频内容(多模态)
|
|
2099
|
+
* 支持 URL 或 base64 编码的音频数据
|
|
2100
|
+
* @param url - 音频 URL 或 base64 data URL
|
|
2101
|
+
* @returns this 支持链式调用
|
|
2102
|
+
*
|
|
2103
|
+
* @example
|
|
2104
|
+
* ```typescript
|
|
2105
|
+
* builder
|
|
2106
|
+
* .audio('data:audio/mp3;base64,...')
|
|
2107
|
+
* .ask('这段音频说了什么?')
|
|
2108
|
+
* ```
|
|
2109
|
+
*/
|
|
2110
|
+
audio(url: string): this;
|
|
1959
2111
|
/**
|
|
1960
2112
|
* 标记为流式请求
|
|
1961
2113
|
* 调用后 ask() 将返回 AsyncGenerator
|
|
@@ -2178,5 +2330,11 @@ declare const nova: PresetProvider;
|
|
|
2178
2330
|
* 环境变量: ZHIPU_API_KEY
|
|
2179
2331
|
*/
|
|
2180
2332
|
declare const zhipu: PresetProvider;
|
|
2333
|
+
/**
|
|
2334
|
+
* SiliconFlow 预设实例
|
|
2335
|
+
* 环境变量: SILICONFLOW_API_KEY
|
|
2336
|
+
* 支持多模态模型(视觉/音频/视频)
|
|
2337
|
+
*/
|
|
2338
|
+
declare const siliconflow: PresetProvider;
|
|
2181
2339
|
|
|
2182
|
-
export { type AIProvider, APIError, type AdapterConfig, type AskOptions, BaseAdapter, BaseProvider, type BuilderConfig, CONFIG_DEFAULTS, type ChatMessage, type ChatOptions, type ChatResult, type ChatSession, type ChatSessionOptions, ConfigManager, ConfigValidator, ConfigurationError, DeepSeekAdapter, type DeltaExtractor, EFFORT_TOKEN_MAP, ValidationError as FluentValidationError, GeminiAdapter, GeminiProvider, GroqAdapter, GroqProvider, HttpProviderClient, HuggingFaceAdapter, HuggingFaceProvider, type LegacyProviderConfig, type ModelInfo, type ModelPricing, ModelScopeAdapter, ModelScopeProvider, NetworkError, NovaAdapter, type OiiaiBuilder, OpenRouterAdapter, type OpenRouterModelInfo, OpenRouterProvider, PoeAdapter, type PresetConfigOptions, type PresetProvider, type ProviderAdapter, type ProviderCapabilities, type ProviderClient, type ProviderClientConfig, type ProviderConfig, ProviderError, ProviderRegistry, type ProviderType$2 as ProviderType, type ReasoningConfig, type ReasoningEffort, type RegistryConfig, RegistryError, RequestBuilder, type StreamBuilder, type StreamCallbacks, type StreamChunk, StreamProcessor, TimeoutError, type TokenUsage, type UnifiedProviderConfig, VALID_PROVIDERS, type ValidationError$1 as ValidationError, type ValidationResult, ZhipuAdapter, ai, createBuilder, createBuiltInAdapters, createProvider, deepseek, gemini, groq, huggingface, modelscope, nova, oiiai, openrouter, poe, zhipu };
|
|
2340
|
+
export { type AIProvider, APIError, type AdapterConfig, type AskOptions, type AudioContentPart, type AudioUrlConfig, BaseAdapter, BaseProvider, type BuilderConfig, CONFIG_DEFAULTS, type ChatMessage, type ChatOptions, type ChatResult, type ChatSession, type ChatSessionOptions, ConfigManager, ConfigValidator, ConfigurationError, type ContentPart, DeepSeekAdapter, type DeltaExtractor, EFFORT_TOKEN_MAP, ValidationError as FluentValidationError, GeminiAdapter, GeminiProvider, GroqAdapter, GroqProvider, HttpProviderClient, HuggingFaceAdapter, HuggingFaceProvider, type ImageContentPart, type ImageUrlConfig, type LegacyProviderConfig, type MessageContent, type ModelInfo, type ModelPricing, ModelScopeAdapter, ModelScopeProvider, NetworkError, NovaAdapter, type OiiaiBuilder, OpenRouterAdapter, type OpenRouterModelInfo, OpenRouterProvider, PoeAdapter, type PresetConfigOptions, type PresetProvider, type ProviderAdapter, type ProviderCapabilities, type ProviderClient, type ProviderClientConfig, type ProviderConfig, ProviderError, ProviderRegistry, type ProviderType$2 as ProviderType, type ReasoningConfig, type ReasoningEffort, type RegistryConfig, RegistryError, RequestBuilder, type StreamBuilder, type StreamCallbacks, type StreamChunk, StreamProcessor, type TextContentPart, TimeoutError, type TokenUsage, type UnifiedProviderConfig, VALID_PROVIDERS, type ValidationError$1 as ValidationError, type ValidationResult, type VideoContentPart, type VideoUrlConfig, ZhipuAdapter, ai, createBuilder, createBuiltInAdapters, createProvider, deepseek, gemini, groq, huggingface, modelscope, nova, oiiai, openrouter, poe, siliconflow, zhipu };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AI Provider 统一类型定义
|
|
3
3
|
*/
|
|
4
|
+
/**
|
|
5
|
+
* 文本内容部分
|
|
6
|
+
*/
|
|
7
|
+
interface TextContentPart {
|
|
8
|
+
type: 'text';
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 图像 URL 配置
|
|
13
|
+
*/
|
|
14
|
+
interface ImageUrlConfig {
|
|
15
|
+
/** 图像 URL 或 base64 编码数据 */
|
|
16
|
+
url: string;
|
|
17
|
+
/** 细节级别 */
|
|
18
|
+
detail?: 'auto' | 'low' | 'high';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 图像内容部分
|
|
22
|
+
*/
|
|
23
|
+
interface ImageContentPart {
|
|
24
|
+
type: 'image_url';
|
|
25
|
+
image_url: ImageUrlConfig;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 视频 URL 配置
|
|
29
|
+
*/
|
|
30
|
+
interface VideoUrlConfig {
|
|
31
|
+
/** 视频 URL 或 base64 编码数据 */
|
|
32
|
+
url: string;
|
|
33
|
+
/** 细节级别 */
|
|
34
|
+
detail?: 'auto' | 'low' | 'high';
|
|
35
|
+
/** 最大提取帧数 */
|
|
36
|
+
max_frames?: number;
|
|
37
|
+
/** 每秒提取帧数 */
|
|
38
|
+
fps?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 视频内容部分
|
|
42
|
+
*/
|
|
43
|
+
interface VideoContentPart {
|
|
44
|
+
type: 'video_url';
|
|
45
|
+
video_url: VideoUrlConfig;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 音频 URL 配置
|
|
49
|
+
*/
|
|
50
|
+
interface AudioUrlConfig {
|
|
51
|
+
/** 音频 URL 或 base64 编码数据 */
|
|
52
|
+
url: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 音频内容部分
|
|
56
|
+
*/
|
|
57
|
+
interface AudioContentPart {
|
|
58
|
+
type: 'audio_url';
|
|
59
|
+
audio_url: AudioUrlConfig;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 多模态内容部分联合类型
|
|
63
|
+
*/
|
|
64
|
+
type ContentPart = TextContentPart | ImageContentPart | VideoContentPart | AudioContentPart;
|
|
65
|
+
/**
|
|
66
|
+
* 消息内容类型 - 支持纯文本或多模态内容数组
|
|
67
|
+
*/
|
|
68
|
+
type MessageContent = string | ContentPart[];
|
|
4
69
|
interface ChatMessage {
|
|
5
70
|
role: 'system' | 'user' | 'assistant';
|
|
6
|
-
content:
|
|
71
|
+
content: MessageContent;
|
|
7
72
|
}
|
|
8
73
|
/**
|
|
9
74
|
* 统一的思考努力程度
|
|
@@ -282,7 +347,7 @@ declare abstract class BaseProvider implements AIProvider {
|
|
|
282
347
|
/**
|
|
283
348
|
* Provider 类型
|
|
284
349
|
*/
|
|
285
|
-
type ProviderType$2 = 'openrouter' | 'gemini' | 'groq' | 'huggingface' | 'modelscope' | 'deepseek' | 'poe' | 'nova' | 'zhipu';
|
|
350
|
+
type ProviderType$2 = 'openrouter' | 'gemini' | 'groq' | 'huggingface' | 'modelscope' | 'deepseek' | 'poe' | 'nova' | 'zhipu' | 'siliconflow';
|
|
286
351
|
/**
|
|
287
352
|
* 统一的 Provider 配置格式
|
|
288
353
|
* 用于配置各种 AI Provider 的连接和行为
|
|
@@ -437,6 +502,7 @@ declare const ai: {
|
|
|
437
502
|
poe: (apiKey: string, baseUrl?: string) => AIProvider;
|
|
438
503
|
nova: (apiKey: string, baseUrl?: string) => AIProvider;
|
|
439
504
|
zhipu: (apiKey: string, baseUrl?: string) => AIProvider;
|
|
505
|
+
siliconflow: (apiKey: string, baseUrl?: string) => AIProvider;
|
|
440
506
|
};
|
|
441
507
|
|
|
442
508
|
/**
|
|
@@ -1148,7 +1214,7 @@ declare class HttpProviderClient implements ProviderClient {
|
|
|
1148
1214
|
* Provider 类型枚举
|
|
1149
1215
|
* 支持的所有 Provider 类型
|
|
1150
1216
|
*/
|
|
1151
|
-
type ProviderType = 'openrouter' | 'gemini' | 'groq' | 'huggingface' | 'modelscope' | 'deepseek' | 'poe' | 'nova' | 'zhipu';
|
|
1217
|
+
type ProviderType = 'openrouter' | 'gemini' | 'groq' | 'huggingface' | 'modelscope' | 'deepseek' | 'poe' | 'nova' | 'zhipu' | 'siliconflow';
|
|
1152
1218
|
/**
|
|
1153
1219
|
* 适配器配置
|
|
1154
1220
|
* 用于创建适配器实例时的配置
|
|
@@ -1799,6 +1865,32 @@ declare function createBuiltInAdapters(): Map<ProviderType, ProviderAdapter>;
|
|
|
1799
1865
|
* 提供链式调用和预设实例的类型支持
|
|
1800
1866
|
*/
|
|
1801
1867
|
|
|
1868
|
+
/**
|
|
1869
|
+
* 图像配置选项
|
|
1870
|
+
*/
|
|
1871
|
+
interface ImageOptions {
|
|
1872
|
+
/** 细节级别 */
|
|
1873
|
+
detail?: 'auto' | 'low' | 'high';
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* 视频配置选项
|
|
1877
|
+
*/
|
|
1878
|
+
interface VideoOptions {
|
|
1879
|
+
/** 细节级别 */
|
|
1880
|
+
detail?: 'auto' | 'low' | 'high';
|
|
1881
|
+
/** 最大提取帧数 */
|
|
1882
|
+
maxFrames?: number;
|
|
1883
|
+
/** 每秒提取帧数 */
|
|
1884
|
+
fps?: number;
|
|
1885
|
+
}
|
|
1886
|
+
/**
|
|
1887
|
+
* 多模态内容项(内部使用)
|
|
1888
|
+
*/
|
|
1889
|
+
interface MultimodalItem {
|
|
1890
|
+
type: 'image' | 'video' | 'audio';
|
|
1891
|
+
url: string;
|
|
1892
|
+
options?: ImageOptions | VideoOptions;
|
|
1893
|
+
}
|
|
1802
1894
|
/**
|
|
1803
1895
|
* 问答选项
|
|
1804
1896
|
* 用于配置单次 AI 调用的参数
|
|
@@ -1892,6 +1984,8 @@ interface BuilderConfig {
|
|
|
1892
1984
|
reasoning?: ReasoningConfig;
|
|
1893
1985
|
/** 是否流式请求 */
|
|
1894
1986
|
isStream?: boolean;
|
|
1987
|
+
/** 多模态内容列表 */
|
|
1988
|
+
multimodal?: MultimodalItem[];
|
|
1895
1989
|
}
|
|
1896
1990
|
/**
|
|
1897
1991
|
* 链式调用构建器接口
|
|
@@ -1899,12 +1993,21 @@ interface BuilderConfig {
|
|
|
1899
1993
|
*
|
|
1900
1994
|
* @example
|
|
1901
1995
|
* ```typescript
|
|
1996
|
+
* // 纯文本请求
|
|
1902
1997
|
* const answer = await oiiai
|
|
1903
1998
|
* .use('deepseek')
|
|
1904
1999
|
* .key('your-api-key')
|
|
1905
2000
|
* .model('deepseek-chat')
|
|
1906
2001
|
* .system('你是助手')
|
|
1907
2002
|
* .ask('你好');
|
|
2003
|
+
*
|
|
2004
|
+
* // 多模态请求
|
|
2005
|
+
* const answer = await oiiai
|
|
2006
|
+
* .use('siliconflow')
|
|
2007
|
+
* .key('your-api-key')
|
|
2008
|
+
* .model('Qwen/Qwen2.5-VL-72B-Instruct')
|
|
2009
|
+
* .image('https://example.com/image.jpg', { detail: 'high' })
|
|
2010
|
+
* .ask('描述这张图片');
|
|
1908
2011
|
* ```
|
|
1909
2012
|
*/
|
|
1910
2013
|
interface OiiaiBuilder {
|
|
@@ -1956,6 +2059,55 @@ interface OiiaiBuilder {
|
|
|
1956
2059
|
* @returns this 支持链式调用
|
|
1957
2060
|
*/
|
|
1958
2061
|
baseUrl(url: string): this;
|
|
2062
|
+
/**
|
|
2063
|
+
* 添加图像内容(多模态)
|
|
2064
|
+
* 支持 URL 或 base64 编码的图像数据
|
|
2065
|
+
* @param url - 图像 URL 或 base64 data URL
|
|
2066
|
+
* @param options - 图像配置选项
|
|
2067
|
+
* @returns this 支持链式调用
|
|
2068
|
+
*
|
|
2069
|
+
* @example
|
|
2070
|
+
* ```typescript
|
|
2071
|
+
* // 使用 URL
|
|
2072
|
+
* builder.image('https://example.com/image.jpg')
|
|
2073
|
+
*
|
|
2074
|
+
* // 使用 base64
|
|
2075
|
+
* builder.image('data:image/jpeg;base64,...', { detail: 'high' })
|
|
2076
|
+
*
|
|
2077
|
+
* // 多张图片
|
|
2078
|
+
* builder.image(url1).image(url2).ask('比较这两张图片')
|
|
2079
|
+
* ```
|
|
2080
|
+
*/
|
|
2081
|
+
image(url: string, options?: ImageOptions): this;
|
|
2082
|
+
/**
|
|
2083
|
+
* 添加视频内容(多模态)
|
|
2084
|
+
* 支持 URL 或 base64 编码的视频数据
|
|
2085
|
+
* @param url - 视频 URL 或 base64 data URL
|
|
2086
|
+
* @param options - 视频配置选项
|
|
2087
|
+
* @returns this 支持链式调用
|
|
2088
|
+
*
|
|
2089
|
+
* @example
|
|
2090
|
+
* ```typescript
|
|
2091
|
+
* builder
|
|
2092
|
+
* .video('https://example.com/video.mp4', { maxFrames: 8, fps: 1 })
|
|
2093
|
+
* .ask('描述这个视频的内容')
|
|
2094
|
+
* ```
|
|
2095
|
+
*/
|
|
2096
|
+
video(url: string, options?: VideoOptions): this;
|
|
2097
|
+
/**
|
|
2098
|
+
* 添加音频内容(多模态)
|
|
2099
|
+
* 支持 URL 或 base64 编码的音频数据
|
|
2100
|
+
* @param url - 音频 URL 或 base64 data URL
|
|
2101
|
+
* @returns this 支持链式调用
|
|
2102
|
+
*
|
|
2103
|
+
* @example
|
|
2104
|
+
* ```typescript
|
|
2105
|
+
* builder
|
|
2106
|
+
* .audio('data:audio/mp3;base64,...')
|
|
2107
|
+
* .ask('这段音频说了什么?')
|
|
2108
|
+
* ```
|
|
2109
|
+
*/
|
|
2110
|
+
audio(url: string): this;
|
|
1959
2111
|
/**
|
|
1960
2112
|
* 标记为流式请求
|
|
1961
2113
|
* 调用后 ask() 将返回 AsyncGenerator
|
|
@@ -2178,5 +2330,11 @@ declare const nova: PresetProvider;
|
|
|
2178
2330
|
* 环境变量: ZHIPU_API_KEY
|
|
2179
2331
|
*/
|
|
2180
2332
|
declare const zhipu: PresetProvider;
|
|
2333
|
+
/**
|
|
2334
|
+
* SiliconFlow 预设实例
|
|
2335
|
+
* 环境变量: SILICONFLOW_API_KEY
|
|
2336
|
+
* 支持多模态模型(视觉/音频/视频)
|
|
2337
|
+
*/
|
|
2338
|
+
declare const siliconflow: PresetProvider;
|
|
2181
2339
|
|
|
2182
|
-
export { type AIProvider, APIError, type AdapterConfig, type AskOptions, BaseAdapter, BaseProvider, type BuilderConfig, CONFIG_DEFAULTS, type ChatMessage, type ChatOptions, type ChatResult, type ChatSession, type ChatSessionOptions, ConfigManager, ConfigValidator, ConfigurationError, DeepSeekAdapter, type DeltaExtractor, EFFORT_TOKEN_MAP, ValidationError as FluentValidationError, GeminiAdapter, GeminiProvider, GroqAdapter, GroqProvider, HttpProviderClient, HuggingFaceAdapter, HuggingFaceProvider, type LegacyProviderConfig, type ModelInfo, type ModelPricing, ModelScopeAdapter, ModelScopeProvider, NetworkError, NovaAdapter, type OiiaiBuilder, OpenRouterAdapter, type OpenRouterModelInfo, OpenRouterProvider, PoeAdapter, type PresetConfigOptions, type PresetProvider, type ProviderAdapter, type ProviderCapabilities, type ProviderClient, type ProviderClientConfig, type ProviderConfig, ProviderError, ProviderRegistry, type ProviderType$2 as ProviderType, type ReasoningConfig, type ReasoningEffort, type RegistryConfig, RegistryError, RequestBuilder, type StreamBuilder, type StreamCallbacks, type StreamChunk, StreamProcessor, TimeoutError, type TokenUsage, type UnifiedProviderConfig, VALID_PROVIDERS, type ValidationError$1 as ValidationError, type ValidationResult, ZhipuAdapter, ai, createBuilder, createBuiltInAdapters, createProvider, deepseek, gemini, groq, huggingface, modelscope, nova, oiiai, openrouter, poe, zhipu };
|
|
2340
|
+
export { type AIProvider, APIError, type AdapterConfig, type AskOptions, type AudioContentPart, type AudioUrlConfig, BaseAdapter, BaseProvider, type BuilderConfig, CONFIG_DEFAULTS, type ChatMessage, type ChatOptions, type ChatResult, type ChatSession, type ChatSessionOptions, ConfigManager, ConfigValidator, ConfigurationError, type ContentPart, DeepSeekAdapter, type DeltaExtractor, EFFORT_TOKEN_MAP, ValidationError as FluentValidationError, GeminiAdapter, GeminiProvider, GroqAdapter, GroqProvider, HttpProviderClient, HuggingFaceAdapter, HuggingFaceProvider, type ImageContentPart, type ImageUrlConfig, type LegacyProviderConfig, type MessageContent, type ModelInfo, type ModelPricing, ModelScopeAdapter, ModelScopeProvider, NetworkError, NovaAdapter, type OiiaiBuilder, OpenRouterAdapter, type OpenRouterModelInfo, OpenRouterProvider, PoeAdapter, type PresetConfigOptions, type PresetProvider, type ProviderAdapter, type ProviderCapabilities, type ProviderClient, type ProviderClientConfig, type ProviderConfig, ProviderError, ProviderRegistry, type ProviderType$2 as ProviderType, type ReasoningConfig, type ReasoningEffort, type RegistryConfig, RegistryError, RequestBuilder, type StreamBuilder, type StreamCallbacks, type StreamChunk, StreamProcessor, type TextContentPart, TimeoutError, type TokenUsage, type UnifiedProviderConfig, VALID_PROVIDERS, type ValidationError$1 as ValidationError, type ValidationResult, type VideoContentPart, type VideoUrlConfig, ZhipuAdapter, ai, createBuilder, createBuiltInAdapters, createProvider, deepseek, gemini, groq, huggingface, modelscope, nova, oiiai, openrouter, poe, siliconflow, zhipu };
|