@adminforth/completion-adapter-open-ai-chat-gpt 2.0.6 → 2.0.7

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/index.js CHANGED
@@ -37,6 +37,7 @@ export default class CompletionAdapterOpenAIChatGPT {
37
37
  };
38
38
  });
39
39
  this.options = options;
40
+ this.encoding = encoding_for_model((this.options.model || "gpt-5-nano"));
40
41
  }
41
42
  validate() {
42
43
  if (!this.options.openAiApiKey) {
@@ -45,9 +46,7 @@ export default class CompletionAdapterOpenAIChatGPT {
45
46
  }
46
47
  measureTokensCount(content) {
47
48
  // Implement token counting logic here
48
- const model = this.options.model || "gpt-5-nano";
49
- const encoding = encoding_for_model(model);
50
- const tokens = encoding.encode(content);
49
+ const tokens = this.encoding.encode(content);
51
50
  return tokens.length;
52
51
  }
53
52
  }
package/index.ts CHANGED
@@ -5,9 +5,13 @@ export default class CompletionAdapterOpenAIChatGPT
5
5
  implements CompletionAdapter
6
6
  {
7
7
  options: AdapterOptions;
8
+ private encoding: ReturnType<typeof encoding_for_model>;
8
9
 
9
10
  constructor(options: AdapterOptions) {
10
11
  this.options = options;
12
+ this.encoding = encoding_for_model(
13
+ (this.options.model || "gpt-5-nano") as TiktokenModel
14
+ );
11
15
  }
12
16
 
13
17
  validate() {
@@ -16,12 +20,9 @@ export default class CompletionAdapterOpenAIChatGPT
16
20
  }
17
21
  }
18
22
 
19
-
20
23
  measureTokensCount(content: string): number {
21
24
  // Implement token counting logic here
22
- const model = this.options.model || "gpt-5-nano";
23
- const encoding = encoding_for_model(model as TiktokenModel);
24
- const tokens = encoding.encode(content);
25
+ const tokens = this.encoding.encode(content);
25
26
  return tokens.length;
26
27
  }
27
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/completion-adapter-open-ai-chat-gpt",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",