@rxap/plugin-gpt 16.0.1-dev.1 → 16.0.1-dev.3
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 +12 -0
- package/README.md +8 -1
- package/generators.json +7 -0
- package/package.json +12 -11
- package/src/generators/documentation/generator.js +110 -127
- package/src/generators/documentation/generator.js.map +1 -1
- package/src/generators/documentation/index.d.ts +2 -0
- package/src/generators/documentation/index.js +5 -0
- package/src/generators/documentation/index.js.map +1 -0
- package/src/generators/documentation/simple-prompt.js +50 -51
- package/src/generators/documentation/simple-prompt.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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.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
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- change from commonjs to es2022 ([fd0f2ba](https://gitlab.com/rxap/packages/commit/fd0f2bae24eae7c854e96f630076cd5598c30be6))
|
|
11
|
+
|
|
12
|
+
## [16.0.1-dev.2](https://gitlab.com/rxap/packages/compare/@rxap/plugin-gpt@16.0.1-dev.1...@rxap/plugin-gpt@16.0.1-dev.2) (2023-08-06)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- expose generators as schematics ([679ca36](https://gitlab.com/rxap/packages/commit/679ca36d3712a11e4dc838762bca2f7c471e1e04))
|
|
17
|
+
|
|
6
18
|
## [16.0.1-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/plugin-gpt@16.0.1-dev.0...@rxap/plugin-gpt@16.0.1-dev.1) (2023-08-04)
|
|
7
19
|
|
|
8
20
|
### 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.3 @rxap/generator-utilities@^1.1.0-dev.4 gpt-3-encoder@^1.1.4 openai@^3.3.0 ts-morph@^18.0.0
|
|
22
22
|
```
|
|
23
23
|
# Generators
|
|
24
24
|
|
|
@@ -28,3 +28,10 @@ yarn add @nx/devkit@^16.5.0 @rxap/generator-ts-morph@^1.0.1-dev.2 @rxap/generato
|
|
|
28
28
|
```bash
|
|
29
29
|
yarn nx g @rxap/plugin-gpt:documentation
|
|
30
30
|
```
|
|
31
|
+
|
|
32
|
+
## documentation
|
|
33
|
+
> documentation generator
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
yarn nx g @rxap/plugin-gpt:documentation
|
|
37
|
+
```
|
package/generators.json
CHANGED
|
@@ -5,5 +5,12 @@
|
|
|
5
5
|
"schema": "./src/generators/documentation/schema.json",
|
|
6
6
|
"description": "documentation generator"
|
|
7
7
|
}
|
|
8
|
+
},
|
|
9
|
+
"schematics": {
|
|
10
|
+
"documentation": {
|
|
11
|
+
"factory": "./src/generators/documentation/index",
|
|
12
|
+
"schema": "./src/generators/documentation/schema.json",
|
|
13
|
+
"description": "documentation generator"
|
|
14
|
+
}
|
|
8
15
|
}
|
|
9
16
|
}
|
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.3",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"directory": "../../../dist/packages/plugin/gpt"
|
|
@@ -39,29 +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.0
|
|
42
|
+
"@rxap/generator-ts-morph": "^1.0.1-dev.3",
|
|
43
|
+
"@rxap/generator-utilities": "^1.1.0-dev.4",
|
|
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.0
|
|
50
|
-
"@rxap/workspace-utilities": "0.1.0-dev.
|
|
47
|
+
"@rxap/node-utilities": "1.1.0-dev.2",
|
|
48
|
+
"@rxap/utilities": "16.0.0-dev.10",
|
|
49
|
+
"@rxap/workspace-ts-morph": "0.1.0-dev.1",
|
|
50
|
+
"@rxap/workspace-utilities": "0.1.0-dev.4"
|
|
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.3"
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
"package": "@rxap/generator-utilities",
|
|
60
|
-
"version": "1.0
|
|
60
|
+
"version": "1.1.0-dev.4"
|
|
61
61
|
}
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
|
-
"
|
|
64
|
+
"schematics": "./generators.json",
|
|
65
|
+
"gitHead": "bbab80e59acbe435a02e69c9fec022780cf4640d",
|
|
65
66
|
"main": "./src/index.js",
|
|
66
67
|
"types": "./src/index.d.ts"
|
|
67
68
|
}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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");
|
|
1
|
+
import { getProjects, } from '@nx/devkit';
|
|
2
|
+
import { IndentationText, Project, QuoteKind, } from 'ts-morph';
|
|
3
|
+
import { AddDir } from '@rxap/generator-ts-morph';
|
|
4
|
+
import { GetProjectSourceRoot } from '@rxap/generator-utilities';
|
|
5
|
+
import * as process from 'process';
|
|
6
|
+
import { Configuration, OpenAIApi, } from 'openai';
|
|
7
|
+
import { SimplePrompt } from './simple-prompt';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
import { existsSync, readFileSync, } from 'fs';
|
|
14
10
|
function getOpenAi(param = {}) {
|
|
15
|
-
const configuration = new
|
|
16
|
-
|
|
11
|
+
const configuration = new Configuration({
|
|
12
|
+
...param,
|
|
13
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
14
|
+
});
|
|
15
|
+
return new OpenAIApi(configuration);
|
|
17
16
|
}
|
|
18
17
|
function loadSystemPrompt(name) {
|
|
19
|
-
const filePath =
|
|
20
|
-
if (!
|
|
18
|
+
const filePath = join(__dirname, 'system-prompts', `${name}.txt`);
|
|
19
|
+
if (!existsSync(filePath)) {
|
|
21
20
|
throw new Error(`Can not find system prompt file '${filePath}'`);
|
|
22
21
|
}
|
|
23
|
-
return
|
|
22
|
+
return readFileSync(filePath).toString();
|
|
24
23
|
}
|
|
25
24
|
const FUNCTION_SYSTEM_PROMPT = loadSystemPrompt('function');
|
|
26
25
|
const METHOD_SYSTEM_PROMPT = loadSystemPrompt('method');
|
|
@@ -28,13 +27,11 @@ const CLASS_SYSTEM_PROMPT = loadSystemPrompt('class');
|
|
|
28
27
|
function hasJsDoc(node) {
|
|
29
28
|
return node.getJsDocs().length > 0;
|
|
30
29
|
}
|
|
31
|
-
function prompt(options, systemPrompt, prompt) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return (0, simple_prompt_1.SimplePrompt)(systemPrompt, prompt, getOpenAi());
|
|
37
|
-
});
|
|
30
|
+
async function prompt(options, systemPrompt, prompt) {
|
|
31
|
+
if (options.offline) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
return SimplePrompt(systemPrompt, prompt, getOpenAi());
|
|
38
35
|
}
|
|
39
36
|
function cleanupJsDoc(jsDoc) {
|
|
40
37
|
const cleanJsDocArray = jsDoc
|
|
@@ -54,68 +51,60 @@ function addJsDoc(options, node, jsDoc) {
|
|
|
54
51
|
}
|
|
55
52
|
node.addJsDoc(cleanupJsDoc(jsDoc));
|
|
56
53
|
}
|
|
57
|
-
function processMethod(options, project, sourceFile, methodDeclaration) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return true;
|
|
72
|
-
});
|
|
54
|
+
async function processMethod(options, project, sourceFile, methodDeclaration) {
|
|
55
|
+
console.log(`====== Process method: \x1b[36m${methodDeclaration.getName()}\x1b[0m`);
|
|
56
|
+
if (hasJsDoc(methodDeclaration)) {
|
|
57
|
+
console.log(`\x1b[33mMethod has already a documentation\x1b[0m`);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const methodText = methodDeclaration.getText();
|
|
61
|
+
console.log('Method text:');
|
|
62
|
+
console.log(methodText);
|
|
63
|
+
const jsDoc = await prompt(options, METHOD_SYSTEM_PROMPT, methodText);
|
|
64
|
+
console.log('Method documentation:');
|
|
65
|
+
console.log(jsDoc);
|
|
66
|
+
addJsDoc(options, methodDeclaration, jsDoc);
|
|
67
|
+
return true;
|
|
73
68
|
}
|
|
74
|
-
function processClass(options, project, sourceFile, classDeclaration) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
changed = changed || hasChanged;
|
|
83
|
-
}
|
|
69
|
+
async function processClass(options, project, sourceFile, classDeclaration) {
|
|
70
|
+
console.log(`====== Process class: \x1b[36m${classDeclaration.getName()}\x1b[0m`);
|
|
71
|
+
let changed = false;
|
|
72
|
+
for (const md of classDeclaration.getMethods()) {
|
|
73
|
+
const scope = md.getScope();
|
|
74
|
+
if (scope === 'public' || scope === undefined) {
|
|
75
|
+
const hasChanged = await processMethod(options, project, sourceFile, md);
|
|
76
|
+
changed = changed || hasChanged;
|
|
84
77
|
}
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
}
|
|
79
|
+
return changed;
|
|
87
80
|
}
|
|
88
|
-
function processFunction(options, project, sourceFile, functionDeclaration) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return true;
|
|
103
|
-
});
|
|
81
|
+
async function processFunction(options, project, sourceFile, functionDeclaration) {
|
|
82
|
+
console.log(`====== Process function: \x1b[36m${functionDeclaration.getName()}\x1b[0m`);
|
|
83
|
+
if (hasJsDoc(functionDeclaration)) {
|
|
84
|
+
console.log(`\x1b[33mFunction has already a documentation\x1b[0m`);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
const functionText = functionDeclaration.getText();
|
|
88
|
+
console.log('Function text:');
|
|
89
|
+
console.log(functionText);
|
|
90
|
+
const jsDoc = await prompt(options, FUNCTION_SYSTEM_PROMPT, functionText);
|
|
91
|
+
console.log('Function documentation:');
|
|
92
|
+
console.log(jsDoc);
|
|
93
|
+
addJsDoc(options, functionDeclaration, jsDoc);
|
|
94
|
+
return true;
|
|
104
95
|
}
|
|
105
|
-
function processSourceFile(options, project, sourceFile) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return changed;
|
|
118
|
-
});
|
|
96
|
+
async function processSourceFile(options, project, sourceFile) {
|
|
97
|
+
console.log(`====== Process source file: \x1b[35m${sourceFile.getFilePath()}\x1b[0m`);
|
|
98
|
+
let changed = false;
|
|
99
|
+
for (const fd of sourceFile.getFunctions()) {
|
|
100
|
+
const hasChanged = await processFunction(options, project, sourceFile, fd);
|
|
101
|
+
changed = changed || hasChanged;
|
|
102
|
+
}
|
|
103
|
+
for (const cd of sourceFile.getClasses()) {
|
|
104
|
+
const hasChanged = await processClass(options, project, sourceFile, cd);
|
|
105
|
+
changed = changed || hasChanged;
|
|
106
|
+
}
|
|
107
|
+
return changed;
|
|
119
108
|
}
|
|
120
109
|
function skipSourceFile(sourceFile) {
|
|
121
110
|
if (sourceFile.getBaseName() === 'index.ts') {
|
|
@@ -136,59 +125,53 @@ function skipSourceFile(sourceFile) {
|
|
|
136
125
|
}
|
|
137
126
|
return false;
|
|
138
127
|
}
|
|
139
|
-
function processProject(options, projectName, tree) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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;
|
|
128
|
+
async function processProject(options, projectName, tree) {
|
|
129
|
+
const projectSourceRoot = GetProjectSourceRoot(tree, projectName);
|
|
130
|
+
const project = new Project({
|
|
131
|
+
manipulationSettings: {
|
|
132
|
+
indentationText: IndentationText.TwoSpaces,
|
|
133
|
+
quoteKind: QuoteKind.Single,
|
|
134
|
+
},
|
|
135
|
+
useInMemoryFileSystem: true,
|
|
136
|
+
});
|
|
137
|
+
AddDir(tree, projectSourceRoot, project);
|
|
138
|
+
const start = Date.now();
|
|
139
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
140
|
+
if (skipSourceFile(sourceFile)) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const changed = await processSourceFile(options, project, sourceFile);
|
|
145
|
+
if (changed) {
|
|
146
|
+
tree.write(sourceFile.getFilePath(), sourceFile.getFullText());
|
|
170
147
|
}
|
|
171
148
|
}
|
|
172
|
-
|
|
149
|
+
catch (e) {
|
|
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
|
+
}
|
|
173
160
|
}
|
|
174
161
|
function skipProject(project, projectName, options) {
|
|
175
|
-
|
|
176
|
-
if ((_a = options.projects) === null || _a === void 0 ? void 0 : _a.length) {
|
|
162
|
+
if (options.projects?.length) {
|
|
177
163
|
return !options.projects.includes(projectName);
|
|
178
164
|
}
|
|
179
165
|
return false;
|
|
180
166
|
}
|
|
181
167
|
const MAX_TIME = 1000 * 60 * 60 * 0.5;
|
|
182
|
-
function documentationGenerator(tree, options) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
yield processProject(options, projectName, tree);
|
|
168
|
+
export async function documentationGenerator(tree, options) {
|
|
169
|
+
for (const [projectName, project] of getProjects(tree).entries()) {
|
|
170
|
+
if (skipProject(project, projectName, options)) {
|
|
171
|
+
continue;
|
|
189
172
|
}
|
|
190
|
-
|
|
173
|
+
await processProject(options, projectName, tree);
|
|
174
|
+
}
|
|
191
175
|
}
|
|
192
|
-
|
|
193
|
-
exports.default = documentationGenerator;
|
|
176
|
+
export default documentationGenerator;
|
|
194
177
|
//# sourceMappingURL=generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,GAGZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAGL,eAAe,EAGf,OAAO,EACP,SAAS,GAEV,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EACL,aAAa,EAEb,SAAS,GACV,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,UAAU,EACV,YAAY,GACb,MAAM,IAAI,CAAC;AAEZ,SA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CAAC,WAAW,CAAC,CAAC;KAChD;IAED,OAAO,KAAK,CAAC;AAEf,CAAC;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;AAEtC,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,IAAU,EACV,OAAqC;IAGrC,KAAK,MAAM,CAAE,WAAW,EAAE,OAAO,CAAE,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QAElE,IAAI,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE;YAC9C,SAAS;SACV;QAED,MAAM,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;KAElD;AAEH,CAAC;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC,MAAM,SAAS,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAChD,eAAe,SAAS,CAAC"}
|
|
@@ -1,62 +1,61 @@
|
|
|
1
|
-
|
|
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");
|
|
1
|
+
import { encode } from 'gpt-3-encoder';
|
|
6
2
|
const tokenLimits = {
|
|
7
3
|
'gpt-4': 8192,
|
|
8
4
|
'gpt-3.5-turbo': 4096,
|
|
9
5
|
'gpt-3.5-turbo-16k': 16384,
|
|
10
6
|
};
|
|
11
|
-
function SimplePrompt(systemPrompt, prompt, openai, options = {
|
|
7
|
+
export async function SimplePrompt(systemPrompt, prompt, openai, options = {
|
|
12
8
|
max_tokens: 1024,
|
|
13
9
|
model: 'gpt-4',
|
|
14
10
|
}) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
const systemPromptLength = encode(systemPrompt).length;
|
|
12
|
+
const promptLength = encode(prompt).length;
|
|
13
|
+
const inputLength = Math.floor((systemPromptLength + promptLength) * 1.1);
|
|
14
|
+
options.model ??= 'gpt-4';
|
|
15
|
+
options.max_tokens ??= 1024;
|
|
16
|
+
if (!tokenLimits[options.model]) {
|
|
17
|
+
throw new Error(`\x1b[31mModel '${options.model}' is not supported.\x1b[0m`);
|
|
18
|
+
}
|
|
19
|
+
const tokenLimit = tokenLimits[options.model];
|
|
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;
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
if (!content) {
|
|
56
|
-
throw new Error(`\x1b[31mNo content in response for paper\x1b[0m`);
|
|
57
|
-
}
|
|
58
|
-
return content;
|
|
59
|
-
});
|
|
30
|
+
}
|
|
31
|
+
let content;
|
|
32
|
+
try {
|
|
33
|
+
const response = await openai.createChatCompletion({
|
|
34
|
+
...options,
|
|
35
|
+
messages: [
|
|
36
|
+
{
|
|
37
|
+
'role': 'system',
|
|
38
|
+
'content': systemPrompt,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
'role': 'user',
|
|
42
|
+
'content': prompt,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
temperature: 0,
|
|
46
|
+
top_p: 1,
|
|
47
|
+
frequency_penalty: 0,
|
|
48
|
+
presence_penalty: 0,
|
|
49
|
+
});
|
|
50
|
+
content = response.data.choices[0].message?.content;
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
console.log(e.response?.data);
|
|
54
|
+
throw new Error('OpenAI API error: ' + e.message);
|
|
55
|
+
}
|
|
56
|
+
if (!content) {
|
|
57
|
+
throw new Error(`\x1b[31mNo content in response for paper\x1b[0m`);
|
|
58
|
+
}
|
|
59
|
+
return content;
|
|
60
60
|
}
|
|
61
|
-
exports.SimplePrompt = SimplePrompt;
|
|
62
61
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"simple-prompt.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/simple-prompt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,IAAI;IACrB,mBAAmB,EAAE,KAAK;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