@zwa73/utils 1.0.265 → 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.
@@ -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
- * @param context - 上下文对象,用于在渲染模板时提供数据
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 模板字符串
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Hbs = void 0;
4
4
  const UtilLogger_1 = require("../UtilLogger");
5
5
  const js_utils_1 = require("@zwa73/js-utils");
6
+ const UtilFunctions_1 = require("../UtilFunctions");
6
7
  /**文本模板渲染器
7
8
  * @template T - 上下文对象的类型,默认为记录类型
8
9
  */
@@ -30,10 +31,13 @@ class Hbs {
30
31
  });
31
32
  }
32
33
  /**创建一个新的 Hbs 实例
33
- * @param context - 上下文对象,用于在渲染模板时提供数据
34
- */
34
+ * 依赖于 handlebars@4.7.8 但不会自动安装
35
+ * @param context - 上下文对象,用于在渲染模板时提供数据
36
+ */
35
37
  static async create(context = {}) {
36
38
  const Handlebars = await js_utils_1.JsFunc.dynamicImport('handlebars');
39
+ if (Handlebars == undefined)
40
+ UtilFunctions_1.UtilFunc.throwError(`npm包 handlebars 动态导入失败, 此包不会随@zwa73/utils自动安装, 可能是未安装, 可使用 npm i handlebars@4.7.8 来安装`);
37
41
  //console.log(Handlebars);
38
42
  const hbs = Handlebars.create();
39
43
  return new Hbs(hbs, context);
@@ -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
  */
@@ -26,17 +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
- return await UtilFunctions_1.UtilFunc.dynamicImport("tiktoken");
33
+ const tik = await UtilFunctions_1.UtilFunc.dynamicImport("tiktoken");
34
+ if (tik == undefined)
35
+ UtilFunctions_1.UtilFunc.throwError(`npm包 tiktoken 动态导入失败, 此包不会随@zwa73/utils自动安装, 可能是未安装, 可使用 npm i tiktoken@1.0.7 来安装`);
36
+ return tik;
31
37
  }
38
+ //#endregion
32
39
  /**编码/解码器 */
33
40
  var UtilCodec;
34
41
  (function (UtilCodec) {
35
- /**gpt-4, gpt-3.5-turbo, text-embedding-ada-002, text-embedding-3-small, text-embedding-3-large
36
- */
42
+ /**gpt-4, gpt-3.5-turbo, text-embedding-ada-002, text-embedding-3-small, text-embedding-3-large */
37
43
  let encoderCl100kBase = null;
38
- /**Codex models, text-davinci-002, text-davinci-003
39
- */
44
+ /**Codex models, text-davinci-002, text-davinci-003 */
40
45
  let encoderP50kBase = null;
41
46
  const textDecoder = new TextDecoder();
42
47
  /**HTML实体解码 将一个字符串中的HTML实体转换为对应的字符
@@ -57,10 +62,12 @@ var UtilCodec;
57
62
  UtilCodec.encodeHtmlEntities = encodeHtmlEntities;
58
63
  //#region LAM
59
64
  //token长度计算器
60
- //cl100k_base ChatGPT models, text-embedding-ada-002
61
- //p50k_base Code models, text-davinci-002, text-davinci-003
62
- //r50k_base (or gpt2) GPT-3 models like davinci
63
- //避免在nextjs调用时出错
65
+ //cl100k_base ChatGPT models, text-embedding-ada-002
66
+ //p50k_base Code models, text-davinci-002, text-davinci-003
67
+ //r50k_base (or gpt2) GPT-3 models like davinci
68
+ /**避免在nextjs调用时出错
69
+ * 依赖于 tiktoken@1.0.7 但不会自动安装
70
+ */
64
71
  async function initTikTokenEncoder() {
65
72
  if (encoderCl100kBase != null && encoderP50kBase != null)
66
73
  return;
@@ -69,6 +76,7 @@ var UtilCodec;
69
76
  encoderP50kBase = get_encoding("p50k_base");
70
77
  }
71
78
  /**token长度计算器 Turbo模型
79
+ * 依赖于 tiktoken@1.0.7 但不会自动安装
72
80
  * @param str = 所要计算的消息
73
81
  * @returns 整数长度结果
74
82
  */
@@ -79,6 +87,7 @@ var UtilCodec;
79
87
  }
80
88
  UtilCodec.tokenNumTurbo = tokenNumTurbo;
81
89
  /**token长度计算器 Davinci模型
90
+ * 依赖于 tiktoken@1.0.7 但不会自动安装
82
91
  * @param str = 所要计算的消息
83
92
  * @returns 整数长度结果
84
93
  */
@@ -88,6 +97,7 @@ var UtilCodec;
88
97
  }
89
98
  UtilCodec.tokenNumDavinci = tokenNumDavinci;
90
99
  /**token编码 Turbo模型
100
+ * 依赖于 tiktoken@1.0.7 但不会自动安装
91
101
  * @param str = 所要计算的消息
92
102
  * @returns Token数组
93
103
  */
@@ -97,6 +107,7 @@ var UtilCodec;
97
107
  }
98
108
  UtilCodec.encodeTokenTurbo = encodeTokenTurbo;
99
109
  /**token编码 Davinci模型
110
+ * 依赖于 tiktoken@1.0.7 但不会自动安装
100
111
  * @param str = 所要计算的消息
101
112
  * @returns Token数组
102
113
  */
@@ -106,6 +117,7 @@ var UtilCodec;
106
117
  }
107
118
  UtilCodec.encodeTokenDavinci = encodeTokenDavinci;
108
119
  /**token解码 Turbo模型
120
+ * 依赖于 tiktoken@1.0.7 但不会自动安装
109
121
  * @param arr = Token数组
110
122
  * @returns 消息字符串
111
123
  */
@@ -117,6 +129,7 @@ var UtilCodec;
117
129
  }
118
130
  UtilCodec.decodeTokenTurbo = decodeTokenTurbo;
119
131
  /**token解码 Davinci模型
132
+ * 依赖于 tiktoken@1.0.7 但不会自动安装
120
133
  * @param arr = Token数组
121
134
  * @returns 消息字符串
122
135
  */
@@ -124,7 +124,7 @@ class _UtilFunc {
124
124
  //if(_UtilFunc.publicIp===undefined)
125
125
  // _UtilFunc.publicIp = await import("public-ip");
126
126
  if (pip == undefined) {
127
- UtilLogger_1.SLogger.warn(`npm包 public-ip 动态导入失败, 可能是未安装, 可使用 npm i public-ip@6.0.2 来安装`);
127
+ UtilLogger_1.SLogger.warn(`npm包 public-ip 动态导入失败, 此包不会随@zwa73/utils自动安装, 可能是未安装, 可使用 npm i public-ip@6.0.2 来安装`);
128
128
  return undefined;
129
129
  }
130
130
  return pip.publicIpv4();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.265",
3
+ "version": "1.0.267",
4
4
  "description": "my utils",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -20,14 +20,12 @@
20
20
  "@zwa73/modular-mixer": "^1.0.8",
21
21
  "form-data": "^4.0.2",
22
22
  "glob": "^10.4.1",
23
- "handlebars": "^4.7.8",
24
23
  "html-entities": "^2.3.3",
25
24
  "http-proxy-agent": "^5.0.0",
26
25
  "https-proxy-agent": "^5.0.1",
27
26
  "json5": "^2.2.3",
28
27
  "pathe": "^1.1.2",
29
28
  "querystring": "^0.2.1",
30
- "tiktoken": "^1.0.7",
31
29
  "winston": "^3.10.0",
32
30
  "winston-daily-rotate-file": "^4.7.1"
33
31
  },
@@ -36,7 +34,9 @@
36
34
  "@types/jest": "^29.5.12",
37
35
  "@types/node": "^20.14.11",
38
36
  "@zwa73/dev-utils": "*",
37
+ "handlebars": "^4.7.8",
39
38
  "public-ip": "^6.0.2",
39
+ "tiktoken": "^1.0.7",
40
40
  "tsc-alias": "^1.8.8",
41
41
  "typescript": "^5.3.3"
42
42
  },