@kevisual/ai 0.0.17 → 0.0.19
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/ai-provider-browser.d.ts +172 -17
- package/dist/ai-provider-browser.js +13 -1
- package/dist/ai-provider.d.ts +172 -17
- package/dist/ai-provider.js +13 -1
- package/package.json +1 -1
- package/src/provider/chat-adapter/dashscope.ts +3 -0
- package/src/provider/chat-adapter/kevisual.ts +3 -0
- package/src/provider/chat-adapter/siliconflow.ts +1 -2
- package/src/provider/core/chat.ts +20 -5
- package/src/provider/core/type.ts +162 -9
- package/src/provider/media/video/siliconflow.ts +6 -6
- package/src/test/aliyun/test.ts +0 -59
- package/src/test/chunks/01-get.ts +0 -65
- package/src/test/common.ts +0 -18
- package/src/test/encrypt/index.ts +0 -9
- package/src/test/func-call/curl.sh +0 -35
- package/src/test/func-call/demo.ts +0 -116
- package/src/test/model-scope/index.ts +0 -26
- package/src/test/ollama-knowledge.ts +0 -37
- package/src/test/ollama.ts +0 -86
- package/src/test/provider/index.ts +0 -7
- package/src/test/siliconflow/common.ts +0 -15
- package/src/test/siliconflow/get.ts +0 -22
- package/src/test/siliconflow/knowledge/create.ts +0 -18
- package/src/test/siliconflow/knowledge/qwen.md +0 -232
- package/src/test/siliconflow/rerank/fc.ts +0 -28
- package/src/test/siliconflow/rerank/index.ts +0 -34
- package/src/test/siliconflow/videos/index.ts +0 -100
- package/src/utils/json.ts +0 -12
|
@@ -1,25 +1,169 @@
|
|
|
1
|
-
import * as openai_resources_index_mjs from 'openai/resources/index.mjs';
|
|
2
|
-
import OpenAI, { OpenAI as OpenAI$1 } from 'openai';
|
|
3
|
-
import * as openai_resources_embeddings_mjs from 'openai/resources/embeddings.mjs';
|
|
4
1
|
import * as _kevisual_permission from '@kevisual/permission';
|
|
5
2
|
import { Permission } from '@kevisual/permission';
|
|
6
3
|
|
|
7
|
-
type ChatMessage =
|
|
8
|
-
|
|
4
|
+
type ChatMessage = {
|
|
5
|
+
role?: 'user' | 'assistant' | 'system' | 'tool';
|
|
6
|
+
content: string;
|
|
7
|
+
};
|
|
8
|
+
type ChatMessageOptions = {
|
|
9
|
+
messages: ChatMessage[];
|
|
10
|
+
/**
|
|
11
|
+
* 模型名称
|
|
12
|
+
*/
|
|
13
|
+
model?: string;
|
|
14
|
+
/**
|
|
15
|
+
* 温度参数,控制随机性 (0-2)
|
|
16
|
+
* 较高的值如0.8会使输出更随机,较低的值如0.2会使其更集中和确定
|
|
17
|
+
*/
|
|
18
|
+
temperature?: number;
|
|
19
|
+
/**
|
|
20
|
+
* 核采样参数 (0-1)
|
|
21
|
+
* 与temperature类似,但使用不同的采样方法
|
|
22
|
+
*/
|
|
23
|
+
top_p?: number;
|
|
24
|
+
/**
|
|
25
|
+
* 生成的最大令牌数
|
|
26
|
+
*/
|
|
27
|
+
max_tokens?: number;
|
|
28
|
+
/**
|
|
29
|
+
* 停止序列
|
|
30
|
+
* 当遇到这些序列时停止生成
|
|
31
|
+
*/
|
|
32
|
+
stop?: string | string[];
|
|
33
|
+
/**
|
|
34
|
+
* 频率惩罚 (-2.0 到 2.0)
|
|
35
|
+
* 正值会根据新令牌在文本中的现有频率来惩罚它们
|
|
36
|
+
*/
|
|
37
|
+
frequency_penalty?: number;
|
|
38
|
+
/**
|
|
39
|
+
* 存在惩罚 (-2.0 到 2.0)
|
|
40
|
+
* 正值会根据新令牌是否出现在文本中来惩罚它们
|
|
41
|
+
*/
|
|
42
|
+
presence_penalty?: number;
|
|
43
|
+
/**
|
|
44
|
+
* 流式输出
|
|
45
|
+
*/
|
|
46
|
+
stream?: boolean;
|
|
9
47
|
/**
|
|
10
48
|
* 是否能够思考
|
|
11
49
|
* 如果会话是千文,服务器的接口,默认为 true
|
|
12
50
|
*/
|
|
13
51
|
enable_thinking?: boolean;
|
|
52
|
+
response_format?: 'text' | 'json' | 'xml' | 'html';
|
|
53
|
+
/**
|
|
54
|
+
* 工具调用参数
|
|
55
|
+
*/
|
|
56
|
+
tool_calls?: any;
|
|
57
|
+
};
|
|
58
|
+
type Choice = {
|
|
59
|
+
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
|
|
60
|
+
index: number;
|
|
61
|
+
message: {
|
|
62
|
+
role: 'assistant' | 'tool';
|
|
63
|
+
content: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
type ChatMessageComplete = {
|
|
67
|
+
/**
|
|
68
|
+
* 聊天完成的唯一标识符
|
|
69
|
+
*/
|
|
70
|
+
id: string;
|
|
71
|
+
/**
|
|
72
|
+
* 聊天完成选项列表
|
|
73
|
+
* 如果 n 大于 1,可以有多个选项
|
|
74
|
+
*/
|
|
75
|
+
choices: Array<Choice>;
|
|
76
|
+
/**
|
|
77
|
+
* 聊天完成创建时的 Unix 时间戳(秒)
|
|
78
|
+
*/
|
|
79
|
+
created: number;
|
|
80
|
+
/**
|
|
81
|
+
* 用于聊天完成的模型名称
|
|
82
|
+
*/
|
|
83
|
+
model: string;
|
|
84
|
+
/**
|
|
85
|
+
* 对象类型,始终为 `chat.completion`
|
|
86
|
+
*/
|
|
87
|
+
object: 'chat.completion';
|
|
88
|
+
/**
|
|
89
|
+
* 系统指纹
|
|
90
|
+
* 用于标识后端配置
|
|
91
|
+
*/
|
|
92
|
+
system_fingerprint?: string;
|
|
93
|
+
/**
|
|
94
|
+
* 完成请求的使用统计信息
|
|
95
|
+
*/
|
|
96
|
+
usage?: Usage;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* 向量嵌入请求参数
|
|
100
|
+
*/
|
|
101
|
+
type EmbeddingMessage = {
|
|
102
|
+
/**
|
|
103
|
+
* 输入文本或文本数组
|
|
104
|
+
* 要生成嵌入向量的文本内容
|
|
105
|
+
*/
|
|
106
|
+
input: string | string[];
|
|
107
|
+
/**
|
|
108
|
+
* 模型名称
|
|
109
|
+
* 用于生成嵌入向量的模型
|
|
110
|
+
*/
|
|
111
|
+
model: string;
|
|
112
|
+
/**
|
|
113
|
+
* 编码格式
|
|
114
|
+
* 返回的嵌入向量编码格式
|
|
115
|
+
*/
|
|
116
|
+
encoding_format?: 'float' | 'base64';
|
|
117
|
+
/**
|
|
118
|
+
* 维度
|
|
119
|
+
* 输出嵌入向量的维度(某些模型支持)
|
|
120
|
+
*/
|
|
121
|
+
dimensions?: number;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* 单个嵌入向量对象
|
|
125
|
+
*/
|
|
126
|
+
type EmbeddingObject = {
|
|
127
|
+
/**
|
|
128
|
+
* 对象类型,始终为 `embedding`
|
|
129
|
+
*/
|
|
130
|
+
object: 'embedding';
|
|
131
|
+
/**
|
|
132
|
+
* 嵌入向量
|
|
133
|
+
* 浮点数数组,表示文本的向量表示
|
|
134
|
+
*/
|
|
135
|
+
embedding: number[];
|
|
136
|
+
/**
|
|
137
|
+
* 索引位置
|
|
138
|
+
* 该嵌入在输入数组中的位置
|
|
139
|
+
*/
|
|
140
|
+
index: number;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* 向量嵌入响应结果
|
|
144
|
+
*/
|
|
145
|
+
type EmbeddingMessageComplete = {
|
|
146
|
+
/**
|
|
147
|
+
* 对象类型,始终为 `list`
|
|
148
|
+
*/
|
|
149
|
+
object: 'list';
|
|
150
|
+
/**
|
|
151
|
+
* 嵌入向量数据列表
|
|
152
|
+
*/
|
|
153
|
+
data: EmbeddingObject[];
|
|
154
|
+
/**
|
|
155
|
+
* 使用的模型名称
|
|
156
|
+
*/
|
|
157
|
+
model: string;
|
|
158
|
+
/**
|
|
159
|
+
* 使用统计信息
|
|
160
|
+
*/
|
|
161
|
+
usage: Usage;
|
|
14
162
|
};
|
|
15
|
-
type ChatMessageComplete = OpenAI.Chat.Completions.ChatCompletion;
|
|
16
|
-
type ChatMessageStream = OpenAI.Chat.Completions.ChatCompletion;
|
|
17
|
-
type EmbeddingMessage = Partial<OpenAI.Embeddings.EmbeddingCreateParams>;
|
|
18
|
-
type EmbeddingMessageComplete = OpenAI.Embeddings.CreateEmbeddingResponse;
|
|
19
163
|
interface BaseChatInterface {
|
|
20
164
|
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
21
165
|
}
|
|
22
|
-
interface
|
|
166
|
+
interface Usage {
|
|
23
167
|
/**
|
|
24
168
|
* 提示词令牌
|
|
25
169
|
*/
|
|
@@ -118,7 +262,11 @@ type BaseChatOptions<T = Record<string, any>> = {
|
|
|
118
262
|
/**
|
|
119
263
|
* 默认apiKey
|
|
120
264
|
*/
|
|
121
|
-
apiKey
|
|
265
|
+
apiKey?: string;
|
|
266
|
+
/**
|
|
267
|
+
* token
|
|
268
|
+
*/
|
|
269
|
+
token?: string;
|
|
122
270
|
/**
|
|
123
271
|
* 是否在浏览器中使用
|
|
124
272
|
*/
|
|
@@ -128,7 +276,7 @@ type BaseChatOptions<T = Record<string, any>> = {
|
|
|
128
276
|
*/
|
|
129
277
|
stream?: boolean;
|
|
130
278
|
} & T;
|
|
131
|
-
declare class BaseChat implements BaseChatInterface,
|
|
279
|
+
declare class BaseChat implements BaseChatInterface, Usage {
|
|
132
280
|
/**
|
|
133
281
|
* 默认baseURL
|
|
134
282
|
*/
|
|
@@ -159,6 +307,13 @@ declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
|
159
307
|
*/
|
|
160
308
|
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
161
309
|
chatStream(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatStream>;
|
|
310
|
+
/**
|
|
311
|
+
* 简单提问接口
|
|
312
|
+
* @param message
|
|
313
|
+
* @param options
|
|
314
|
+
* @returns
|
|
315
|
+
*/
|
|
316
|
+
question(message: string, options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
162
317
|
/**
|
|
163
318
|
* 获取聊天使用情况
|
|
164
319
|
* @returns
|
|
@@ -207,7 +362,7 @@ type OllamaModel = {
|
|
|
207
362
|
declare class Ollama extends BaseChat {
|
|
208
363
|
static BASE_URL: string;
|
|
209
364
|
constructor(options: OllamaOptions$1);
|
|
210
|
-
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<
|
|
365
|
+
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
211
366
|
/**
|
|
212
367
|
* 获取模型列表
|
|
213
368
|
* @returns
|
|
@@ -245,7 +400,7 @@ declare class SiliconFlow extends BaseChat {
|
|
|
245
400
|
static BASE_URL: string;
|
|
246
401
|
constructor(options: SiliconFlowOptions);
|
|
247
402
|
getUsageInfo(): Promise<SiliconFlowUsageResponse>;
|
|
248
|
-
chat(messages:
|
|
403
|
+
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
249
404
|
}
|
|
250
405
|
|
|
251
406
|
type OllamaOptions = BaseChatOptions;
|
|
@@ -344,7 +499,7 @@ declare class ProviderManager {
|
|
|
344
499
|
provider: BaseChat;
|
|
345
500
|
constructor(config: ProviderManagerConfig);
|
|
346
501
|
static createProvider(config: ProviderManagerConfig): Promise<BaseChat>;
|
|
347
|
-
chat(messages: ChatMessage[]): Promise<
|
|
502
|
+
chat(messages: ChatMessage[]): Promise<ChatMessageComplete>;
|
|
348
503
|
}
|
|
349
504
|
|
|
350
505
|
type KnowledgeOptions<T = Record<string, any>> = BaseChatOptions<{
|
|
@@ -372,7 +527,7 @@ declare class KnowledgeBase extends BaseChat {
|
|
|
372
527
|
*/
|
|
373
528
|
generateEmbedding(text: string | string[]): Promise<{
|
|
374
529
|
code: number;
|
|
375
|
-
data:
|
|
530
|
+
data: EmbeddingObject[];
|
|
376
531
|
message?: undefined;
|
|
377
532
|
} | {
|
|
378
533
|
code: any;
|
|
@@ -548,4 +703,4 @@ declare class AIConfigParser {
|
|
|
548
703
|
}
|
|
549
704
|
|
|
550
705
|
export { AIConfigParser, AIUtils, BailianChat, BailianProvider, BaseChat, ChatProviderMap, Custom, CustomProvider, DeepSeek, DeepSeekProvider, Kevisual, KevisualProvider, Kimi, KimiProvider, KnowledgeBase, ModelScope, ModelScopeProvider, Ollama, OllamaProvider, ProviderManager, SiliconFlow, SiliconFlowKnowledge, SiliconFlowProvider, Volces, VolcesProvider, Zhipu, ZhipuProvider, decryptAES, encryptAES, readStream };
|
|
551
|
-
export type { AIConfig, AIModel, BaseChatInterface, BaseChatOptions,
|
|
706
|
+
export type { AIConfig, AIModel, BaseChatInterface, BaseChatOptions, ChatMessage, ChatMessageComplete, ChatMessageOptions, ChatStream, EmbeddingMessage, EmbeddingMessageComplete, EmbeddingObject, GetProviderOpts, KnowledgeOptions, ProviderResult, RerankOptions, SecretKey, Usage };
|
|
@@ -18798,7 +18798,7 @@ class BaseChat {
|
|
|
18798
18798
|
constructor(options) {
|
|
18799
18799
|
this.baseURL = options.baseURL;
|
|
18800
18800
|
this.model = options.model;
|
|
18801
|
-
this.apiKey = options.apiKey;
|
|
18801
|
+
this.apiKey = options.token || options.apiKey;
|
|
18802
18802
|
}
|
|
18803
18803
|
post(url = "", opts = {}) {
|
|
18804
18804
|
let _url = url.startsWith("http") ? url : this.baseURL + url;
|
|
@@ -18892,6 +18892,12 @@ class BaseChat {
|
|
|
18892
18892
|
});
|
|
18893
18893
|
return stream;
|
|
18894
18894
|
}
|
|
18895
|
+
question(message, options) {
|
|
18896
|
+
const messages = [
|
|
18897
|
+
{ role: "user", content: message }
|
|
18898
|
+
];
|
|
18899
|
+
return this.chat(messages, options);
|
|
18900
|
+
}
|
|
18895
18901
|
getChatUsage() {
|
|
18896
18902
|
return {
|
|
18897
18903
|
prompt_tokens: this.prompt_tokens,
|
|
@@ -19013,6 +19019,9 @@ class BailianChat extends BaseChat {
|
|
|
19013
19019
|
static BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1";
|
|
19014
19020
|
constructor(options) {
|
|
19015
19021
|
const baseURL = options.baseURL || BailianChat.BASE_URL;
|
|
19022
|
+
if (!options.model) {
|
|
19023
|
+
options.model = "qwen-plus";
|
|
19024
|
+
}
|
|
19016
19025
|
super({ ...options, baseURL });
|
|
19017
19026
|
}
|
|
19018
19027
|
}
|
|
@@ -19040,6 +19049,9 @@ class Kevisual extends BaseChat {
|
|
|
19040
19049
|
static BASE_URL = "https://newapi.kevisual.cn/v1/";
|
|
19041
19050
|
constructor(options) {
|
|
19042
19051
|
const baseURL = options.baseURL || Kevisual.BASE_URL;
|
|
19052
|
+
if (!options.model) {
|
|
19053
|
+
options.model = "qwen-plus";
|
|
19054
|
+
}
|
|
19043
19055
|
super({ ...options, baseURL });
|
|
19044
19056
|
}
|
|
19045
19057
|
}
|
package/dist/ai-provider.d.ts
CHANGED
|
@@ -1,25 +1,169 @@
|
|
|
1
|
-
import * as openai_resources_index_mjs from 'openai/resources/index.mjs';
|
|
2
|
-
import OpenAI, { OpenAI as OpenAI$1 } from 'openai';
|
|
3
|
-
import * as openai_resources_embeddings_mjs from 'openai/resources/embeddings.mjs';
|
|
4
1
|
import * as _kevisual_permission from '@kevisual/permission';
|
|
5
2
|
import { Permission } from '@kevisual/permission';
|
|
6
3
|
|
|
7
|
-
type ChatMessage =
|
|
8
|
-
|
|
4
|
+
type ChatMessage = {
|
|
5
|
+
role?: 'user' | 'assistant' | 'system' | 'tool';
|
|
6
|
+
content: string;
|
|
7
|
+
};
|
|
8
|
+
type ChatMessageOptions = {
|
|
9
|
+
messages: ChatMessage[];
|
|
10
|
+
/**
|
|
11
|
+
* 模型名称
|
|
12
|
+
*/
|
|
13
|
+
model?: string;
|
|
14
|
+
/**
|
|
15
|
+
* 温度参数,控制随机性 (0-2)
|
|
16
|
+
* 较高的值如0.8会使输出更随机,较低的值如0.2会使其更集中和确定
|
|
17
|
+
*/
|
|
18
|
+
temperature?: number;
|
|
19
|
+
/**
|
|
20
|
+
* 核采样参数 (0-1)
|
|
21
|
+
* 与temperature类似,但使用不同的采样方法
|
|
22
|
+
*/
|
|
23
|
+
top_p?: number;
|
|
24
|
+
/**
|
|
25
|
+
* 生成的最大令牌数
|
|
26
|
+
*/
|
|
27
|
+
max_tokens?: number;
|
|
28
|
+
/**
|
|
29
|
+
* 停止序列
|
|
30
|
+
* 当遇到这些序列时停止生成
|
|
31
|
+
*/
|
|
32
|
+
stop?: string | string[];
|
|
33
|
+
/**
|
|
34
|
+
* 频率惩罚 (-2.0 到 2.0)
|
|
35
|
+
* 正值会根据新令牌在文本中的现有频率来惩罚它们
|
|
36
|
+
*/
|
|
37
|
+
frequency_penalty?: number;
|
|
38
|
+
/**
|
|
39
|
+
* 存在惩罚 (-2.0 到 2.0)
|
|
40
|
+
* 正值会根据新令牌是否出现在文本中来惩罚它们
|
|
41
|
+
*/
|
|
42
|
+
presence_penalty?: number;
|
|
43
|
+
/**
|
|
44
|
+
* 流式输出
|
|
45
|
+
*/
|
|
46
|
+
stream?: boolean;
|
|
9
47
|
/**
|
|
10
48
|
* 是否能够思考
|
|
11
49
|
* 如果会话是千文,服务器的接口,默认为 true
|
|
12
50
|
*/
|
|
13
51
|
enable_thinking?: boolean;
|
|
52
|
+
response_format?: 'text' | 'json' | 'xml' | 'html';
|
|
53
|
+
/**
|
|
54
|
+
* 工具调用参数
|
|
55
|
+
*/
|
|
56
|
+
tool_calls?: any;
|
|
57
|
+
};
|
|
58
|
+
type Choice = {
|
|
59
|
+
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
|
|
60
|
+
index: number;
|
|
61
|
+
message: {
|
|
62
|
+
role: 'assistant' | 'tool';
|
|
63
|
+
content: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
type ChatMessageComplete = {
|
|
67
|
+
/**
|
|
68
|
+
* 聊天完成的唯一标识符
|
|
69
|
+
*/
|
|
70
|
+
id: string;
|
|
71
|
+
/**
|
|
72
|
+
* 聊天完成选项列表
|
|
73
|
+
* 如果 n 大于 1,可以有多个选项
|
|
74
|
+
*/
|
|
75
|
+
choices: Array<Choice>;
|
|
76
|
+
/**
|
|
77
|
+
* 聊天完成创建时的 Unix 时间戳(秒)
|
|
78
|
+
*/
|
|
79
|
+
created: number;
|
|
80
|
+
/**
|
|
81
|
+
* 用于聊天完成的模型名称
|
|
82
|
+
*/
|
|
83
|
+
model: string;
|
|
84
|
+
/**
|
|
85
|
+
* 对象类型,始终为 `chat.completion`
|
|
86
|
+
*/
|
|
87
|
+
object: 'chat.completion';
|
|
88
|
+
/**
|
|
89
|
+
* 系统指纹
|
|
90
|
+
* 用于标识后端配置
|
|
91
|
+
*/
|
|
92
|
+
system_fingerprint?: string;
|
|
93
|
+
/**
|
|
94
|
+
* 完成请求的使用统计信息
|
|
95
|
+
*/
|
|
96
|
+
usage?: Usage;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* 向量嵌入请求参数
|
|
100
|
+
*/
|
|
101
|
+
type EmbeddingMessage = {
|
|
102
|
+
/**
|
|
103
|
+
* 输入文本或文本数组
|
|
104
|
+
* 要生成嵌入向量的文本内容
|
|
105
|
+
*/
|
|
106
|
+
input: string | string[];
|
|
107
|
+
/**
|
|
108
|
+
* 模型名称
|
|
109
|
+
* 用于生成嵌入向量的模型
|
|
110
|
+
*/
|
|
111
|
+
model: string;
|
|
112
|
+
/**
|
|
113
|
+
* 编码格式
|
|
114
|
+
* 返回的嵌入向量编码格式
|
|
115
|
+
*/
|
|
116
|
+
encoding_format?: 'float' | 'base64';
|
|
117
|
+
/**
|
|
118
|
+
* 维度
|
|
119
|
+
* 输出嵌入向量的维度(某些模型支持)
|
|
120
|
+
*/
|
|
121
|
+
dimensions?: number;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* 单个嵌入向量对象
|
|
125
|
+
*/
|
|
126
|
+
type EmbeddingObject = {
|
|
127
|
+
/**
|
|
128
|
+
* 对象类型,始终为 `embedding`
|
|
129
|
+
*/
|
|
130
|
+
object: 'embedding';
|
|
131
|
+
/**
|
|
132
|
+
* 嵌入向量
|
|
133
|
+
* 浮点数数组,表示文本的向量表示
|
|
134
|
+
*/
|
|
135
|
+
embedding: number[];
|
|
136
|
+
/**
|
|
137
|
+
* 索引位置
|
|
138
|
+
* 该嵌入在输入数组中的位置
|
|
139
|
+
*/
|
|
140
|
+
index: number;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* 向量嵌入响应结果
|
|
144
|
+
*/
|
|
145
|
+
type EmbeddingMessageComplete = {
|
|
146
|
+
/**
|
|
147
|
+
* 对象类型,始终为 `list`
|
|
148
|
+
*/
|
|
149
|
+
object: 'list';
|
|
150
|
+
/**
|
|
151
|
+
* 嵌入向量数据列表
|
|
152
|
+
*/
|
|
153
|
+
data: EmbeddingObject[];
|
|
154
|
+
/**
|
|
155
|
+
* 使用的模型名称
|
|
156
|
+
*/
|
|
157
|
+
model: string;
|
|
158
|
+
/**
|
|
159
|
+
* 使用统计信息
|
|
160
|
+
*/
|
|
161
|
+
usage: Usage;
|
|
14
162
|
};
|
|
15
|
-
type ChatMessageComplete = OpenAI.Chat.Completions.ChatCompletion;
|
|
16
|
-
type ChatMessageStream = OpenAI.Chat.Completions.ChatCompletion;
|
|
17
|
-
type EmbeddingMessage = Partial<OpenAI.Embeddings.EmbeddingCreateParams>;
|
|
18
|
-
type EmbeddingMessageComplete = OpenAI.Embeddings.CreateEmbeddingResponse;
|
|
19
163
|
interface BaseChatInterface {
|
|
20
164
|
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
21
165
|
}
|
|
22
|
-
interface
|
|
166
|
+
interface Usage {
|
|
23
167
|
/**
|
|
24
168
|
* 提示词令牌
|
|
25
169
|
*/
|
|
@@ -118,7 +262,11 @@ type BaseChatOptions<T = Record<string, any>> = {
|
|
|
118
262
|
/**
|
|
119
263
|
* 默认apiKey
|
|
120
264
|
*/
|
|
121
|
-
apiKey
|
|
265
|
+
apiKey?: string;
|
|
266
|
+
/**
|
|
267
|
+
* token
|
|
268
|
+
*/
|
|
269
|
+
token?: string;
|
|
122
270
|
/**
|
|
123
271
|
* 是否在浏览器中使用
|
|
124
272
|
*/
|
|
@@ -128,7 +276,7 @@ type BaseChatOptions<T = Record<string, any>> = {
|
|
|
128
276
|
*/
|
|
129
277
|
stream?: boolean;
|
|
130
278
|
} & T;
|
|
131
|
-
declare class BaseChat implements BaseChatInterface,
|
|
279
|
+
declare class BaseChat implements BaseChatInterface, Usage {
|
|
132
280
|
/**
|
|
133
281
|
* 默认baseURL
|
|
134
282
|
*/
|
|
@@ -159,6 +307,13 @@ declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
|
159
307
|
*/
|
|
160
308
|
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
161
309
|
chatStream(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatStream>;
|
|
310
|
+
/**
|
|
311
|
+
* 简单提问接口
|
|
312
|
+
* @param message
|
|
313
|
+
* @param options
|
|
314
|
+
* @returns
|
|
315
|
+
*/
|
|
316
|
+
question(message: string, options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
162
317
|
/**
|
|
163
318
|
* 获取聊天使用情况
|
|
164
319
|
* @returns
|
|
@@ -207,7 +362,7 @@ type OllamaModel = {
|
|
|
207
362
|
declare class Ollama extends BaseChat {
|
|
208
363
|
static BASE_URL: string;
|
|
209
364
|
constructor(options: OllamaOptions$1);
|
|
210
|
-
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<
|
|
365
|
+
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
211
366
|
/**
|
|
212
367
|
* 获取模型列表
|
|
213
368
|
* @returns
|
|
@@ -245,7 +400,7 @@ declare class SiliconFlow extends BaseChat {
|
|
|
245
400
|
static BASE_URL: string;
|
|
246
401
|
constructor(options: SiliconFlowOptions);
|
|
247
402
|
getUsageInfo(): Promise<SiliconFlowUsageResponse>;
|
|
248
|
-
chat(messages:
|
|
403
|
+
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
249
404
|
}
|
|
250
405
|
|
|
251
406
|
type OllamaOptions = BaseChatOptions;
|
|
@@ -344,7 +499,7 @@ declare class ProviderManager {
|
|
|
344
499
|
provider: BaseChat;
|
|
345
500
|
constructor(config: ProviderManagerConfig);
|
|
346
501
|
static createProvider(config: ProviderManagerConfig): Promise<BaseChat>;
|
|
347
|
-
chat(messages: ChatMessage[]): Promise<
|
|
502
|
+
chat(messages: ChatMessage[]): Promise<ChatMessageComplete>;
|
|
348
503
|
}
|
|
349
504
|
|
|
350
505
|
type KnowledgeOptions<T = Record<string, any>> = BaseChatOptions<{
|
|
@@ -372,7 +527,7 @@ declare class KnowledgeBase extends BaseChat {
|
|
|
372
527
|
*/
|
|
373
528
|
generateEmbedding(text: string | string[]): Promise<{
|
|
374
529
|
code: number;
|
|
375
|
-
data:
|
|
530
|
+
data: EmbeddingObject[];
|
|
376
531
|
message?: undefined;
|
|
377
532
|
} | {
|
|
378
533
|
code: any;
|
|
@@ -548,4 +703,4 @@ declare class AIConfigParser {
|
|
|
548
703
|
}
|
|
549
704
|
|
|
550
705
|
export { AIConfigParser, AIUtils, BailianChat, BailianProvider, BaseChat, ChatProviderMap, Custom, CustomProvider, DeepSeek, DeepSeekProvider, Kevisual, KevisualProvider, Kimi, KimiProvider, KnowledgeBase, ModelScope, ModelScopeProvider, Ollama, OllamaProvider, ProviderManager, SiliconFlow, SiliconFlowKnowledge, SiliconFlowProvider, Volces, VolcesProvider, Zhipu, ZhipuProvider, decryptAES, encryptAES, readStream };
|
|
551
|
-
export type { AIConfig, AIModel, BaseChatInterface, BaseChatOptions,
|
|
706
|
+
export type { AIConfig, AIModel, BaseChatInterface, BaseChatOptions, ChatMessage, ChatMessageComplete, ChatMessageOptions, ChatStream, EmbeddingMessage, EmbeddingMessageComplete, EmbeddingObject, GetProviderOpts, KnowledgeOptions, ProviderResult, RerankOptions, SecretKey, Usage };
|
package/dist/ai-provider.js
CHANGED
|
@@ -1358,7 +1358,7 @@ class BaseChat {
|
|
|
1358
1358
|
constructor(options) {
|
|
1359
1359
|
this.baseURL = options.baseURL;
|
|
1360
1360
|
this.model = options.model;
|
|
1361
|
-
this.apiKey = options.apiKey;
|
|
1361
|
+
this.apiKey = options.token || options.apiKey;
|
|
1362
1362
|
}
|
|
1363
1363
|
post(url = "", opts = {}) {
|
|
1364
1364
|
let _url = url.startsWith("http") ? url : this.baseURL + url;
|
|
@@ -1452,6 +1452,12 @@ class BaseChat {
|
|
|
1452
1452
|
});
|
|
1453
1453
|
return stream;
|
|
1454
1454
|
}
|
|
1455
|
+
question(message, options) {
|
|
1456
|
+
const messages = [
|
|
1457
|
+
{ role: "user", content: message }
|
|
1458
|
+
];
|
|
1459
|
+
return this.chat(messages, options);
|
|
1460
|
+
}
|
|
1455
1461
|
getChatUsage() {
|
|
1456
1462
|
return {
|
|
1457
1463
|
prompt_tokens: this.prompt_tokens,
|
|
@@ -1573,6 +1579,9 @@ class BailianChat extends BaseChat {
|
|
|
1573
1579
|
static BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1";
|
|
1574
1580
|
constructor(options) {
|
|
1575
1581
|
const baseURL = options.baseURL || BailianChat.BASE_URL;
|
|
1582
|
+
if (!options.model) {
|
|
1583
|
+
options.model = "qwen-plus";
|
|
1584
|
+
}
|
|
1576
1585
|
super({ ...options, baseURL });
|
|
1577
1586
|
}
|
|
1578
1587
|
}
|
|
@@ -1600,6 +1609,9 @@ class Kevisual extends BaseChat {
|
|
|
1600
1609
|
static BASE_URL = "https://newapi.kevisual.cn/v1/";
|
|
1601
1610
|
constructor(options) {
|
|
1602
1611
|
const baseURL = options.baseURL || Kevisual.BASE_URL;
|
|
1612
|
+
if (!options.model) {
|
|
1613
|
+
options.model = "qwen-plus";
|
|
1614
|
+
}
|
|
1603
1615
|
super({ ...options, baseURL });
|
|
1604
1616
|
}
|
|
1605
1617
|
}
|
package/package.json
CHANGED
|
@@ -5,6 +5,9 @@ export class BailianChat extends BaseChat {
|
|
|
5
5
|
static BASE_URL = 'https://dashscope.aliyuncs.com/compatible-mode/v1';
|
|
6
6
|
constructor(options: BailianOptions) {
|
|
7
7
|
const baseURL = options.baseURL || BailianChat.BASE_URL;
|
|
8
|
+
if (!options.model) {
|
|
9
|
+
options.model = 'qwen-plus'
|
|
10
|
+
}
|
|
8
11
|
super({ ...(options as BaseChatOptions), baseURL: baseURL });
|
|
9
12
|
}
|
|
10
13
|
}
|
|
@@ -9,6 +9,9 @@ export class Kevisual extends BaseChat {
|
|
|
9
9
|
static BASE_URL = 'https://newapi.kevisual.cn/v1/';
|
|
10
10
|
constructor(options: KevisualOptions) {
|
|
11
11
|
const baseURL = options.baseURL || Kevisual.BASE_URL;
|
|
12
|
+
if (!options.model) {
|
|
13
|
+
options.model = 'qwen-plus'
|
|
14
|
+
}
|
|
12
15
|
super({ ...(options as BaseChatOptions), baseURL: baseURL });
|
|
13
16
|
}
|
|
14
17
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseChat, BaseChatOptions } from '../core/chat.ts';
|
|
2
|
-
import { OpenAI } from 'openai';
|
|
3
2
|
import type { ChatMessage, ChatMessageOptions } from '../core/index.ts';
|
|
4
3
|
|
|
5
4
|
export type SiliconFlowOptions = Partial<BaseChatOptions>;
|
|
@@ -33,7 +32,7 @@ export class SiliconFlow extends BaseChat {
|
|
|
33
32
|
async getUsageInfo(): Promise<SiliconFlowUsageResponse> {
|
|
34
33
|
return this.get('/user/info');
|
|
35
34
|
}
|
|
36
|
-
async chat(messages:
|
|
35
|
+
async chat(messages: ChatMessage[], options?: ChatMessageOptions) {
|
|
37
36
|
const res = await super.chat(messages, options);
|
|
38
37
|
return res;
|
|
39
38
|
}
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
ChatMessageComplete,
|
|
4
4
|
ChatMessage,
|
|
5
5
|
ChatMessageOptions,
|
|
6
|
-
|
|
6
|
+
Usage,
|
|
7
7
|
ChatStream,
|
|
8
8
|
EmbeddingMessage,
|
|
9
9
|
EmbeddingMessageComplete,
|
|
@@ -22,7 +22,11 @@ export type BaseChatOptions<T = Record<string, any>> = {
|
|
|
22
22
|
/**
|
|
23
23
|
* 默认apiKey
|
|
24
24
|
*/
|
|
25
|
-
apiKey
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
/**
|
|
27
|
+
* token
|
|
28
|
+
*/
|
|
29
|
+
token?: string;
|
|
26
30
|
/**
|
|
27
31
|
* 是否在浏览器中使用
|
|
28
32
|
*/
|
|
@@ -33,7 +37,7 @@ export type BaseChatOptions<T = Record<string, any>> = {
|
|
|
33
37
|
stream?: boolean;
|
|
34
38
|
} & T;
|
|
35
39
|
|
|
36
|
-
export class BaseChat implements BaseChatInterface,
|
|
40
|
+
export class BaseChat implements BaseChatInterface, Usage {
|
|
37
41
|
/**
|
|
38
42
|
* 默认baseURL
|
|
39
43
|
*/
|
|
@@ -54,7 +58,7 @@ export class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
|
54
58
|
constructor(options: BaseChatOptions) {
|
|
55
59
|
this.baseURL = options.baseURL;
|
|
56
60
|
this.model = options.model;
|
|
57
|
-
this.apiKey = options.apiKey;
|
|
61
|
+
this.apiKey = options.token || options.apiKey;
|
|
58
62
|
}
|
|
59
63
|
post(url = '', opts: { headers?: Record<string, string>, data?: any } = {}) {
|
|
60
64
|
let _url = url.startsWith('http') ? url : this.baseURL + url;
|
|
@@ -164,7 +168,18 @@ export class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
|
164
168
|
|
|
165
169
|
return stream as unknown as ChatStream;
|
|
166
170
|
}
|
|
167
|
-
|
|
171
|
+
/**
|
|
172
|
+
* 简单提问接口
|
|
173
|
+
* @param message
|
|
174
|
+
* @param options
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
177
|
+
question(message: string, options?: ChatMessageOptions) {
|
|
178
|
+
const messages: ChatMessage[] = [
|
|
179
|
+
{ role: 'user', content: message }
|
|
180
|
+
];
|
|
181
|
+
return this.chat(messages, options);
|
|
182
|
+
}
|
|
168
183
|
/**
|
|
169
184
|
* 获取聊天使用情况
|
|
170
185
|
* @returns
|