@rxap/plugin-gpt 16.0.1-dev.3 → 16.0.1-dev.4
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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/package.json +11 -11
- package/src/generators/documentation/generator.js +127 -110
- package/src/generators/documentation/generator.js.map +1 -1
- package/src/generators/documentation/index.js +6 -4
- package/src/generators/documentation/index.js.map +1 -1
- package/src/generators/documentation/simple-prompt.js +51 -50
- package/src/generators/documentation/simple-prompt.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [16.0.1-dev.4](https://gitlab.com/rxap/packages/compare/@rxap/plugin-gpt@16.0.1-dev.3...@rxap/plugin-gpt@16.0.1-dev.4) (2023-08-17)
|
|
7
|
+
|
|
8
|
+
### Reverts
|
|
9
|
+
|
|
10
|
+
- change from commonjs to es2022 ([747a381](https://gitlab.com/rxap/packages/commit/747a381a090f0a276cf363da61bb19ed0c9cb5b7))
|
|
11
|
+
|
|
6
12
|
## [16.0.1-dev.3](https://gitlab.com/rxap/packages/compare/@rxap/plugin-gpt@16.0.1-dev.2...@rxap/plugin-gpt@16.0.1-dev.3) (2023-08-16)
|
|
7
13
|
|
|
8
14
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ yarn add @rxap/plugin-gpt
|
|
|
18
18
|
```
|
|
19
19
|
**Install peer dependencies:**
|
|
20
20
|
```bash
|
|
21
|
-
yarn add @nx/devkit@^16.5.0 @rxap/generator-ts-morph@^1.0.1-dev.
|
|
21
|
+
yarn add @nx/devkit@^16.5.0 @rxap/generator-ts-morph@^1.0.1-dev.4 @rxap/generator-utilities@^1.1.0-dev.5 gpt-3-encoder@^1.1.4 openai@^3.3.0 ts-morph@^18.0.0
|
|
22
22
|
```
|
|
23
23
|
# Generators
|
|
24
24
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxap/plugin-gpt",
|
|
3
|
-
"version": "16.0.1-dev.
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "16.0.1-dev.4",
|
|
4
|
+
"type": "commonjs",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"directory": "../../../dist/packages/plugin/gpt"
|
|
@@ -39,30 +39,30 @@
|
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@nx/devkit": "^16.5.0",
|
|
42
|
-
"@rxap/generator-ts-morph": "^1.0.1-dev.
|
|
43
|
-
"@rxap/generator-utilities": "^1.1.0-dev.
|
|
42
|
+
"@rxap/generator-ts-morph": "^1.0.1-dev.4",
|
|
43
|
+
"@rxap/generator-utilities": "^1.1.0-dev.5",
|
|
44
44
|
"gpt-3-encoder": "^1.1.4",
|
|
45
45
|
"openai": "^3.3.0",
|
|
46
46
|
"ts-morph": "^18.0.0",
|
|
47
|
-
"@rxap/node-utilities": "1.1.0-dev.
|
|
48
|
-
"@rxap/utilities": "16.0.0-dev.
|
|
49
|
-
"@rxap/workspace-ts-morph": "0.1.0-dev.
|
|
50
|
-
"@rxap/workspace-utilities": "0.1.0-dev.
|
|
47
|
+
"@rxap/node-utilities": "1.1.0-dev.3",
|
|
48
|
+
"@rxap/utilities": "16.0.0-dev.11",
|
|
49
|
+
"@rxap/workspace-ts-morph": "0.1.0-dev.2",
|
|
50
|
+
"@rxap/workspace-utilities": "0.1.0-dev.5"
|
|
51
51
|
},
|
|
52
52
|
"nx-migrations": {
|
|
53
53
|
"packageGroup": [
|
|
54
54
|
{
|
|
55
55
|
"package": "@rxap/generator-ts-morph",
|
|
56
|
-
"version": "1.0.1-dev.
|
|
56
|
+
"version": "1.0.1-dev.4"
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
"package": "@rxap/generator-utilities",
|
|
60
|
-
"version": "1.1.0-dev.
|
|
60
|
+
"version": "1.1.0-dev.5"
|
|
61
61
|
}
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
64
|
"schematics": "./generators.json",
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "bdda345932cb56c4034526de42761d15700fc56d",
|
|
66
66
|
"main": "./src/index.js",
|
|
67
67
|
"types": "./src/index.d.ts"
|
|
68
68
|
}
|
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.documentationGenerator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const ts_morph_1 = require("ts-morph");
|
|
7
|
+
const generator_ts_morph_1 = require("@rxap/generator-ts-morph");
|
|
8
|
+
const generator_utilities_1 = require("@rxap/generator-utilities");
|
|
9
|
+
const process = require("process");
|
|
10
|
+
const openai_1 = require("openai");
|
|
11
|
+
const simple_prompt_1 = require("./simple-prompt");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const fs_1 = require("fs");
|
|
10
14
|
function getOpenAi(param = {}) {
|
|
11
|
-
const configuration = new Configuration({
|
|
12
|
-
|
|
13
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
14
|
-
});
|
|
15
|
-
return new OpenAIApi(configuration);
|
|
15
|
+
const configuration = new openai_1.Configuration(Object.assign(Object.assign({}, param), { apiKey: process.env.OPENAI_API_KEY }));
|
|
16
|
+
return new openai_1.OpenAIApi(configuration);
|
|
16
17
|
}
|
|
17
18
|
function loadSystemPrompt(name) {
|
|
18
|
-
const filePath = join(__dirname, 'system-prompts', `${name}.txt`);
|
|
19
|
-
if (!existsSync(filePath)) {
|
|
19
|
+
const filePath = (0, path_1.join)(__dirname, 'system-prompts', `${name}.txt`);
|
|
20
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
20
21
|
throw new Error(`Can not find system prompt file '${filePath}'`);
|
|
21
22
|
}
|
|
22
|
-
return readFileSync(filePath).toString();
|
|
23
|
+
return (0, fs_1.readFileSync)(filePath).toString();
|
|
23
24
|
}
|
|
24
25
|
const FUNCTION_SYSTEM_PROMPT = loadSystemPrompt('function');
|
|
25
26
|
const METHOD_SYSTEM_PROMPT = loadSystemPrompt('method');
|
|
@@ -27,11 +28,13 @@ const CLASS_SYSTEM_PROMPT = loadSystemPrompt('class');
|
|
|
27
28
|
function hasJsDoc(node) {
|
|
28
29
|
return node.getJsDocs().length > 0;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
function prompt(options, systemPrompt, prompt) {
|
|
32
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
if (options.offline) {
|
|
34
|
+
return '';
|
|
35
|
+
}
|
|
36
|
+
return (0, simple_prompt_1.SimplePrompt)(systemPrompt, prompt, getOpenAi());
|
|
37
|
+
});
|
|
35
38
|
}
|
|
36
39
|
function cleanupJsDoc(jsDoc) {
|
|
37
40
|
const cleanJsDocArray = jsDoc
|
|
@@ -51,60 +54,68 @@ function addJsDoc(options, node, jsDoc) {
|
|
|
51
54
|
}
|
|
52
55
|
node.addJsDoc(cleanupJsDoc(jsDoc));
|
|
53
56
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
function processMethod(options, project, sourceFile, methodDeclaration) {
|
|
58
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
console.log(`====== Process method: \x1b[36m${methodDeclaration.getName()}\x1b[0m`);
|
|
60
|
+
if (hasJsDoc(methodDeclaration)) {
|
|
61
|
+
console.log(`\x1b[33mMethod has already a documentation\x1b[0m`);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const methodText = methodDeclaration.getText();
|
|
65
|
+
console.log('Method text:');
|
|
66
|
+
console.log(methodText);
|
|
67
|
+
const jsDoc = yield prompt(options, METHOD_SYSTEM_PROMPT, methodText);
|
|
68
|
+
console.log('Method documentation:');
|
|
69
|
+
console.log(jsDoc);
|
|
70
|
+
addJsDoc(options, methodDeclaration, jsDoc);
|
|
71
|
+
return true;
|
|
72
|
+
});
|
|
68
73
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
function processClass(options, project, sourceFile, classDeclaration) {
|
|
75
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
console.log(`====== Process class: \x1b[36m${classDeclaration.getName()}\x1b[0m`);
|
|
77
|
+
let changed = false;
|
|
78
|
+
for (const md of classDeclaration.getMethods()) {
|
|
79
|
+
const scope = md.getScope();
|
|
80
|
+
if (scope === 'public' || scope === undefined) {
|
|
81
|
+
const hasChanged = yield processMethod(options, project, sourceFile, md);
|
|
82
|
+
changed = changed || hasChanged;
|
|
83
|
+
}
|
|
77
84
|
}
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
return changed;
|
|
86
|
+
});
|
|
80
87
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
function processFunction(options, project, sourceFile, functionDeclaration) {
|
|
89
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
console.log(`====== Process function: \x1b[36m${functionDeclaration.getName()}\x1b[0m`);
|
|
91
|
+
if (hasJsDoc(functionDeclaration)) {
|
|
92
|
+
console.log(`\x1b[33mFunction has already a documentation\x1b[0m`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
const functionText = functionDeclaration.getText();
|
|
96
|
+
console.log('Function text:');
|
|
97
|
+
console.log(functionText);
|
|
98
|
+
const jsDoc = yield prompt(options, FUNCTION_SYSTEM_PROMPT, functionText);
|
|
99
|
+
console.log('Function documentation:');
|
|
100
|
+
console.log(jsDoc);
|
|
101
|
+
addJsDoc(options, functionDeclaration, jsDoc);
|
|
102
|
+
return true;
|
|
103
|
+
});
|
|
95
104
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
function processSourceFile(options, project, sourceFile) {
|
|
106
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
console.log(`====== Process source file: \x1b[35m${sourceFile.getFilePath()}\x1b[0m`);
|
|
108
|
+
let changed = false;
|
|
109
|
+
for (const fd of sourceFile.getFunctions()) {
|
|
110
|
+
const hasChanged = yield processFunction(options, project, sourceFile, fd);
|
|
111
|
+
changed = changed || hasChanged;
|
|
112
|
+
}
|
|
113
|
+
for (const cd of sourceFile.getClasses()) {
|
|
114
|
+
const hasChanged = yield processClass(options, project, sourceFile, cd);
|
|
115
|
+
changed = changed || hasChanged;
|
|
116
|
+
}
|
|
117
|
+
return changed;
|
|
118
|
+
});
|
|
108
119
|
}
|
|
109
120
|
function skipSourceFile(sourceFile) {
|
|
110
121
|
if (sourceFile.getBaseName() === 'index.ts') {
|
|
@@ -125,53 +136,59 @@ function skipSourceFile(sourceFile) {
|
|
|
125
136
|
}
|
|
126
137
|
return false;
|
|
127
138
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
139
|
+
function processProject(options, projectName, tree) {
|
|
140
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
const projectSourceRoot = (0, generator_utilities_1.GetProjectSourceRoot)(tree, projectName);
|
|
142
|
+
const project = new ts_morph_1.Project({
|
|
143
|
+
manipulationSettings: {
|
|
144
|
+
indentationText: ts_morph_1.IndentationText.TwoSpaces,
|
|
145
|
+
quoteKind: ts_morph_1.QuoteKind.Single,
|
|
146
|
+
},
|
|
147
|
+
useInMemoryFileSystem: true,
|
|
148
|
+
});
|
|
149
|
+
(0, generator_ts_morph_1.AddDir)(tree, projectSourceRoot, project);
|
|
150
|
+
const start = Date.now();
|
|
151
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
152
|
+
if (skipSourceFile(sourceFile)) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const changed = yield processSourceFile(options, project, sourceFile);
|
|
157
|
+
if (changed) {
|
|
158
|
+
tree.write(sourceFile.getFilePath(), sourceFile.getFullText());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
console.error(`\x1b[31mError processing file: \x1b[0m${sourceFile.getFilePath()}`);
|
|
163
|
+
console.error(e.message);
|
|
164
|
+
console.error(e.stack);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
if (Date.now() - start > MAX_TIME) {
|
|
168
|
+
console.log(`\x1b[33mMax time reached: \x1b[0m${MAX_TIME}`);
|
|
169
|
+
break;
|
|
147
170
|
}
|
|
148
171
|
}
|
|
149
|
-
|
|
150
|
-
console.error(`\x1b[31mError processing file: \x1b[0m${sourceFile.getFilePath()}`);
|
|
151
|
-
console.error(e.message);
|
|
152
|
-
console.error(e.stack);
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
if (Date.now() - start > MAX_TIME) {
|
|
156
|
-
console.log(`\x1b[33mMax time reached: \x1b[0m${MAX_TIME}`);
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
172
|
+
});
|
|
160
173
|
}
|
|
161
174
|
function skipProject(project, projectName, options) {
|
|
162
|
-
|
|
175
|
+
var _a;
|
|
176
|
+
if ((_a = options.projects) === null || _a === void 0 ? void 0 : _a.length) {
|
|
163
177
|
return !options.projects.includes(projectName);
|
|
164
178
|
}
|
|
165
179
|
return false;
|
|
166
180
|
}
|
|
167
181
|
const MAX_TIME = 1000 * 60 * 60 * 0.5;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
182
|
+
function documentationGenerator(tree, options) {
|
|
183
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
for (const [projectName, project] of (0, devkit_1.getProjects)(tree).entries()) {
|
|
185
|
+
if (skipProject(project, projectName, options)) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
yield processProject(options, projectName, tree);
|
|
172
189
|
}
|
|
173
|
-
|
|
174
|
-
}
|
|
190
|
+
});
|
|
175
191
|
}
|
|
176
|
-
|
|
192
|
+
exports.documentationGenerator = documentationGenerator;
|
|
193
|
+
exports.default = documentationGenerator;
|
|
177
194
|
//# sourceMappingURL=generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/generator.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/generator.ts"],"names":[],"mappings":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AC9D,MAAM;aACP;SACF;IAEH,CAAC;CAAA;AAED,SAAS,WAAW,CAAC,OAA6B,EAAE,WAAmB,EAAE,OAAqC;;IAE5G,IAAI,MAAA,OAAO,CAAC,QAAQ,0CAAE,MAAM,EAAE;QAC5B,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;KAChD;IAED,OAAO,KAAK,CAAC;AAEf,CAAC;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;AAEtC,SAAsB,sBAAsB,CAC1C,IAAU,EACV,OAAqC;;QAGrC,KAAK,MAAM,CAAE,WAAW,EAAE,OAAO,CAAE,IAAI,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;YAElE,IAAI,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE;gBAC9C,SAAS;aACV;YAED,MAAM,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;SAElD;IAEH,CAAC;CAAA;AAfD,wDAeC;AAED,kBAAe,sBAAsB,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const generator_1 = require("./generator");
|
|
5
|
+
const schematic = (0, devkit_1.convertNxGenerator)(generator_1.default);
|
|
6
|
+
exports.default = schematic;
|
|
5
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/index.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAChD,2CAAoC;AAEpC,MAAM,SAAS,GAAG,IAAA,2BAAkB,EAAC,mBAAS,CAAC,CAAC;AAChD,kBAAe,SAAS,CAAC"}
|
|
@@ -1,61 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimplePrompt = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const gpt_3_encoder_1 = require("gpt-3-encoder");
|
|
2
6
|
const tokenLimits = {
|
|
3
7
|
'gpt-4': 8192,
|
|
4
8
|
'gpt-3.5-turbo': 4096,
|
|
5
9
|
'gpt-3.5-turbo-16k': 16384,
|
|
6
10
|
};
|
|
7
|
-
|
|
11
|
+
function SimplePrompt(systemPrompt, prompt, openai, options = {
|
|
8
12
|
max_tokens: 1024,
|
|
9
13
|
model: 'gpt-4',
|
|
10
14
|
}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (inputLength > tokenLimit * 0.8) {
|
|
21
|
-
throw new Error(`\x1b[31mInput length (${inputLength}) is too large. It should be at most ${tokenLimit *
|
|
22
|
-
0.8}\x1b[0m`);
|
|
23
|
-
}
|
|
24
|
-
if (options.max_tokens) {
|
|
25
|
-
if (options.max_tokens > tokenLimit - inputLength) {
|
|
26
|
-
console.log(`\x1b[33mWarning: max_tokens (${options.max_tokens}) is too large. It should be at most ${tokenLimit -
|
|
27
|
-
inputLength}\x1b[0m`);
|
|
28
|
-
options.max_tokens = tokenLimit - inputLength;
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const systemPromptLength = (0, gpt_3_encoder_1.encode)(systemPrompt).length;
|
|
18
|
+
const promptLength = (0, gpt_3_encoder_1.encode)(prompt).length;
|
|
19
|
+
const inputLength = Math.floor((systemPromptLength + promptLength) * 1.1);
|
|
20
|
+
(_a = options.model) !== null && _a !== void 0 ? _a : (options.model = 'gpt-4');
|
|
21
|
+
(_b = options.max_tokens) !== null && _b !== void 0 ? _b : (options.max_tokens = 1024);
|
|
22
|
+
if (!tokenLimits[options.model]) {
|
|
23
|
+
throw new Error(`\x1b[31mModel '${options.model}' is not supported.\x1b[0m`);
|
|
29
24
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
25
|
+
const tokenLimit = tokenLimits[options.model];
|
|
26
|
+
if (inputLength > tokenLimit * 0.8) {
|
|
27
|
+
throw new Error(`\x1b[31mInput length (${inputLength}) is too large. It should be at most ${tokenLimit *
|
|
28
|
+
0.8}\x1b[0m`);
|
|
29
|
+
}
|
|
30
|
+
if (options.max_tokens) {
|
|
31
|
+
if (options.max_tokens > tokenLimit - inputLength) {
|
|
32
|
+
console.log(`\x1b[33mWarning: max_tokens (${options.max_tokens}) is too large. It should be at most ${tokenLimit -
|
|
33
|
+
inputLength}\x1b[0m`);
|
|
34
|
+
options.max_tokens = tokenLimit - inputLength;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
let content;
|
|
38
|
+
try {
|
|
39
|
+
const response = yield openai.createChatCompletion(Object.assign(Object.assign({}, options), { messages: [
|
|
40
|
+
{
|
|
41
|
+
'role': 'system',
|
|
42
|
+
'content': systemPrompt,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
'role': 'user',
|
|
46
|
+
'content': prompt,
|
|
47
|
+
},
|
|
48
|
+
], temperature: 0, top_p: 1, frequency_penalty: 0, presence_penalty: 0 }));
|
|
49
|
+
content = (_c = response.data.choices[0].message) === null || _c === void 0 ? void 0 : _c.content;
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
console.log((_d = e.response) === null || _d === void 0 ? void 0 : _d.data);
|
|
53
|
+
throw new Error('OpenAI API error: ' + e.message);
|
|
54
|
+
}
|
|
55
|
+
if (!content) {
|
|
56
|
+
throw new Error(`\x1b[31mNo content in response for paper\x1b[0m`);
|
|
57
|
+
}
|
|
58
|
+
return content;
|
|
59
|
+
});
|
|
60
60
|
}
|
|
61
|
+
exports.SimplePrompt = SimplePrompt;
|
|
61
62
|
//# sourceMappingURL=simple-prompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-prompt.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/simple-prompt.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"simple-prompt.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/simple-prompt.ts"],"names":[],"mappings":";;;;AACA,iDAAuC;AAEvC,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,IAAI;IACrB,mBAAmB,EAAE,KAAK;CAC3B,CAAC;AAOF,SAAsB,YAAY,CAChC,YAAoB,EACpB,MAAc,EACd,MAAiB,EACjB,UAA8B;IAC5B,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,OAAO;CACf;;;QAID,MAAM,kBAAkB,GAAG,IAAA,sBAAM,EAAC,YAAY,CAAC,CAAC,MAAM,CAAC;QACvD,MAAM,YAAY,GAAG,IAAA,sBAAM,EAAC,MAAM,CAAC,CAAC,MAAM,CAAC;QAE3C,MAAM,WAAW,GAAG,IAAI,C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