@kevisual/ai 0.0.18 → 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 +167 -16
- package/dist/ai-provider-browser.js +6 -0
- package/dist/ai-provider.d.ts +167 -16
- package/dist/ai-provider.js +6 -0
- package/package.json +1 -1
- package/src/provider/chat-adapter/siliconflow.ts +1 -2
- package/src/provider/core/chat.ts +14 -3
- 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
|
*/
|
|
@@ -132,7 +276,7 @@ type BaseChatOptions<T = Record<string, any>> = {
|
|
|
132
276
|
*/
|
|
133
277
|
stream?: boolean;
|
|
134
278
|
} & T;
|
|
135
|
-
declare class BaseChat implements BaseChatInterface,
|
|
279
|
+
declare class BaseChat implements BaseChatInterface, Usage {
|
|
136
280
|
/**
|
|
137
281
|
* 默认baseURL
|
|
138
282
|
*/
|
|
@@ -163,6 +307,13 @@ declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
|
163
307
|
*/
|
|
164
308
|
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
165
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>;
|
|
166
317
|
/**
|
|
167
318
|
* 获取聊天使用情况
|
|
168
319
|
* @returns
|
|
@@ -211,7 +362,7 @@ type OllamaModel = {
|
|
|
211
362
|
declare class Ollama extends BaseChat {
|
|
212
363
|
static BASE_URL: string;
|
|
213
364
|
constructor(options: OllamaOptions$1);
|
|
214
|
-
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<
|
|
365
|
+
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
215
366
|
/**
|
|
216
367
|
* 获取模型列表
|
|
217
368
|
* @returns
|
|
@@ -249,7 +400,7 @@ declare class SiliconFlow extends BaseChat {
|
|
|
249
400
|
static BASE_URL: string;
|
|
250
401
|
constructor(options: SiliconFlowOptions);
|
|
251
402
|
getUsageInfo(): Promise<SiliconFlowUsageResponse>;
|
|
252
|
-
chat(messages:
|
|
403
|
+
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
253
404
|
}
|
|
254
405
|
|
|
255
406
|
type OllamaOptions = BaseChatOptions;
|
|
@@ -348,7 +499,7 @@ declare class ProviderManager {
|
|
|
348
499
|
provider: BaseChat;
|
|
349
500
|
constructor(config: ProviderManagerConfig);
|
|
350
501
|
static createProvider(config: ProviderManagerConfig): Promise<BaseChat>;
|
|
351
|
-
chat(messages: ChatMessage[]): Promise<
|
|
502
|
+
chat(messages: ChatMessage[]): Promise<ChatMessageComplete>;
|
|
352
503
|
}
|
|
353
504
|
|
|
354
505
|
type KnowledgeOptions<T = Record<string, any>> = BaseChatOptions<{
|
|
@@ -376,7 +527,7 @@ declare class KnowledgeBase extends BaseChat {
|
|
|
376
527
|
*/
|
|
377
528
|
generateEmbedding(text: string | string[]): Promise<{
|
|
378
529
|
code: number;
|
|
379
|
-
data:
|
|
530
|
+
data: EmbeddingObject[];
|
|
380
531
|
message?: undefined;
|
|
381
532
|
} | {
|
|
382
533
|
code: any;
|
|
@@ -552,4 +703,4 @@ declare class AIConfigParser {
|
|
|
552
703
|
}
|
|
553
704
|
|
|
554
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 };
|
|
555
|
-
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 };
|
|
@@ -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,
|
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
|
*/
|
|
@@ -132,7 +276,7 @@ type BaseChatOptions<T = Record<string, any>> = {
|
|
|
132
276
|
*/
|
|
133
277
|
stream?: boolean;
|
|
134
278
|
} & T;
|
|
135
|
-
declare class BaseChat implements BaseChatInterface,
|
|
279
|
+
declare class BaseChat implements BaseChatInterface, Usage {
|
|
136
280
|
/**
|
|
137
281
|
* 默认baseURL
|
|
138
282
|
*/
|
|
@@ -163,6 +307,13 @@ declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
|
163
307
|
*/
|
|
164
308
|
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
165
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>;
|
|
166
317
|
/**
|
|
167
318
|
* 获取聊天使用情况
|
|
168
319
|
* @returns
|
|
@@ -211,7 +362,7 @@ type OllamaModel = {
|
|
|
211
362
|
declare class Ollama extends BaseChat {
|
|
212
363
|
static BASE_URL: string;
|
|
213
364
|
constructor(options: OllamaOptions$1);
|
|
214
|
-
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<
|
|
365
|
+
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
215
366
|
/**
|
|
216
367
|
* 获取模型列表
|
|
217
368
|
* @returns
|
|
@@ -249,7 +400,7 @@ declare class SiliconFlow extends BaseChat {
|
|
|
249
400
|
static BASE_URL: string;
|
|
250
401
|
constructor(options: SiliconFlowOptions);
|
|
251
402
|
getUsageInfo(): Promise<SiliconFlowUsageResponse>;
|
|
252
|
-
chat(messages:
|
|
403
|
+
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
253
404
|
}
|
|
254
405
|
|
|
255
406
|
type OllamaOptions = BaseChatOptions;
|
|
@@ -348,7 +499,7 @@ declare class ProviderManager {
|
|
|
348
499
|
provider: BaseChat;
|
|
349
500
|
constructor(config: ProviderManagerConfig);
|
|
350
501
|
static createProvider(config: ProviderManagerConfig): Promise<BaseChat>;
|
|
351
|
-
chat(messages: ChatMessage[]): Promise<
|
|
502
|
+
chat(messages: ChatMessage[]): Promise<ChatMessageComplete>;
|
|
352
503
|
}
|
|
353
504
|
|
|
354
505
|
type KnowledgeOptions<T = Record<string, any>> = BaseChatOptions<{
|
|
@@ -376,7 +527,7 @@ declare class KnowledgeBase extends BaseChat {
|
|
|
376
527
|
*/
|
|
377
528
|
generateEmbedding(text: string | string[]): Promise<{
|
|
378
529
|
code: number;
|
|
379
|
-
data:
|
|
530
|
+
data: EmbeddingObject[];
|
|
380
531
|
message?: undefined;
|
|
381
532
|
} | {
|
|
382
533
|
code: any;
|
|
@@ -552,4 +703,4 @@ declare class AIConfigParser {
|
|
|
552
703
|
}
|
|
553
704
|
|
|
554
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 };
|
|
555
|
-
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
|
@@ -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,
|
package/package.json
CHANGED
|
@@ -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,
|
|
@@ -37,7 +37,7 @@ export type BaseChatOptions<T = Record<string, any>> = {
|
|
|
37
37
|
stream?: boolean;
|
|
38
38
|
} & T;
|
|
39
39
|
|
|
40
|
-
export class BaseChat implements BaseChatInterface,
|
|
40
|
+
export class BaseChat implements BaseChatInterface, Usage {
|
|
41
41
|
/**
|
|
42
42
|
* 默认baseURL
|
|
43
43
|
*/
|
|
@@ -168,7 +168,18 @@ export class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
|
168
168
|
|
|
169
169
|
return stream as unknown as ChatStream;
|
|
170
170
|
}
|
|
171
|
-
|
|
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
|
+
}
|
|
172
183
|
/**
|
|
173
184
|
* 获取聊天使用情况
|
|
174
185
|
* @returns
|