@zwa73/utils 1.0.266 → 1.0.267
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/UtilClass/Hbs.d.ts +3 -2
- package/dist/UtilClass/Hbs.js +3 -2
- package/dist/UtilCodecs.d.ts +6 -0
- package/dist/UtilCodecs.js +16 -6
- package/package.json +1 -1
package/dist/UtilClass/Hbs.d.ts
CHANGED
|
@@ -10,8 +10,9 @@ export declare class Hbs<T extends Record<Keyable, any> = Record<Keyable, any>>
|
|
|
10
10
|
*/
|
|
11
11
|
private constructor();
|
|
12
12
|
/**创建一个新的 Hbs 实例
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
* 依赖于 handlebars@4.7.8 但不会自动安装
|
|
14
|
+
* @param context - 上下文对象,用于在渲染模板时提供数据
|
|
15
|
+
*/
|
|
15
16
|
static create<T extends Record<Keyable, any> = Record<Keyable, any>>(context?: T): Promise<Hbs<T>>;
|
|
16
17
|
/**渲染模板
|
|
17
18
|
* @param template - 要渲染的 Handlebars 模板字符串
|
package/dist/UtilClass/Hbs.js
CHANGED
|
@@ -31,8 +31,9 @@ class Hbs {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
/**创建一个新的 Hbs 实例
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
* 依赖于 handlebars@4.7.8 但不会自动安装
|
|
35
|
+
* @param context - 上下文对象,用于在渲染模板时提供数据
|
|
36
|
+
*/
|
|
36
37
|
static async create(context = {}) {
|
|
37
38
|
const Handlebars = await js_utils_1.JsFunc.dynamicImport('handlebars');
|
|
38
39
|
if (Handlebars == undefined)
|
package/dist/UtilCodecs.d.ts
CHANGED
|
@@ -11,31 +11,37 @@ export declare namespace UtilCodec {
|
|
|
11
11
|
*/
|
|
12
12
|
function encodeHtmlEntities(str: string): string;
|
|
13
13
|
/**token长度计算器 Turbo模型
|
|
14
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
14
15
|
* @param str = 所要计算的消息
|
|
15
16
|
* @returns 整数长度结果
|
|
16
17
|
*/
|
|
17
18
|
function tokenNumTurbo(str: string): Promise<number>;
|
|
18
19
|
/**token长度计算器 Davinci模型
|
|
20
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
19
21
|
* @param str = 所要计算的消息
|
|
20
22
|
* @returns 整数长度结果
|
|
21
23
|
*/
|
|
22
24
|
function tokenNumDavinci(str: string): Promise<number>;
|
|
23
25
|
/**token编码 Turbo模型
|
|
26
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
24
27
|
* @param str = 所要计算的消息
|
|
25
28
|
* @returns Token数组
|
|
26
29
|
*/
|
|
27
30
|
function encodeTokenTurbo(str: string): Promise<Uint32Array>;
|
|
28
31
|
/**token编码 Davinci模型
|
|
32
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
29
33
|
* @param str = 所要计算的消息
|
|
30
34
|
* @returns Token数组
|
|
31
35
|
*/
|
|
32
36
|
function encodeTokenDavinci(str: string): Promise<Uint32Array>;
|
|
33
37
|
/**token解码 Turbo模型
|
|
38
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
34
39
|
* @param arr = Token数组
|
|
35
40
|
* @returns 消息字符串
|
|
36
41
|
*/
|
|
37
42
|
function decodeTokenTurbo(arr: Uint32Array | number[]): Promise<string>;
|
|
38
43
|
/**token解码 Davinci模型
|
|
44
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
39
45
|
* @param arr = Token数组
|
|
40
46
|
* @returns 消息字符串
|
|
41
47
|
*/
|
package/dist/UtilCodecs.js
CHANGED
|
@@ -26,20 +26,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.UtilCodec = void 0;
|
|
27
27
|
const he = __importStar(require("html-entities"));
|
|
28
28
|
const UtilFunctions_1 = require("./UtilFunctions");
|
|
29
|
+
/**引入tiktoken
|
|
30
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
31
|
+
*/
|
|
29
32
|
async function importTikToken() {
|
|
30
33
|
const tik = await UtilFunctions_1.UtilFunc.dynamicImport("tiktoken");
|
|
31
34
|
if (tik == undefined)
|
|
32
35
|
UtilFunctions_1.UtilFunc.throwError(`npm包 tiktoken 动态导入失败, 此包不会随@zwa73/utils自动安装, 可能是未安装, 可使用 npm i tiktoken@1.0.7 来安装`);
|
|
33
36
|
return tik;
|
|
34
37
|
}
|
|
38
|
+
//#endregion
|
|
35
39
|
/**编码/解码器 */
|
|
36
40
|
var UtilCodec;
|
|
37
41
|
(function (UtilCodec) {
|
|
38
|
-
/**gpt-4, gpt-3.5-turbo, text-embedding-ada-002, text-embedding-3-small, text-embedding-3-large
|
|
39
|
-
*/
|
|
42
|
+
/**gpt-4, gpt-3.5-turbo, text-embedding-ada-002, text-embedding-3-small, text-embedding-3-large */
|
|
40
43
|
let encoderCl100kBase = null;
|
|
41
|
-
/**Codex models, text-davinci-002, text-davinci-003
|
|
42
|
-
*/
|
|
44
|
+
/**Codex models, text-davinci-002, text-davinci-003 */
|
|
43
45
|
let encoderP50kBase = null;
|
|
44
46
|
const textDecoder = new TextDecoder();
|
|
45
47
|
/**HTML实体解码 将一个字符串中的HTML实体转换为对应的字符
|
|
@@ -62,8 +64,10 @@ var UtilCodec;
|
|
|
62
64
|
//token长度计算器
|
|
63
65
|
//cl100k_base ChatGPT models, text-embedding-ada-002
|
|
64
66
|
//p50k_base Code models, text-davinci-002, text-davinci-003
|
|
65
|
-
//r50k_base
|
|
66
|
-
|
|
67
|
+
//r50k_base (or gpt2) GPT-3 models like davinci
|
|
68
|
+
/**避免在nextjs调用时出错
|
|
69
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
70
|
+
*/
|
|
67
71
|
async function initTikTokenEncoder() {
|
|
68
72
|
if (encoderCl100kBase != null && encoderP50kBase != null)
|
|
69
73
|
return;
|
|
@@ -72,6 +76,7 @@ var UtilCodec;
|
|
|
72
76
|
encoderP50kBase = get_encoding("p50k_base");
|
|
73
77
|
}
|
|
74
78
|
/**token长度计算器 Turbo模型
|
|
79
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
75
80
|
* @param str = 所要计算的消息
|
|
76
81
|
* @returns 整数长度结果
|
|
77
82
|
*/
|
|
@@ -82,6 +87,7 @@ var UtilCodec;
|
|
|
82
87
|
}
|
|
83
88
|
UtilCodec.tokenNumTurbo = tokenNumTurbo;
|
|
84
89
|
/**token长度计算器 Davinci模型
|
|
90
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
85
91
|
* @param str = 所要计算的消息
|
|
86
92
|
* @returns 整数长度结果
|
|
87
93
|
*/
|
|
@@ -91,6 +97,7 @@ var UtilCodec;
|
|
|
91
97
|
}
|
|
92
98
|
UtilCodec.tokenNumDavinci = tokenNumDavinci;
|
|
93
99
|
/**token编码 Turbo模型
|
|
100
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
94
101
|
* @param str = 所要计算的消息
|
|
95
102
|
* @returns Token数组
|
|
96
103
|
*/
|
|
@@ -100,6 +107,7 @@ var UtilCodec;
|
|
|
100
107
|
}
|
|
101
108
|
UtilCodec.encodeTokenTurbo = encodeTokenTurbo;
|
|
102
109
|
/**token编码 Davinci模型
|
|
110
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
103
111
|
* @param str = 所要计算的消息
|
|
104
112
|
* @returns Token数组
|
|
105
113
|
*/
|
|
@@ -109,6 +117,7 @@ var UtilCodec;
|
|
|
109
117
|
}
|
|
110
118
|
UtilCodec.encodeTokenDavinci = encodeTokenDavinci;
|
|
111
119
|
/**token解码 Turbo模型
|
|
120
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
112
121
|
* @param arr = Token数组
|
|
113
122
|
* @returns 消息字符串
|
|
114
123
|
*/
|
|
@@ -120,6 +129,7 @@ var UtilCodec;
|
|
|
120
129
|
}
|
|
121
130
|
UtilCodec.decodeTokenTurbo = decodeTokenTurbo;
|
|
122
131
|
/**token解码 Davinci模型
|
|
132
|
+
* 依赖于 tiktoken@1.0.7 但不会自动安装
|
|
123
133
|
* @param arr = Token数组
|
|
124
134
|
* @returns 消息字符串
|
|
125
135
|
*/
|