@adminforth/completion-adapter-open-ai-chat-gpt 2.0.3 → 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 +7 -0
- package/index.ts +11 -1
- package/package.json +4 -1
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) {
|
|
@@ -36,10 +37,16 @@ export default class CompletionAdapterOpenAIChatGPT {
|
|
|
36
37
|
};
|
|
37
38
|
});
|
|
38
39
|
this.options = options;
|
|
40
|
+
this.encoding = encoding_for_model((this.options.model || "gpt-5-nano"));
|
|
39
41
|
}
|
|
40
42
|
validate() {
|
|
41
43
|
if (!this.options.openAiApiKey) {
|
|
42
44
|
throw new Error("openAiApiKey is required");
|
|
43
45
|
}
|
|
44
46
|
}
|
|
47
|
+
measureTokensCount(content) {
|
|
48
|
+
// Implement token counting logic here
|
|
49
|
+
const tokens = this.encoding.encode(content);
|
|
50
|
+
return tokens.length;
|
|
51
|
+
}
|
|
45
52
|
}
|
package/index.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
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
|
{
|
|
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,6 +20,12 @@ export default class CompletionAdapterOpenAIChatGPT
|
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
22
|
|
|
23
|
+
measureTokensCount(content: string): number {
|
|
24
|
+
// Implement token counting logic here
|
|
25
|
+
const tokens = this.encoding.encode(content);
|
|
26
|
+
return tokens.length;
|
|
27
|
+
}
|
|
28
|
+
|
|
19
29
|
complete = async (content: string, stop = ["."], maxTokens = 50, outputSchema?: any): Promise<{
|
|
20
30
|
content?: string;
|
|
21
31
|
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
|
+
"version": "2.0.7",
|
|
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
|
}
|