@adminforth/text-complete 1.8.4 → 1.8.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/build.log +2 -2
- package/custom/tsconfig.json +15 -7
- package/dist/custom/tsconfig.json +15 -7
- package/dist/index.js +12 -9
- package/index.ts +7 -3
- package/package.json +1 -1
package/build.log
CHANGED
|
@@ -9,5 +9,5 @@ custom/package-lock.json
|
|
|
9
9
|
custom/package.json
|
|
10
10
|
custom/tsconfig.json
|
|
11
11
|
|
|
12
|
-
sent 22,
|
|
13
|
-
total size is 21,
|
|
12
|
+
sent 22,344 bytes received 96 bytes 44,880.00 bytes/sec
|
|
13
|
+
total size is 21,986 speedup is 0.98
|
package/custom/tsconfig.json
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"baseUrl": ".",
|
|
3
|
+
"baseUrl": ".",
|
|
4
4
|
"paths": {
|
|
5
5
|
"@/*": [
|
|
6
|
-
|
|
7
|
-
"../../../spa/src/*"
|
|
6
|
+
"../../../adminforth/spa/src/*"
|
|
8
7
|
],
|
|
9
8
|
"*": [
|
|
10
|
-
|
|
11
|
-
"../../../spa/node_modules/*"
|
|
9
|
+
"../../../adminforth/spa/node_modules/*"
|
|
12
10
|
],
|
|
13
11
|
"@@/*": [
|
|
14
|
-
// "node_modules/adminforth/dist/spa/src/*"
|
|
15
12
|
"."
|
|
16
13
|
]
|
|
17
14
|
}
|
|
18
|
-
}
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"./**/*.ts",
|
|
18
|
+
"./**/*.tsx",
|
|
19
|
+
"./**/*.vue",
|
|
20
|
+
"../**/*.ts",
|
|
21
|
+
"../**/*.tsx",
|
|
22
|
+
"../**/*.vue",
|
|
23
|
+
"../*.vue",
|
|
24
|
+
"../*.ts",
|
|
25
|
+
"../*.tsx"
|
|
26
|
+
]
|
|
19
27
|
}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"baseUrl": ".",
|
|
3
|
+
"baseUrl": ".",
|
|
4
4
|
"paths": {
|
|
5
5
|
"@/*": [
|
|
6
|
-
|
|
7
|
-
"../../../spa/src/*"
|
|
6
|
+
"../../../adminforth/spa/src/*"
|
|
8
7
|
],
|
|
9
8
|
"*": [
|
|
10
|
-
|
|
11
|
-
"../../../spa/node_modules/*"
|
|
9
|
+
"../../../adminforth/spa/node_modules/*"
|
|
12
10
|
],
|
|
13
11
|
"@@/*": [
|
|
14
|
-
// "node_modules/adminforth/dist/spa/src/*"
|
|
15
12
|
"."
|
|
16
13
|
]
|
|
17
14
|
}
|
|
18
|
-
}
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"./**/*.ts",
|
|
18
|
+
"./**/*.tsx",
|
|
19
|
+
"./**/*.vue",
|
|
20
|
+
"../**/*.ts",
|
|
21
|
+
"../**/*.tsx",
|
|
22
|
+
"../**/*.vue",
|
|
23
|
+
"../*.vue",
|
|
24
|
+
"../*.ts",
|
|
25
|
+
"../*.tsx"
|
|
26
|
+
]
|
|
19
27
|
}
|
package/dist/index.js
CHANGED
|
@@ -10,8 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { AdminForthPlugin, AdminForthDataTypes, RateLimiter } from "adminforth";
|
|
11
11
|
export default class TextCompletePlugin extends AdminForthPlugin {
|
|
12
12
|
constructor(options) {
|
|
13
|
+
var _a, _b;
|
|
13
14
|
super(options, import.meta.url);
|
|
14
15
|
this.options = options;
|
|
16
|
+
if ((_a = options.rateLimit) === null || _a === void 0 ? void 0 : _a.limit) {
|
|
17
|
+
this.rateLimiter = new RateLimiter((_b = options.rateLimit) === null || _b === void 0 ? void 0 : _b.limit);
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
instanceUniqueRepresentation(pluginOptions) {
|
|
17
21
|
return `${pluginOptions.fieldName}`;
|
|
@@ -63,16 +67,15 @@ export default class TextCompletePlugin extends AdminForthPlugin {
|
|
|
63
67
|
method: 'POST',
|
|
64
68
|
path: `/plugin/${this.pluginInstanceId}/doComplete`,
|
|
65
69
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers }) {
|
|
66
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o
|
|
67
|
-
if (
|
|
70
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
71
|
+
if (this.rateLimiter) {
|
|
68
72
|
// rate limit
|
|
69
73
|
// const { error } = RateLimiter.checkRateLimit(
|
|
70
74
|
// this.pluginInstanceId,
|
|
71
75
|
// this.options.rateLimit?.limit,
|
|
72
76
|
// this.adminforth.auth.getClientIp(headers),
|
|
73
77
|
// );
|
|
74
|
-
|
|
75
|
-
if (!rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`)) {
|
|
78
|
+
if (!(yield this.rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`))) {
|
|
76
79
|
return {
|
|
77
80
|
completion: [],
|
|
78
81
|
};
|
|
@@ -82,12 +85,12 @@ export default class TextCompletePlugin extends AdminForthPlugin {
|
|
|
82
85
|
const recordNoField = Object.assign({}, record);
|
|
83
86
|
delete recordNoField[this.options.fieldName];
|
|
84
87
|
let currentVal = record[this.options.fieldName];
|
|
85
|
-
const promptLimit = ((
|
|
86
|
-
const inputContext = this.generateRecordContext(recordNoField, ((
|
|
88
|
+
const promptLimit = ((_b = this.options.expert) === null || _b === void 0 ? void 0 : _b.promptInputLimit) || 500;
|
|
89
|
+
const inputContext = this.generateRecordContext(recordNoField, ((_d = (_c = this.options.expert) === null || _c === void 0 ? void 0 : _c.recordContext) === null || _d === void 0 ? void 0 : _d.maxFields) || 5, ((_f = (_e = this.options.expert) === null || _e === void 0 ? void 0 : _e.recordContext) === null || _f === void 0 ? void 0 : _f.maxFieldLength) || 300, ((_h = (_g = this.options.expert) === null || _g === void 0 ? void 0 : _g.recordContext) === null || _h === void 0 ? void 0 : _h.splitParts) || 5);
|
|
87
90
|
if (currentVal && currentVal.length > promptLimit) {
|
|
88
91
|
currentVal = currentVal.slice(-promptLimit);
|
|
89
92
|
}
|
|
90
|
-
const fieldLabel = ((
|
|
93
|
+
const fieldLabel = ((_k = (_j = this.resourceConfig) === null || _j === void 0 ? void 0 : _j.columns.find(c => c.name === this.options.fieldName)) === null || _k === void 0 ? void 0 : _k.label) || this.options.fieldName;
|
|
91
94
|
const resLabel = this.resourceConfig.label;
|
|
92
95
|
let content;
|
|
93
96
|
if (currentVal) {
|
|
@@ -117,8 +120,8 @@ export default class TextCompletePlugin extends AdminForthPlugin {
|
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
process.env.HEAVY_DEBUG && console.log('🪲 OpenAI Prompt 🧠', content);
|
|
120
|
-
const { content: respContent, finishReason } = yield this.options.adapter.complete(content, (
|
|
121
|
-
const stop = ((
|
|
123
|
+
const { content: respContent, finishReason } = yield this.options.adapter.complete(content, (_l = this.options.expert) === null || _l === void 0 ? void 0 : _l.stop, (_m = this.options.expert) === null || _m === void 0 ? void 0 : _m.maxTokens);
|
|
124
|
+
const stop = ((_o = this.options.expert) === null || _o === void 0 ? void 0 : _o.stop) || ['.'];
|
|
122
125
|
let suggestion = respContent + (finishReason === 'stop' ? (stop[0] === '.' && stop.length === 1 && this.columnType === AdminForthDataTypes.TEXT ? '. ' : '') : '');
|
|
123
126
|
if (suggestion.startsWith(currentVal)) {
|
|
124
127
|
suggestion = suggestion.slice(currentVal.length);
|
package/index.ts
CHANGED
|
@@ -12,9 +12,14 @@ export default class TextCompletePlugin extends AdminForthPlugin {
|
|
|
12
12
|
|
|
13
13
|
adminforth!: IAdminForth;
|
|
14
14
|
|
|
15
|
+
rateLimiter?: RateLimiter;
|
|
16
|
+
|
|
15
17
|
constructor(options: PluginOptions) {
|
|
16
18
|
super(options, import.meta.url);
|
|
17
19
|
this.options = options;
|
|
20
|
+
if (options.rateLimit?.limit) {
|
|
21
|
+
this.rateLimiter = new RateLimiter(options.rateLimit?.limit);
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
instanceUniqueRepresentation(pluginOptions: any) : string {
|
|
@@ -78,15 +83,14 @@ export default class TextCompletePlugin extends AdminForthPlugin {
|
|
|
78
83
|
method: 'POST',
|
|
79
84
|
path: `/plugin/${this.pluginInstanceId}/doComplete`,
|
|
80
85
|
handler: async ({ body, headers }) => {
|
|
81
|
-
if (this.
|
|
86
|
+
if (this.rateLimiter) {
|
|
82
87
|
// rate limit
|
|
83
88
|
// const { error } = RateLimiter.checkRateLimit(
|
|
84
89
|
// this.pluginInstanceId,
|
|
85
90
|
// this.options.rateLimit?.limit,
|
|
86
91
|
// this.adminforth.auth.getClientIp(headers),
|
|
87
92
|
// );
|
|
88
|
-
|
|
89
|
-
if (!rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`)) {
|
|
93
|
+
if (!await this.rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`)) {
|
|
90
94
|
return {
|
|
91
95
|
completion: [],
|
|
92
96
|
}
|