@adminforth/text-complete 1.0.21
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/custom/completionInput.vue +59 -0
- package/custom/package-lock.json +368 -0
- package/custom/package.json +15 -0
- package/dist/custom/completionInput.vue +59 -0
- package/dist/custom/package-lock.json +368 -0
- package/dist/custom/package.json +15 -0
- package/dist/index.js +141 -0
- package/dist/types.js +1 -0
- package/index.ts +174 -0
- package/package.json +16 -0
- package/tsconfig.json +112 -0
- package/types.ts +82 -0
package/index.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
|
|
2
|
+
import { IAdminForth, IHttpServer, AdminForthPlugin, AdminForthResource, AdminForthDataTypes, RateLimiter } from "adminforth";
|
|
3
|
+
import { PluginOptions } from './types.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export default class TextCompletePlugin extends AdminForthPlugin {
|
|
7
|
+
options: PluginOptions;
|
|
8
|
+
|
|
9
|
+
resourceConfig!: AdminForthResource;
|
|
10
|
+
|
|
11
|
+
columnType!: AdminForthDataTypes;
|
|
12
|
+
|
|
13
|
+
adminforth!: IAdminForth;
|
|
14
|
+
|
|
15
|
+
constructor(options: PluginOptions) {
|
|
16
|
+
super(options, import.meta.url);
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
instanceUniqueRepresentation(pluginOptions: any) : string {
|
|
21
|
+
return `${pluginOptions.fieldName}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
26
|
+
this.adminforth = adminforth;
|
|
27
|
+
const column = this.resourceConfig.columns.find(f => f.name === this.options.fieldName);
|
|
28
|
+
if (![AdminForthDataTypes.STRING, AdminForthDataTypes.TEXT].includes(column!.type!)) {
|
|
29
|
+
throw new Error(`Field ${this.options.fieldName} should be string or text type, but it is ${column!.type}`);
|
|
30
|
+
}
|
|
31
|
+
if (!this.options.adapter) {
|
|
32
|
+
throw new Error('adapter is required');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
generateRecordContext(record: any, maxFields: number, inputFieldLimit: number, partsCount: number): string {
|
|
37
|
+
// stringify each field
|
|
38
|
+
let fields: [string, string][] = Object.entries(record).map(([key, value]) => {
|
|
39
|
+
return [key, JSON.stringify(value)];
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// sort fields by length, higher first
|
|
43
|
+
fields = fields.sort((a, b) => b[1].length - a[1].length);
|
|
44
|
+
|
|
45
|
+
// select longest maxFields fields
|
|
46
|
+
fields = fields.slice(0, maxFields);
|
|
47
|
+
|
|
48
|
+
const minLimit = '...'.length * partsCount;
|
|
49
|
+
|
|
50
|
+
if (inputFieldLimit < minLimit) {
|
|
51
|
+
throw new Error(`inputFieldLimit should be at least ${minLimit}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// for each field, if it is longer than inputFieldLimit, truncate it using next way:
|
|
55
|
+
// split into 5 parts, divide inputFieldLimit by 5, crop each part to this length, join parts using '...'
|
|
56
|
+
fields = fields.map(([key, value]) => {
|
|
57
|
+
if (value.length > inputFieldLimit) {
|
|
58
|
+
const partLength = Math.floor(inputFieldLimit / partsCount) - '...'.length;
|
|
59
|
+
const parts = [];
|
|
60
|
+
for (let i = 0; i < partsCount; i++) {
|
|
61
|
+
parts.push(value.slice(i * partLength, (i + 1) * partLength));
|
|
62
|
+
}
|
|
63
|
+
value = parts.join('...');
|
|
64
|
+
return [key, value];
|
|
65
|
+
}
|
|
66
|
+
return [key, value];
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return JSON.stringify(Object.fromEntries(fields));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setupEndpoints(server: IHttpServer) {
|
|
73
|
+
server.endpoint({
|
|
74
|
+
method: 'POST',
|
|
75
|
+
path: `/plugin/${this.pluginInstanceId}/doComplete`,
|
|
76
|
+
handler: async ({ body, headers }) => {
|
|
77
|
+
if (this.options.rateLimit?.limit) {
|
|
78
|
+
// rate limit
|
|
79
|
+
const { error } = RateLimiter.checkRateLimit(
|
|
80
|
+
this.pluginInstanceId,
|
|
81
|
+
this.options.rateLimit?.limit,
|
|
82
|
+
this.adminforth.auth.getClientIp(headers),
|
|
83
|
+
);
|
|
84
|
+
if (error) {
|
|
85
|
+
return {
|
|
86
|
+
completion: [],
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const { record } = body;
|
|
92
|
+
const recordNoField = {...record};
|
|
93
|
+
delete recordNoField[this.options.fieldName];
|
|
94
|
+
let currentVal = record[this.options.fieldName];
|
|
95
|
+
const promptLimit = this.options.expert?.promptInputLimit || 500;
|
|
96
|
+
const inputContext = this.generateRecordContext(
|
|
97
|
+
recordNoField,
|
|
98
|
+
this.options.expert?.recordContext?.maxFields || 5,
|
|
99
|
+
this.options.expert?.recordContext?.maxFieldLength || 300,
|
|
100
|
+
this.options.expert?.recordContext?.splitParts || 5,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (currentVal && currentVal.length > promptLimit) {
|
|
104
|
+
currentVal = currentVal.slice(-promptLimit);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const resLabel = this.resourceConfig.label;
|
|
108
|
+
|
|
109
|
+
let content;
|
|
110
|
+
|
|
111
|
+
if (currentVal) {
|
|
112
|
+
content = `Continue writing for text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
|
|
113
|
+
(Object.keys(recordNoField).length > 0 ? `Record has values for the context: ${inputContext}\n` : '') +
|
|
114
|
+
`Current field value: ${currentVal}\n` +
|
|
115
|
+
"Don't talk to me. Just write text. No quotes. Don't repeat current field value, just write completion\n";
|
|
116
|
+
|
|
117
|
+
} else {
|
|
118
|
+
content = `Fill text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
|
|
119
|
+
(Object.keys(recordNoField).length > 0 ? `Record has values for the context: ${inputContext}\n` : '') +
|
|
120
|
+
"Be short, clear and precise. No quotes. Don't talk to me. Just write text\n";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
process.env.HEAVY_DEBUG && console.log('🪲 OpenAI Prompt 🧠', content);
|
|
124
|
+
const { content: respContent, finishReason } = await this.options.adapter.complete(content, this.options.expert?.stop, this.options.expert?.maxTokens);
|
|
125
|
+
const stop = this.options.expert?.stop || ['.'];
|
|
126
|
+
let suggestion = respContent + (
|
|
127
|
+
finishReason === 'stop' ? (
|
|
128
|
+
stop[0] === '.' && stop.length === 1 && this.columnType === AdminForthDataTypes.TEXT ? '. ' : ''
|
|
129
|
+
) : ''
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
if (suggestion.startsWith(currentVal)) {
|
|
133
|
+
suggestion = suggestion.slice(currentVal.length);
|
|
134
|
+
}
|
|
135
|
+
const wordsList = suggestion.split(' ').map((w, i) => {
|
|
136
|
+
return (i === suggestion.split(' ').length - 1) ? w : w + ' ';
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// remove quotes from start and end
|
|
140
|
+
return {
|
|
141
|
+
completion: wordsList
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
148
|
+
super.modifyResourceConfig(adminforth, resourceConfig);
|
|
149
|
+
this.resourceConfig = resourceConfig;
|
|
150
|
+
|
|
151
|
+
// ensure that column exists
|
|
152
|
+
const column = this.resourceConfig.columns.find(f => f.name === this.options.fieldName);
|
|
153
|
+
if (!column) {
|
|
154
|
+
throw new Error(`Field ${this.options.fieldName} not found in resource ${this.resourceConfig.label}`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!column.components) {
|
|
158
|
+
column.components = {};
|
|
159
|
+
}
|
|
160
|
+
const filed = {
|
|
161
|
+
file: this.componentPath('completionInput.vue'),
|
|
162
|
+
meta: {
|
|
163
|
+
pluginInstanceId: this.pluginInstanceId,
|
|
164
|
+
fieldName: this.options.fieldName,
|
|
165
|
+
debounceTime: this.options.expert?.debounceTime || 300,
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
column.components.create = filed;
|
|
169
|
+
column.components.edit = filed;
|
|
170
|
+
|
|
171
|
+
this.columnType = column.type!;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adminforth/text-complete",
|
|
3
|
+
"version": "1.0.21",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"rollout": "tsc && rsync -av --exclude 'node_modules' custom dist/ && npm version patch && npm publish --access public",
|
|
11
|
+
"prepare": "npm link adminforth"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC"
|
|
16
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/* Language and Environment */
|
|
15
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
16
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
17
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
18
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
19
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
21
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
22
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
25
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
26
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
+
|
|
28
|
+
/* Modules */
|
|
29
|
+
// changed from commmonjs to node16 because The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.
|
|
30
|
+
"module": "node16", /* Specify what module code is generated. */
|
|
31
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
32
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
33
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
34
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
35
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
36
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
37
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
38
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
39
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
40
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
41
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
42
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
43
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
44
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
45
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
46
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
47
|
+
|
|
48
|
+
/* JavaScript Support */
|
|
49
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
50
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
51
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
52
|
+
|
|
53
|
+
/* Emit */
|
|
54
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
55
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
56
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
57
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
58
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
59
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
60
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
61
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
62
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
63
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
64
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
65
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
66
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
67
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
68
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
69
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
70
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
71
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
72
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
73
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
74
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
75
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
76
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
77
|
+
|
|
78
|
+
/* Interop Constraints */
|
|
79
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
80
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
81
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
82
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
83
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
84
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
85
|
+
|
|
86
|
+
/* Type Checking */
|
|
87
|
+
"strict": false, /* TODO */ /* Enable all strict type-checking options. */
|
|
88
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
89
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
90
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
91
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
92
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
93
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
94
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
95
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
96
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
97
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
98
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
99
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
100
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
101
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
102
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
103
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
104
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
105
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
106
|
+
|
|
107
|
+
/* Completeness */
|
|
108
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
109
|
+
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
|
|
110
|
+
},
|
|
111
|
+
"exclude": ["node_modules", "dist", "custom"], /* Exclude files from compilation. */
|
|
112
|
+
}
|
package/types.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { CompletionAdapter } from "adminforth";
|
|
2
|
+
|
|
3
|
+
export interface PluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Field where plugin will auto-complete text. Should be string or text field.
|
|
6
|
+
*/
|
|
7
|
+
fieldName: string;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Expert settings
|
|
11
|
+
*/
|
|
12
|
+
expert?: {
|
|
13
|
+
/**
|
|
14
|
+
* Maximum number of last characters which will be used for completion for target field. Default is 500.
|
|
15
|
+
* Higher value will give better context but will cost more.
|
|
16
|
+
*/
|
|
17
|
+
promptInputLimit?: number;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Debounce time in ms. Default is 300. Time after user stopped typing before request will be sent.
|
|
21
|
+
*/
|
|
22
|
+
debounceTime?: number;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* When completion is made, this plugin passes non-empty fields of the record to the LLM model for record context understanding.
|
|
26
|
+
*/
|
|
27
|
+
recordContext?: {
|
|
28
|
+
/**
|
|
29
|
+
* Using this field you can limit number of fields passed to the model.
|
|
30
|
+
* Default is 5.
|
|
31
|
+
* Completion field is not included in this limit.
|
|
32
|
+
* Set to 0 to disable context passing at all.
|
|
33
|
+
* If count of fields exceeds this number, longest fields will be selected.
|
|
34
|
+
* If some of values will exceed maxFieldLength, it will be smartly truncated by splitting ito splitParts, taking their
|
|
35
|
+
* starting substring and joining back with '...'.
|
|
36
|
+
*/
|
|
37
|
+
maxFields?: number;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Limit of input field value. Default is 300. If field is longer, it will be truncated.
|
|
41
|
+
*/
|
|
42
|
+
maxFieldLength?: number;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* How many parts to split field value if it exceeds maxFieldLength. Default is 5.
|
|
46
|
+
*/
|
|
47
|
+
splitParts?: number;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Number of tokens to generate. Default is 50. 1 token ~= ¾ words
|
|
52
|
+
*/
|
|
53
|
+
maxTokens?: number;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Stop tokens. Default is ['.']
|
|
57
|
+
*/
|
|
58
|
+
stop?: string[];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Since AI generation can be expensive, we can limit the number of requests per IP.
|
|
63
|
+
* Completion will simply stop working when limit is reached so user will not be bothered with error messages.
|
|
64
|
+
*/
|
|
65
|
+
rateLimit?: {
|
|
66
|
+
/**
|
|
67
|
+
* E.g. 5/1d - 5 requests per day
|
|
68
|
+
* 3/1h - 3 requests per hour
|
|
69
|
+
*/
|
|
70
|
+
limit: string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Message shown to user when rate limit is reached
|
|
74
|
+
*/
|
|
75
|
+
errorMessage: string;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Adapter for completion
|
|
80
|
+
*/
|
|
81
|
+
adapter: CompletionAdapter;
|
|
82
|
+
}
|