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

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
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { encoding_for_model } from "tiktoken";
10
11
  export default class CompletionAdapterOpenAIChatGPT {
11
12
  constructor(options) {
12
13
  this.complete = (content_1, ...args_1) => __awaiter(this, [content_1, ...args_1], void 0, function* (content, stop = ["."], maxTokens = 50, outputSchema) {
@@ -42,4 +43,11 @@ export default class CompletionAdapterOpenAIChatGPT {
42
43
  throw new Error("openAiApiKey is required");
43
44
  }
44
45
  }
46
+ measureTokensCount(content) {
47
+ // 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);
51
+ return tokens.length;
52
+ }
45
53
  }
package/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { AdapterOptions } from "./types.js";
2
2
  import type { CompletionAdapter } from "adminforth";
3
-
3
+ import { encoding_for_model, type TiktokenModel } from "tiktoken";
4
4
  export default class CompletionAdapterOpenAIChatGPT
5
5
  implements CompletionAdapter
6
6
  {
@@ -16,6 +16,15 @@ export default class CompletionAdapterOpenAIChatGPT
16
16
  }
17
17
  }
18
18
 
19
+
20
+ measureTokensCount(content: string): number {
21
+ // 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
+ return tokens.length;
26
+ }
27
+
19
28
  complete = async (content: string, stop = ["."], maxTokens = 50, outputSchema?: any): Promise<{
20
29
  content?: string;
21
30
  finishReason?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/completion-adapter-open-ai-chat-gpt",
3
- "version": "2.0.3",
3
+ "version": "2.0.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -15,5 +15,8 @@
15
15
  "description": "",
16
16
  "devDependencies": {
17
17
  "typescript": "^5.9.3"
18
+ },
19
+ "dependencies": {
20
+ "tiktoken": "^1.0.22"
18
21
  }
19
22
  }