@kevisual/ai 0.0.4 → 0.0.5
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.d.ts +205 -3
- package/dist/ai-provider.js +1485 -88
- package/package.json +3 -3
package/dist/ai-provider.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as openai_resources_index_mjs from 'openai/resources/index.mjs';
|
|
2
2
|
import OpenAI, { OpenAI as OpenAI$1 } from 'openai';
|
|
3
|
+
import * as openai_resources_embeddings_mjs from 'openai/resources/embeddings.mjs';
|
|
4
|
+
import { Permission } from '@kevisual/permission';
|
|
3
5
|
|
|
4
6
|
type ChatMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
|
5
7
|
type ChatMessageOptions = Partial<OpenAI.Chat.Completions.ChatCompletionCreateParams>;
|
|
@@ -204,7 +206,7 @@ declare const CustomProvider: typeof Custom;
|
|
|
204
206
|
declare const VolcesProvider: typeof Volces;
|
|
205
207
|
declare const DeepSeekProvider: typeof DeepSeek;
|
|
206
208
|
declare const ModelScopeProvider: typeof ModelScope;
|
|
207
|
-
declare const
|
|
209
|
+
declare const ChatProviderMap: {
|
|
208
210
|
Ollama: typeof Ollama;
|
|
209
211
|
SiliconFlow: typeof SiliconFlow;
|
|
210
212
|
Custom: typeof Custom;
|
|
@@ -226,5 +228,205 @@ declare class ProviderManager {
|
|
|
226
228
|
chat(messages: ChatMessage[]): Promise<openai_resources_index_mjs.ChatCompletion>;
|
|
227
229
|
}
|
|
228
230
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
+
type KnowledgeOptions<T = Record<string, any>> = BaseChatOptions<{
|
|
232
|
+
embeddingModel?: string;
|
|
233
|
+
splitSize?: number;
|
|
234
|
+
splitOverlap?: number;
|
|
235
|
+
batchSize?: number;
|
|
236
|
+
} & T>;
|
|
237
|
+
/**
|
|
238
|
+
* 知识库构建
|
|
239
|
+
* 1. Embedding generate
|
|
240
|
+
* 2. retriever
|
|
241
|
+
* 3. reranker
|
|
242
|
+
*/
|
|
243
|
+
declare class KnowledgeBase extends BaseChat {
|
|
244
|
+
embeddingModel: string;
|
|
245
|
+
splitSize: number;
|
|
246
|
+
splitOverlap: number;
|
|
247
|
+
batchSize: number;
|
|
248
|
+
constructor(options: KnowledgeOptions);
|
|
249
|
+
/**
|
|
250
|
+
* 生成embedding
|
|
251
|
+
* @param text
|
|
252
|
+
* @returns
|
|
253
|
+
*/
|
|
254
|
+
generateEmbedding(text: string | string[]): Promise<{
|
|
255
|
+
code: number;
|
|
256
|
+
data: openai_resources_embeddings_mjs.Embedding[];
|
|
257
|
+
message?: undefined;
|
|
258
|
+
} | {
|
|
259
|
+
code: any;
|
|
260
|
+
message: string;
|
|
261
|
+
data?: undefined;
|
|
262
|
+
}>;
|
|
263
|
+
/**
|
|
264
|
+
* 批量生成embedding
|
|
265
|
+
* @param text
|
|
266
|
+
* @returns
|
|
267
|
+
*/
|
|
268
|
+
generateEmbeddingBatch(textArray: string[]): Promise<number[][]>;
|
|
269
|
+
/**
|
|
270
|
+
* 分割长文本, 生成对应的embedding
|
|
271
|
+
* @param text
|
|
272
|
+
* @returns
|
|
273
|
+
*/
|
|
274
|
+
splitLongText(text: string): Promise<{
|
|
275
|
+
text: string;
|
|
276
|
+
embedding: number[];
|
|
277
|
+
}[]>;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
declare class SiliconFlowKnowledge extends KnowledgeBase {
|
|
281
|
+
static BASE_URL: string;
|
|
282
|
+
constructor(options: KnowledgeOptions);
|
|
283
|
+
rerank(data: RerankOptions): Promise<any>;
|
|
284
|
+
}
|
|
285
|
+
type RerankOptions = {
|
|
286
|
+
model: string;
|
|
287
|
+
query: string;
|
|
288
|
+
documents: string[];
|
|
289
|
+
top_n?: number;
|
|
290
|
+
return_documents?: boolean;
|
|
291
|
+
max_chunks_per_doc?: number;
|
|
292
|
+
overlap_tokens?: number;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
type AIModel = {
|
|
296
|
+
/**
|
|
297
|
+
* 提供商
|
|
298
|
+
*/
|
|
299
|
+
provider: string;
|
|
300
|
+
/**
|
|
301
|
+
* 模型名称
|
|
302
|
+
*/
|
|
303
|
+
model: string;
|
|
304
|
+
/**
|
|
305
|
+
* 模型组
|
|
306
|
+
*/
|
|
307
|
+
group: string;
|
|
308
|
+
/**
|
|
309
|
+
* 每日请求频率限制
|
|
310
|
+
*/
|
|
311
|
+
dayLimit?: number;
|
|
312
|
+
/**
|
|
313
|
+
* 总的token限制
|
|
314
|
+
*/
|
|
315
|
+
tokenLimit?: number;
|
|
316
|
+
};
|
|
317
|
+
type SecretKey = {
|
|
318
|
+
/**
|
|
319
|
+
* 组
|
|
320
|
+
*/
|
|
321
|
+
group: string;
|
|
322
|
+
/**
|
|
323
|
+
* API密钥
|
|
324
|
+
*/
|
|
325
|
+
apiKey: string;
|
|
326
|
+
/**
|
|
327
|
+
* 解密密钥
|
|
328
|
+
*/
|
|
329
|
+
decryptKey?: string;
|
|
330
|
+
};
|
|
331
|
+
type AIConfig = {
|
|
332
|
+
title?: string;
|
|
333
|
+
description?: string;
|
|
334
|
+
models: AIModel[];
|
|
335
|
+
secretKeys: SecretKey[];
|
|
336
|
+
permission?: Permission;
|
|
337
|
+
filter?: {
|
|
338
|
+
objectKey: string;
|
|
339
|
+
type: 'array' | 'object';
|
|
340
|
+
operate: 'removeAttribute' | 'remove';
|
|
341
|
+
attribute: string[];
|
|
342
|
+
}[];
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
declare function encryptAES(plainText: string, secretKey: string): string;
|
|
346
|
+
declare function decryptAES(cipherText: string, secretKey: string): string;
|
|
347
|
+
type GetProviderOpts = {
|
|
348
|
+
model: string;
|
|
349
|
+
group: string;
|
|
350
|
+
decryptKey?: string;
|
|
351
|
+
};
|
|
352
|
+
type ProviderResult = {
|
|
353
|
+
provider: string;
|
|
354
|
+
model: string;
|
|
355
|
+
group: string;
|
|
356
|
+
apiKey: string;
|
|
357
|
+
dayLimit?: number;
|
|
358
|
+
tokenLimit?: number;
|
|
359
|
+
baseURL?: string;
|
|
360
|
+
/**
|
|
361
|
+
* 解密密钥
|
|
362
|
+
*/
|
|
363
|
+
decryptKey?: string;
|
|
364
|
+
};
|
|
365
|
+
declare class AIConfigParser {
|
|
366
|
+
private config;
|
|
367
|
+
result: ProviderResult;
|
|
368
|
+
constructor(config: AIConfig);
|
|
369
|
+
/**
|
|
370
|
+
* 获取模型配置
|
|
371
|
+
* @param opts
|
|
372
|
+
* @returns
|
|
373
|
+
*/
|
|
374
|
+
getProvider(opts: GetProviderOpts): ProviderResult;
|
|
375
|
+
/**
|
|
376
|
+
* 获取解密密钥
|
|
377
|
+
* @param opts
|
|
378
|
+
* @returns
|
|
379
|
+
*/
|
|
380
|
+
getSecretKey(opts?: {
|
|
381
|
+
getCache?: (key: string) => Promise<string>;
|
|
382
|
+
setCache?: (key: string, value: string) => Promise<void>;
|
|
383
|
+
providerResult?: ProviderResult;
|
|
384
|
+
}): Promise<string>;
|
|
385
|
+
/**
|
|
386
|
+
* 加密
|
|
387
|
+
* @param plainText
|
|
388
|
+
* @param secretKey
|
|
389
|
+
* @returns
|
|
390
|
+
*/
|
|
391
|
+
encrypt(plainText: string, secretKey: string): string;
|
|
392
|
+
/**
|
|
393
|
+
* 解密
|
|
394
|
+
* @param cipherText
|
|
395
|
+
* @param secretKey
|
|
396
|
+
* @returns
|
|
397
|
+
*/
|
|
398
|
+
decrypt(cipherText: string, secretKey: string): string;
|
|
399
|
+
/**
|
|
400
|
+
* 获取模型配置
|
|
401
|
+
* @returns
|
|
402
|
+
*/
|
|
403
|
+
getSelectOpts(): {
|
|
404
|
+
group: string;
|
|
405
|
+
apiKey: string;
|
|
406
|
+
decryptKey?: string;
|
|
407
|
+
provider: string;
|
|
408
|
+
model: string;
|
|
409
|
+
dayLimit?: number;
|
|
410
|
+
tokenLimit?: number;
|
|
411
|
+
}[];
|
|
412
|
+
getConfig(keepSecret?: boolean, config?: AIConfig): AIConfig | {
|
|
413
|
+
secretKeys: {
|
|
414
|
+
apiKey: any;
|
|
415
|
+
decryptKey: any;
|
|
416
|
+
group: string;
|
|
417
|
+
}[];
|
|
418
|
+
title?: string;
|
|
419
|
+
description?: string;
|
|
420
|
+
models?: AIModel[];
|
|
421
|
+
permission?: Permission;
|
|
422
|
+
filter?: {
|
|
423
|
+
objectKey: string;
|
|
424
|
+
type: "array" | "object";
|
|
425
|
+
operate: "removeAttribute" | "remove";
|
|
426
|
+
attribute: string[];
|
|
427
|
+
}[];
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export { AIConfigParser, BaseChat, ChatProviderMap, CustomProvider, DeepSeekProvider, KnowledgeBase, ModelScopeProvider, OllamaProvider, ProviderManager, SiliconFlowKnowledge, SiliconFlowProvider, VolcesProvider, decryptAES, encryptAES, readStream };
|
|
432
|
+
export type { AIConfig, AIModel, BaseChatInterface, BaseChatOptions, BaseChatUsageInterface, ChatMessage, ChatMessageComplete, ChatMessageOptions, ChatMessageStream, ChatStream, EmbeddingMessage, EmbeddingMessageComplete, GetProviderOpts, KnowledgeOptions, ProviderResult, RerankOptions, SecretKey };
|