@kevisual/ai 0.0.18 → 0.0.20

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.
@@ -1,25 +1,171 @@
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 = OpenAI.Chat.Completions.ChatCompletionMessageParam;
8
- type ChatMessageOptions = Partial<OpenAI.Chat.Completions.ChatCompletionCreateParams> & {
4
+ type ChatMessage = {
5
+ role?: 'user' | 'assistant' | 'system' | 'tool';
6
+ content: string;
7
+ };
8
+ type ChatMessageOptions<T = {}> = {
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
- * 如果会话是千文,服务器的接口,默认为 true
49
+ * 如果会话是千文,服务器的接口,默认为 false
12
50
  */
13
51
  enable_thinking?: boolean;
52
+ response_format?: 'text' | 'json' | 'xml' | 'html';
53
+ /**
54
+ * 工具调用参数
55
+ */
56
+ tool_calls?: any;
57
+ [key: string]: any;
58
+ } & T;
59
+ type Choice = {
60
+ finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
61
+ index: number;
62
+ message: {
63
+ role: 'assistant' | 'tool';
64
+ content: string;
65
+ };
66
+ };
67
+ type ChatMessageComplete = {
68
+ /**
69
+ * 聊天完成的唯一标识符
70
+ */
71
+ id: string;
72
+ /**
73
+ * 聊天完成选项列表
74
+ * 如果 n 大于 1,可以有多个选项
75
+ */
76
+ choices: Array<Choice>;
77
+ /**
78
+ * 聊天完成创建时的 Unix 时间戳(秒)
79
+ */
80
+ created: number;
81
+ /**
82
+ * 用于聊天完成的模型名称
83
+ */
84
+ model: string;
85
+ /**
86
+ * 对象类型,始终为 `chat.completion`
87
+ */
88
+ object: 'chat.completion';
89
+ /**
90
+ * 系统指纹
91
+ * 用于标识后端配置
92
+ */
93
+ system_fingerprint?: string;
94
+ /**
95
+ * 完成请求的使用统计信息
96
+ */
97
+ usage?: Usage;
98
+ };
99
+ /**
100
+ * 向量嵌入请求参数
101
+ */
102
+ type EmbeddingMessage = {
103
+ /**
104
+ * 输入文本或文本数组
105
+ * 要生成嵌入向量的文本内容
106
+ */
107
+ input: string | string[];
108
+ /**
109
+ * 模型名称
110
+ * 用于生成嵌入向量的模型
111
+ */
112
+ model: string;
113
+ /**
114
+ * 编码格式
115
+ * 返回的嵌入向量编码格式
116
+ */
117
+ encoding_format?: 'float' | 'base64';
118
+ /**
119
+ * 维度
120
+ * 输出嵌入向量的维度(某些模型支持)
121
+ */
122
+ dimensions?: number;
123
+ };
124
+ /**
125
+ * 单个嵌入向量对象
126
+ */
127
+ type EmbeddingObject = {
128
+ /**
129
+ * 对象类型,始终为 `embedding`
130
+ */
131
+ object: 'embedding';
132
+ /**
133
+ * 嵌入向量
134
+ * 浮点数数组,表示文本的向量表示
135
+ */
136
+ embedding: number[];
137
+ /**
138
+ * 索引位置
139
+ * 该嵌入在输入数组中的位置
140
+ */
141
+ index: number;
142
+ };
143
+ /**
144
+ * 向量嵌入响应结果
145
+ */
146
+ type EmbeddingMessageComplete = {
147
+ /**
148
+ * 对象类型,始终为 `list`
149
+ */
150
+ object: 'list';
151
+ /**
152
+ * 嵌入向量数据列表
153
+ */
154
+ data: EmbeddingObject[];
155
+ /**
156
+ * 使用的模型名称
157
+ */
158
+ model: string;
159
+ /**
160
+ * 使用统计信息
161
+ */
162
+ usage: Usage;
14
163
  };
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
164
  interface BaseChatInterface {
165
+ chat(options: ChatMessageOptions): Promise<ChatMessageComplete>;
20
166
  chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
21
167
  }
22
- interface BaseChatUsageInterface {
168
+ interface Usage {
23
169
  /**
24
170
  * 提示词令牌
25
171
  */
@@ -132,7 +278,7 @@ type BaseChatOptions<T = Record<string, any>> = {
132
278
  */
133
279
  stream?: boolean;
134
280
  } & T;
135
- declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
281
+ declare class BaseChat implements BaseChatInterface, Usage {
136
282
  /**
137
283
  * 默认baseURL
138
284
  */
@@ -161,8 +307,17 @@ declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
161
307
  /**
162
308
  * 聊天
163
309
  */
310
+ chat(options: ChatMessageOptions): Promise<ChatMessageComplete>;
164
311
  chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatMessageComplete>;
165
- chatStream(messages: ChatMessage[], options?: ChatMessageOptions): Promise<ChatStream>;
312
+ chatStream(options: ChatMessageOptions): AsyncGenerator<ChatMessageComplete>;
313
+ chatStream(messages: ChatMessage[], options?: ChatMessageOptions): AsyncGenerator<ChatMessageComplete>;
314
+ /**
315
+ * 简单提问接口
316
+ * @param message
317
+ * @param options
318
+ * @returns
319
+ */
320
+ question(message: string, options?: ChatMessageOptions): Promise<ChatMessageComplete>;
166
321
  /**
167
322
  * 获取聊天使用情况
168
323
  * @returns
@@ -172,6 +327,11 @@ declare class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
172
327
  total_tokens: number;
173
328
  completion_tokens: number;
174
329
  };
330
+ setChatUsage(usage: {
331
+ prompt_tokens?: number;
332
+ total_tokens?: number;
333
+ completion_tokens?: number;
334
+ }): void;
175
335
  getHeaders(headers?: Record<string, string>): {
176
336
  'Content-Type': string;
177
337
  Authorization: string;
@@ -211,7 +371,6 @@ type OllamaModel = {
211
371
  declare class Ollama extends BaseChat {
212
372
  static BASE_URL: string;
213
373
  constructor(options: OllamaOptions$1);
214
- chat(messages: ChatMessage[], options?: ChatMessageOptions): Promise<openai_resources_index_mjs.ChatCompletion>;
215
374
  /**
216
375
  * 获取模型列表
217
376
  * @returns
@@ -249,7 +408,6 @@ declare class SiliconFlow extends BaseChat {
249
408
  static BASE_URL: string;
250
409
  constructor(options: SiliconFlowOptions);
251
410
  getUsageInfo(): Promise<SiliconFlowUsageResponse>;
252
- chat(messages: OpenAI$1.Chat.Completions.ChatCompletionMessageParam[], options?: ChatMessageOptions): Promise<OpenAI$1.Chat.Completions.ChatCompletion>;
253
411
  }
254
412
 
255
413
  type OllamaOptions = BaseChatOptions;
@@ -348,7 +506,7 @@ declare class ProviderManager {
348
506
  provider: BaseChat;
349
507
  constructor(config: ProviderManagerConfig);
350
508
  static createProvider(config: ProviderManagerConfig): Promise<BaseChat>;
351
- chat(messages: ChatMessage[]): Promise<openai_resources_index_mjs.ChatCompletion>;
509
+ chat(messages: ChatMessage[]): Promise<ChatMessageComplete>;
352
510
  }
353
511
 
354
512
  type KnowledgeOptions<T = Record<string, any>> = BaseChatOptions<{
@@ -376,7 +534,7 @@ declare class KnowledgeBase extends BaseChat {
376
534
  */
377
535
  generateEmbedding(text: string | string[]): Promise<{
378
536
  code: number;
379
- data: openai_resources_embeddings_mjs.Embedding[];
537
+ data: EmbeddingObject[];
380
538
  message?: undefined;
381
539
  } | {
382
540
  code: any;
@@ -552,4 +710,4 @@ declare class AIConfigParser {
552
710
  }
553
711
 
554
712
  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, BaseChatUsageInterface, ChatMessage, ChatMessageComplete, ChatMessageOptions, ChatMessageStream, ChatStream, EmbeddingMessage, EmbeddingMessageComplete, GetProviderOpts, KnowledgeOptions, ProviderResult, RerankOptions, SecretKey };
713
+ export type { AIConfig, AIModel, BaseChatInterface, BaseChatOptions, ChatMessage, ChatMessageComplete, ChatMessageOptions, ChatStream, EmbeddingMessage, EmbeddingMessageComplete, EmbeddingObject, GetProviderOpts, KnowledgeOptions, ProviderResult, RerankOptions, SecretKey, Usage };