@kevisual/ai 0.0.11 → 0.0.13
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 +102 -20
- package/dist/ai-provider-browser.js +2056 -7512
- package/dist/ai-provider.d.ts +102 -20
- package/dist/ai-provider.js +220 -5676
- package/package.json +16 -16
- package/src/provider/chat-adapter/kimi.ts +10 -0
- package/src/provider/chat-adapter/ollama.ts +2 -2
- package/src/provider/chat-adapter/siliconflow.ts +1 -1
- package/src/provider/chat-adapter/zhipu.ts +10 -0
- package/src/provider/chat.ts +6 -0
- package/src/provider/core/chat.ts +104 -39
- package/src/provider/core/index.ts +0 -11
- package/src/provider/core/utils/index.ts +192 -0
- package/src/provider/knowledge-adapter/siliconflow.ts +2 -2
- package/src/test/aliyun/test.ts +46 -13
- package/src/provider/utils/chunk.ts +0 -86
package/dist/ai-provider.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as openai_resources_index_mjs from 'openai/resources/index.mjs';
|
|
2
2
|
import OpenAI, { OpenAI as OpenAI$1 } from 'openai';
|
|
3
3
|
import * as openai_resources_embeddings_mjs from 'openai/resources/embeddings.mjs';
|
|
4
|
-
import
|
|
4
|
+
import * as _kevisual_permission from '@kevisual/permission';
|
|
5
|
+
import { Permission } from '@kevisual/permission';
|
|
5
6
|
|
|
6
7
|
type ChatMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
|
7
8
|
type ChatMessageOptions = Partial<OpenAI.Chat.Completions.ChatCompletionCreateParams> & {
|
|
@@ -34,6 +35,77 @@ interface BaseChatUsageInterface {
|
|
|
34
35
|
}
|
|
35
36
|
type ChatStream = AsyncGenerator<ChatMessageComplete, void, unknown>;
|
|
36
37
|
|
|
38
|
+
declare class AIUtils {
|
|
39
|
+
/**
|
|
40
|
+
* 从 Markdown 代码块中提取 JSON
|
|
41
|
+
* @param str 包含 JSON 的字符串
|
|
42
|
+
* @returns 解析后的对象或 null
|
|
43
|
+
*/
|
|
44
|
+
extractJsonFromMarkdown(str: string): any | null;
|
|
45
|
+
/**
|
|
46
|
+
* 从 Markdown 代码块中提取代码
|
|
47
|
+
* @param str Markdown 字符串
|
|
48
|
+
* @param language 语言类型,不指定则返回所有代码块
|
|
49
|
+
* @returns 提取的代码字符串或数组
|
|
50
|
+
*/
|
|
51
|
+
extractCodeFromMarkdown(str: string, language?: string): string | string[] | null;
|
|
52
|
+
/**
|
|
53
|
+
* 清理 AI 响应中的多余空白和格式
|
|
54
|
+
* @param str 原始字符串
|
|
55
|
+
* @returns 清理后的字符串
|
|
56
|
+
*/
|
|
57
|
+
cleanResponse(str: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* 从 AI 响应中提取标签
|
|
60
|
+
* @param str 响应字符串
|
|
61
|
+
* @returns 标签数组
|
|
62
|
+
*/
|
|
63
|
+
extractTags(str: string): string[];
|
|
64
|
+
/**
|
|
65
|
+
* 从文本中提取 URL
|
|
66
|
+
* @param str 文本字符串
|
|
67
|
+
* @returns URL 数组
|
|
68
|
+
*/
|
|
69
|
+
extractUrls(str: string): string[];
|
|
70
|
+
/**
|
|
71
|
+
* 分割长文本为指定 token 数量的块
|
|
72
|
+
* @param text 原始文本
|
|
73
|
+
* @param maxTokens 每块最大 token 数(粗略估算:1 token ≈ 4 字符)
|
|
74
|
+
* @returns 文本块数组
|
|
75
|
+
*/
|
|
76
|
+
chunkText(text: string, maxTokens?: number): string[];
|
|
77
|
+
/**
|
|
78
|
+
* 移除 AI 响应中的思考过程(thinking 标签)
|
|
79
|
+
* @param str 响应字符串
|
|
80
|
+
* @returns 清理后的字符串
|
|
81
|
+
*/
|
|
82
|
+
removeThinkingTags(str: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* 转义特殊字符用于 AI 提示词
|
|
85
|
+
* @param str 原始字符串
|
|
86
|
+
* @returns 转义后的字符串
|
|
87
|
+
*/
|
|
88
|
+
escapeForPrompt(str: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* 统计文本的大致 token 数量
|
|
91
|
+
* @param text 文本
|
|
92
|
+
* @returns 估算的 token 数量
|
|
93
|
+
*/
|
|
94
|
+
estimateTokens(text: string): number;
|
|
95
|
+
/**
|
|
96
|
+
* 从响应中提取结构化数据(key: value 格式)
|
|
97
|
+
* @param str 响应字符串
|
|
98
|
+
* @returns 键值对对象
|
|
99
|
+
*/
|
|
100
|
+
extractKeyValuePairs(str: string): Record<string, string>;
|
|
101
|
+
/**
|
|
102
|
+
* 验证 AI 响应是否完整(检查截断)
|
|
103
|
+
* @param str 响应字符串
|
|
104
|
+
* @returns 是否完整
|
|
105
|
+
*/
|
|
106
|
+
isResponseComplete(str: string): boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
37
109
|
type BaseChatOptions<T = Record<string, any>> = {
|
|
38
110
|
/**
|
|
39
111
|
* 默认baseURL
|
|
@@ -56,7 +128,6 @@ type BaseChatOptions<T = Record<string, any>> = {
|
|
|
56
128
|
*/
|
|
57
129
|
stream?: boolean;
|
|
58
130
|
} & T;
|
|
59
|
-
declare const getIsBrowser: () => boolean;
|
|
60
131
|
declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
61
132
|
/**
|
|
62
133
|
* 默认baseURL
|
|
@@ -70,27 +141,24 @@ declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
|
|
70
141
|
* 默认apiKey
|
|
71
142
|
*/
|
|
72
143
|
apiKey: string;
|
|
73
|
-
/**
|
|
74
|
-
* 是否在浏览器中使用
|
|
75
|
-
*/
|
|
76
|
-
isBrowser: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* openai实例
|
|
79
|
-
*/
|
|
80
|
-
openai: OpenAI$1;
|
|
81
144
|
prompt_tokens: number;
|
|
82
145
|
total_tokens: number;
|
|
83
146
|
completion_tokens: number;
|
|
147
|
+
responseText: string;
|
|
148
|
+
utils: AIUtils;
|
|
84
149
|
constructor(options: BaseChatOptions);
|
|
150
|
+
post(url?: string, opts?: {
|
|
151
|
+
headers?: Record<string, string>;
|
|
152
|
+
data?: any;
|
|
153
|
+
}): Promise<Response>;
|
|
154
|
+
get<T = any>(url?: string, opts?: {
|
|
155
|
+
headers?: Record<string, string>;
|
|
156
|
+
}): Promise<T>;
|
|
85
157
|
/**
|
|
86
158
|
* 聊天
|
|
87
159
|
*/
|
|
88
160
|
chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
|
|
89
161
|
chatStream(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatStream>;
|
|
90
|
-
/**
|
|
91
|
-
* 测试
|
|
92
|
-
*/
|
|
93
|
-
test(): Promise<OpenAI$1.Chat.Completions.ChatCompletion>;
|
|
94
162
|
/**
|
|
95
163
|
* 获取聊天使用情况
|
|
96
164
|
* @returns
|
|
@@ -213,6 +281,18 @@ declare class BailianChat extends BaseChat {
|
|
|
213
281
|
constructor(options: BailianOptions);
|
|
214
282
|
}
|
|
215
283
|
|
|
284
|
+
type ZhipuOptions = Partial<BaseChatOptions>;
|
|
285
|
+
declare class Zhipu extends BaseChat {
|
|
286
|
+
static BASE_URL: string;
|
|
287
|
+
constructor(options: ZhipuOptions);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
type KimiOptions = Partial<BaseChatOptions>;
|
|
291
|
+
declare class Kimi extends BaseChat {
|
|
292
|
+
static BASE_URL: string;
|
|
293
|
+
constructor(options: KimiOptions);
|
|
294
|
+
}
|
|
295
|
+
|
|
216
296
|
declare const OllamaProvider: typeof Ollama;
|
|
217
297
|
declare const SiliconFlowProvider: typeof SiliconFlow;
|
|
218
298
|
declare const CustomProvider: typeof Custom;
|
|
@@ -220,6 +300,8 @@ declare const VolcesProvider: typeof Volces;
|
|
|
220
300
|
declare const DeepSeekProvider: typeof DeepSeek;
|
|
221
301
|
declare const ModelScopeProvider: typeof ModelScope;
|
|
222
302
|
declare const BailianProvider: typeof BailianChat;
|
|
303
|
+
declare const ZhipuProvider: typeof Zhipu;
|
|
304
|
+
declare const KimiProvider: typeof Kimi;
|
|
223
305
|
declare const ChatProviderMap: {
|
|
224
306
|
Ollama: typeof Ollama;
|
|
225
307
|
SiliconFlow: typeof SiliconFlow;
|
|
@@ -229,6 +311,8 @@ declare const ChatProviderMap: {
|
|
|
229
311
|
ModelScope: typeof ModelScope;
|
|
230
312
|
BaseChat: typeof BaseChat;
|
|
231
313
|
Bailian: typeof BailianChat;
|
|
314
|
+
Zhipu: typeof Zhipu;
|
|
315
|
+
Kimi: typeof Kimi;
|
|
232
316
|
};
|
|
233
317
|
type ProviderManagerConfig = {
|
|
234
318
|
provider: string;
|
|
@@ -295,9 +379,7 @@ declare class KnowledgeBase extends BaseChat {
|
|
|
295
379
|
declare class SiliconFlowKnowledge extends KnowledgeBase {
|
|
296
380
|
static BASE_URL: string;
|
|
297
381
|
constructor(options: KnowledgeOptions);
|
|
298
|
-
rerank(data: RerankOptions): Promise<
|
|
299
|
-
_request_id?: string | null;
|
|
300
|
-
}>;
|
|
382
|
+
rerank(data: RerankOptions): Promise<Response>;
|
|
301
383
|
}
|
|
302
384
|
type RerankOptions = {
|
|
303
385
|
model: string;
|
|
@@ -350,7 +432,7 @@ type AIConfig = {
|
|
|
350
432
|
description?: string;
|
|
351
433
|
models: AIModel[];
|
|
352
434
|
secretKeys: SecretKey[];
|
|
353
|
-
permission?: Permission
|
|
435
|
+
permission?: Permission;
|
|
354
436
|
filter?: {
|
|
355
437
|
objectKey: string;
|
|
356
438
|
type: 'array' | 'object';
|
|
@@ -435,7 +517,7 @@ declare class AIConfigParser {
|
|
|
435
517
|
title?: string;
|
|
436
518
|
description?: string;
|
|
437
519
|
models?: AIModel[];
|
|
438
|
-
permission?: Permission;
|
|
520
|
+
permission?: _kevisual_permission.Permission;
|
|
439
521
|
filter?: {
|
|
440
522
|
objectKey: string;
|
|
441
523
|
type: "array" | "object";
|
|
@@ -445,5 +527,5 @@ declare class AIConfigParser {
|
|
|
445
527
|
};
|
|
446
528
|
}
|
|
447
529
|
|
|
448
|
-
export { AIConfigParser, BailianProvider, BaseChat, ChatProviderMap, CustomProvider, DeepSeekProvider, KnowledgeBase, ModelScopeProvider, OllamaProvider, ProviderManager, SiliconFlowKnowledge, SiliconFlowProvider, VolcesProvider, decryptAES, encryptAES,
|
|
530
|
+
export { AIConfigParser, BailianProvider, BaseChat, ChatProviderMap, CustomProvider, DeepSeekProvider, KimiProvider, KnowledgeBase, ModelScopeProvider, OllamaProvider, ProviderManager, SiliconFlowKnowledge, SiliconFlowProvider, VolcesProvider, ZhipuProvider, decryptAES, encryptAES, readStream };
|
|
449
531
|
export type { AIConfig, AIModel, BaseChatInterface, BaseChatOptions, BaseChatUsageInterface, ChatMessage, ChatMessageComplete, ChatMessageOptions, ChatMessageStream, ChatStream, EmbeddingMessage, EmbeddingMessageComplete, GetProviderOpts, KnowledgeOptions, ProviderResult, RerankOptions, SecretKey };
|