@kevisual/ai 0.0.16 → 0.0.18

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.
@@ -118,7 +118,11 @@ type BaseChatOptions<T = Record<string, any>> = {
118
118
  /**
119
119
  * 默认apiKey
120
120
  */
121
- apiKey: string;
121
+ apiKey?: string;
122
+ /**
123
+ * token
124
+ */
125
+ token?: string;
122
126
  /**
123
127
  * 是否在浏览器中使用
124
128
  */
@@ -293,26 +297,46 @@ declare class Kimi extends BaseChat {
293
297
  constructor(options: KimiOptions);
294
298
  }
295
299
 
296
- declare const OllamaProvider: typeof Ollama;
297
- declare const SiliconFlowProvider: typeof SiliconFlow;
298
- declare const CustomProvider: typeof Custom;
299
- declare const VolcesProvider: typeof Volces;
300
- declare const DeepSeekProvider: typeof DeepSeek;
301
- declare const ModelScopeProvider: typeof ModelScope;
302
- declare const BailianProvider: typeof BailianChat;
303
- declare const ZhipuProvider: typeof Zhipu;
304
- declare const KimiProvider: typeof Kimi;
300
+ type KevisualOptions = Partial<BaseChatOptions>;
301
+ /**
302
+ * Kevisual Chat Adapter
303
+ */
304
+ declare class Kevisual extends BaseChat {
305
+ static BASE_URL: string;
306
+ constructor(options: KevisualOptions);
307
+ }
308
+
309
+ declare class OllamaProvider extends Ollama {
310
+ }
311
+ declare class SiliconFlowProvider extends SiliconFlow {
312
+ }
313
+ declare class CustomProvider extends Custom {
314
+ }
315
+ declare class VolcesProvider extends Volces {
316
+ }
317
+ declare class DeepSeekProvider extends DeepSeek {
318
+ }
319
+ declare class ModelScopeProvider extends ModelScope {
320
+ }
321
+ declare class BailianProvider extends BailianChat {
322
+ }
323
+ declare class ZhipuProvider extends Zhipu {
324
+ }
325
+ declare class KimiProvider extends Kimi {
326
+ }
327
+ declare class KevisualProvider extends Kevisual {
328
+ }
305
329
  declare const ChatProviderMap: {
306
- Ollama: typeof Ollama;
307
- SiliconFlow: typeof SiliconFlow;
308
- Custom: typeof Custom;
309
- Volces: typeof Volces;
310
- DeepSeek: typeof DeepSeek;
311
- ModelScope: typeof ModelScope;
330
+ Ollama: typeof OllamaProvider;
331
+ SiliconFlow: typeof SiliconFlowProvider;
332
+ Custom: typeof CustomProvider;
333
+ Volces: typeof VolcesProvider;
334
+ DeepSeek: typeof DeepSeekProvider;
335
+ ModelScope: typeof ModelScopeProvider;
312
336
  BaseChat: typeof BaseChat;
313
- Bailian: typeof BailianChat;
314
- Zhipu: typeof Zhipu;
315
- Kimi: typeof Kimi;
337
+ Bailian: typeof BailianProvider;
338
+ Zhipu: typeof ZhipuProvider;
339
+ Kimi: typeof KimiProvider;
316
340
  };
317
341
  type ProviderManagerConfig = {
318
342
  provider: string;
@@ -527,5 +551,5 @@ declare class AIConfigParser {
527
551
  };
528
552
  }
529
553
 
530
- export { AIConfigParser, AIUtils, BailianChat, BailianProvider, BaseChat, ChatProviderMap, Custom, CustomProvider, DeepSeek, DeepSeekProvider, Kimi, KimiProvider, KnowledgeBase, ModelScope, ModelScopeProvider, Ollama, OllamaProvider, ProviderManager, SiliconFlow, SiliconFlowKnowledge, SiliconFlowProvider, Volces, VolcesProvider, Zhipu, ZhipuProvider, decryptAES, encryptAES, readStream };
554
+ 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 };
531
555
  export type { AIConfig, AIModel, BaseChatInterface, BaseChatOptions, BaseChatUsageInterface, ChatMessage, ChatMessageComplete, ChatMessageOptions, ChatMessageStream, ChatStream, EmbeddingMessage, EmbeddingMessageComplete, GetProviderOpts, KnowledgeOptions, ProviderResult, RerankOptions, SecretKey };
@@ -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;
@@ -1573,6 +1573,9 @@ class BailianChat extends BaseChat {
1573
1573
  static BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1";
1574
1574
  constructor(options) {
1575
1575
  const baseURL = options.baseURL || BailianChat.BASE_URL;
1576
+ if (!options.model) {
1577
+ options.model = "qwen-plus";
1578
+ }
1576
1579
  super({ ...options, baseURL });
1577
1580
  }
1578
1581
  }
@@ -1595,16 +1598,48 @@ class Kimi extends BaseChat {
1595
1598
  }
1596
1599
  }
1597
1600
 
1601
+ // src/provider/chat-adapter/kevisual.ts
1602
+ class Kevisual extends BaseChat {
1603
+ static BASE_URL = "https://newapi.kevisual.cn/v1/";
1604
+ constructor(options) {
1605
+ const baseURL = options.baseURL || Kevisual.BASE_URL;
1606
+ if (!options.model) {
1607
+ options.model = "qwen-plus";
1608
+ }
1609
+ super({ ...options, baseURL });
1610
+ }
1611
+ }
1612
+
1598
1613
  // src/provider/chat.ts
1599
- var OllamaProvider = Ollama;
1600
- var SiliconFlowProvider = SiliconFlow;
1601
- var CustomProvider = Custom;
1602
- var VolcesProvider = Volces;
1603
- var DeepSeekProvider = DeepSeek;
1604
- var ModelScopeProvider = ModelScope;
1605
- var BailianProvider = BailianChat;
1606
- var ZhipuProvider = Zhipu;
1607
- var KimiProvider = Kimi;
1614
+ class OllamaProvider extends Ollama {
1615
+ }
1616
+
1617
+ class SiliconFlowProvider extends SiliconFlow {
1618
+ }
1619
+
1620
+ class CustomProvider extends Custom {
1621
+ }
1622
+
1623
+ class VolcesProvider extends Volces {
1624
+ }
1625
+
1626
+ class DeepSeekProvider extends DeepSeek {
1627
+ }
1628
+
1629
+ class ModelScopeProvider extends ModelScope {
1630
+ }
1631
+
1632
+ class BailianProvider extends BailianChat {
1633
+ }
1634
+
1635
+ class ZhipuProvider extends Zhipu {
1636
+ }
1637
+
1638
+ class KimiProvider extends Kimi {
1639
+ }
1640
+
1641
+ class KevisualProvider extends Kevisual {
1642
+ }
1608
1643
  var ChatProviderMap = {
1609
1644
  Ollama: OllamaProvider,
1610
1645
  SiliconFlow: SiliconFlowProvider,
@@ -1841,6 +1876,8 @@ export {
1841
1876
  KnowledgeBase,
1842
1877
  KimiProvider,
1843
1878
  Kimi,
1879
+ KevisualProvider,
1880
+ Kevisual,
1844
1881
  DeepSeekProvider,
1845
1882
  DeepSeek,
1846
1883
  CustomProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/ai",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "AI Center Services",
5
5
  "main": "index.js",
6
6
  "basename": "/root/ai-center-services",
@@ -13,13 +13,6 @@
13
13
  "src",
14
14
  "types"
15
15
  ],
16
- "scripts": {
17
- "build": "npm run clean && bun bun.config.mjs",
18
- "dev": "bun run --watch bun.config.mjs",
19
- "test": "tsx test/**/*.ts",
20
- "clean": "rm -rf dist",
21
- "pub": "envision pack -p -u"
22
- },
23
16
  "keywords": [
24
17
  "kevisual",
25
18
  "ai",
@@ -27,7 +20,6 @@
27
20
  ],
28
21
  "author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
29
22
  "license": "MIT",
30
- "packageManager": "pnpm@10.24.0",
31
23
  "type": "module",
32
24
  "publishConfig": {
33
25
  "registry": "https://registry.npmjs.org/",
@@ -53,40 +45,34 @@
53
45
  }
54
46
  },
55
47
  "devDependencies": {
56
- "@kevisual/code-center-module": "0.0.24",
57
- "@kevisual/mark": "0.0.7",
58
- "@kevisual/router": "0.0.33",
48
+ "@kevisual/router": "0.0.36",
59
49
  "@kevisual/types": "^0.0.10",
60
50
  "@kevisual/use-config": "^1.0.21",
61
- "@types/bun": "^1.3.3",
51
+ "@types/bun": "^1.3.4",
62
52
  "@types/crypto-js": "^4.2.2",
63
53
  "@types/formidable": "^3.4.6",
64
- "@types/lodash-es": "^4.17.12",
65
54
  "@types/node": "^24.10.1",
66
- "@vitejs/plugin-basic-ssl": "^2.1.0",
67
- "cookie": "^1.1.1",
68
55
  "cross-env": "^10.1.0",
69
56
  "crypto-js": "^4.2.0",
70
57
  "dayjs": "^1.11.19",
71
58
  "dotenv": "^17.2.3",
72
59
  "formidable": "^3.5.4",
73
- "ioredis": "^5.8.2",
74
- "json5": "^2.2.3",
75
- "lodash-es": "^4.17.21",
76
60
  "openai": "6.10.0",
77
61
  "pm2": "^6.0.14",
78
62
  "rimraf": "^6.1.2",
79
- "rollup": "^4.53.3",
80
- "rollup-plugin-dts": "^6.3.0",
81
- "sequelize": "^6.37.7",
82
- "tape": "^5.9.0",
83
- "tiktoken": "^1.0.22",
84
63
  "typescript": "^5.9.3",
85
64
  "vite": "^7.2.6"
86
65
  },
87
66
  "dependencies": {
88
67
  "@kevisual/logger": "^0.0.4",
89
68
  "@kevisual/permission": "^0.0.3",
90
- "@kevisual/query": "^0.0.30"
69
+ "@kevisual/query": "^0.0.31"
70
+ },
71
+ "scripts": {
72
+ "build": "npm run clean && bun bun.config.mjs",
73
+ "dev": "bun run --watch bun.config.mjs",
74
+ "test": "tsx test/**/*.ts",
75
+ "clean": "rm -rf dist",
76
+ "pub": "envision pack -p -u"
91
77
  }
92
78
  }
@@ -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
  }
@@ -0,0 +1,17 @@
1
+ import { BaseChat, BaseChatOptions } from '../core/chat.ts';
2
+
3
+ export type KevisualOptions = Partial<BaseChatOptions>;
4
+
5
+ /**
6
+ * Kevisual Chat Adapter
7
+ */
8
+ export class Kevisual extends BaseChat {
9
+ static BASE_URL = 'https://newapi.kevisual.cn/v1/';
10
+ constructor(options: KevisualOptions) {
11
+ const baseURL = options.baseURL || Kevisual.BASE_URL;
12
+ if (!options.model) {
13
+ options.model = 'qwen-plus'
14
+ }
15
+ super({ ...(options as BaseChatOptions), baseURL: baseURL });
16
+ }
17
+ }
@@ -10,6 +10,7 @@ import { ModelScope } from './chat-adapter/model-scope.ts';
10
10
  import { BailianChat } from './chat-adapter/dashscope.ts';
11
11
  import { Zhipu } from './chat-adapter/zhipu.ts';
12
12
  import { Kimi } from './chat-adapter/kimi.ts';
13
+ import { Kevisual } from './chat-adapter/kevisual.ts';
13
14
 
14
15
  import { ChatMessage } from './core/type.ts';
15
16
 
@@ -25,16 +26,19 @@ export {
25
26
  Zhipu,
26
27
  Kimi,
27
28
  ChatMessage,
29
+ Kevisual,
28
30
  }
29
- export const OllamaProvider = Ollama;
30
- export const SiliconFlowProvider = SiliconFlow;
31
- export const CustomProvider = Custom;
32
- export const VolcesProvider = Volces;
33
- export const DeepSeekProvider = DeepSeek;
34
- export const ModelScopeProvider = ModelScope;
35
- export const BailianProvider = BailianChat;
36
- export const ZhipuProvider = Zhipu;
37
- export const KimiProvider = Kimi;
31
+ export class OllamaProvider extends Ollama { }
32
+ export class SiliconFlowProvider extends SiliconFlow { }
33
+ export class CustomProvider extends Custom { }
34
+ export class VolcesProvider extends Volces { }
35
+ export class DeepSeekProvider extends DeepSeek { }
36
+ export class ModelScopeProvider extends ModelScope { }
37
+ export class BailianProvider extends BailianChat { }
38
+ export class ZhipuProvider extends Zhipu { }
39
+ export class KimiProvider extends Kimi { }
40
+ export class KevisualProvider extends Kevisual { }
41
+
38
42
 
39
43
  export const ChatProviderMap = {
40
44
  Ollama: OllamaProvider,
@@ -22,7 +22,11 @@ export type BaseChatOptions<T = Record<string, any>> = {
22
22
  /**
23
23
  * 默认apiKey
24
24
  */
25
- apiKey: string;
25
+ apiKey?: string;
26
+ /**
27
+ * token
28
+ */
29
+ token?: string;
26
30
  /**
27
31
  * 是否在浏览器中使用
28
32
  */
@@ -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;
@@ -1,34 +0,0 @@
1
- import { encoding_for_model, get_encoding } from 'tiktoken';
2
-
3
-
4
- const MODEL_TO_ENCODING = {
5
- 'gpt-4': 'cl100k_base',
6
- 'gpt-4-turbo': 'cl100k_base',
7
- 'gpt-3.5-turbo': 'cl100k_base',
8
- 'text-embedding-ada-002': 'cl100k_base',
9
- 'text-davinci-002': 'p50k_base',
10
- 'text-davinci-003': 'p50k_base',
11
- } as const;
12
-
13
- export function numTokensFromString(text: string, model: keyof typeof MODEL_TO_ENCODING = 'gpt-3.5-turbo'): number {
14
- try {
15
- // 对于特定模型使用专门的编码器
16
- const encoder = encoding_for_model(model);
17
- const tokens = encoder.encode(text);
18
- const tokenCount = tokens.length;
19
- encoder.free(); // 释放编码器
20
- return tokenCount;
21
- } catch (error) {
22
- try {
23
- // 如果模型特定的编码器失败,尝试使用基础编码器
24
- const encoder = get_encoding(MODEL_TO_ENCODING[model]);
25
- const tokens = encoder.encode(text);
26
- const tokenCount = tokens.length;
27
- encoder.free(); // 释放编码器
28
- return tokenCount;
29
- } catch (error) {
30
- // 如果编码失败,使用一个粗略的估计:平均每个字符0.25个token
31
- return Math.ceil(text.length * 0.25);
32
- }
33
- }
34
- }