@rxap/plugin-gpt 19.0.2 → 19.0.3-dev.1
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/package.json +8 -8
- package/src/generators/documentation/add-js-doc.d.ts +3 -0
- package/src/generators/documentation/add-js-doc.js +12 -0
- package/src/generators/documentation/add-js-doc.js.map +1 -0
- package/src/generators/documentation/cleanup-js-doc.d.ts +1 -0
- package/src/generators/documentation/cleanup-js-doc.js +18 -0
- package/src/generators/documentation/cleanup-js-doc.js.map +1 -0
- package/src/generators/documentation/const.d.ts +3 -0
- package/src/generators/documentation/const.js +9 -0
- package/src/generators/documentation/const.js.map +1 -0
- package/src/generators/documentation/generator.js +19 -177
- package/src/generators/documentation/generator.js.map +1 -1
- package/src/generators/documentation/has-js-doc.d.ts +2 -0
- package/src/generators/documentation/has-js-doc.js +8 -0
- package/src/generators/documentation/has-js-doc.js.map +1 -0
- package/src/generators/documentation/load-system-prompt.d.ts +1 -0
- package/src/generators/documentation/load-system-prompt.js +14 -0
- package/src/generators/documentation/load-system-prompt.js.map +1 -0
- package/src/generators/documentation/open-ai-instance.d.ts +4 -0
- package/src/generators/documentation/open-ai-instance.js +31 -0
- package/src/generators/documentation/open-ai-instance.js.map +1 -0
- package/src/generators/documentation/process-class.d.ts +3 -0
- package/src/generators/documentation/process-class.js +15 -0
- package/src/generators/documentation/process-class.js.map +1 -0
- package/src/generators/documentation/process-function.d.ts +3 -0
- package/src/generators/documentation/process-function.js +30 -0
- package/src/generators/documentation/process-function.js.map +1 -0
- package/src/generators/documentation/process-method.d.ts +3 -0
- package/src/generators/documentation/process-method.js +30 -0
- package/src/generators/documentation/process-method.js.map +1 -0
- package/src/generators/documentation/process-project.d.ts +3 -0
- package/src/generators/documentation/process-project.js +40 -0
- package/src/generators/documentation/process-project.js.map +1 -0
- package/src/generators/documentation/process-source-file.d.ts +3 -0
- package/src/generators/documentation/process-source-file.js +19 -0
- package/src/generators/documentation/process-source-file.js.map +1 -0
- package/src/generators/documentation/prompt.d.ts +1 -0
- package/src/generators/documentation/prompt.js +16 -0
- package/src/generators/documentation/prompt.js.map +1 -0
- package/src/generators/documentation/schema.d.ts +2 -0
- package/src/generators/documentation/schema.json +8 -0
- package/src/generators/documentation/simple-prompt.d.ts +8 -4
- package/src/generators/documentation/simple-prompt.js +26 -6
- package/src/generators/documentation/simple-prompt.js.map +1 -1
- package/src/generators/documentation/skip-source-file.d.ts +2 -0
- package/src/generators/documentation/skip-source-file.js +30 -0
- package/src/generators/documentation/skip-source-file.js.map +1 -0
- package/src/generators/documentation/system-prompts/function.txt +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
|
+
## [19.0.3-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/plugin-gpt@19.0.3-dev.0...@rxap/plugin-gpt@19.0.3-dev.1) (2024-06-20)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- add html code coverage reporters ([73da1d8](https://gitlab.com/rxap/packages/commit/73da1d85274686590952a97e202c713718988caa))
|
|
11
|
+
- update openapi package ([d5afabe](https://gitlab.com/rxap/packages/commit/d5afabec58c65d3178129b826f016e1c593b8846))
|
|
12
|
+
- update to new openai models ([882aab3](https://gitlab.com/rxap/packages/commit/882aab3575ba99c7e271969fa94e2f2bb9361b2c))
|
|
13
|
+
|
|
14
|
+
## [19.0.3-dev.0](https://gitlab.com/rxap/packages/compare/@rxap/plugin-gpt@19.0.2...@rxap/plugin-gpt@19.0.3-dev.0) (2024-06-18)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @rxap/plugin-gpt
|
|
17
|
+
|
|
6
18
|
## [19.0.2](https://gitlab.com/rxap/packages/compare/@rxap/plugin-gpt@19.0.2-dev.5...@rxap/plugin-gpt@19.0.2) (2024-06-18)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @rxap/plugin-gpt
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "19.0.
|
|
2
|
+
"version": "19.0.3-dev.1",
|
|
3
3
|
"name": "@rxap/plugin-gpt",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@nx/devkit": "19.
|
|
7
|
-
"@rxap/
|
|
8
|
-
"@rxap/ts-morph": "
|
|
9
|
-
"@rxap/workspace-utilities": "^19.
|
|
10
|
-
"gpt-3-encoder": "1.1.4",
|
|
11
|
-
"openai": "
|
|
6
|
+
"@nx/devkit": "19.3.0",
|
|
7
|
+
"@rxap/ts-morph": "^1.4.1-dev.0",
|
|
8
|
+
"@rxap/workspace-ts-morph": "*",
|
|
9
|
+
"@rxap/workspace-utilities": "^19.3.0-dev.0",
|
|
10
|
+
"gpt-3-encoder": "^1.1.4",
|
|
11
|
+
"openai": "^4.52.0",
|
|
12
12
|
"ts-morph": "18.0.0",
|
|
13
13
|
"tslib": "2.6.2"
|
|
14
14
|
},
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
},
|
|
44
44
|
"schematics": "./generators.json",
|
|
45
45
|
"type": "commonjs",
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "3fa5a96cac9ec03017cb91b15f918a0e66db9066",
|
|
47
47
|
"main": "./src/index.js"
|
|
48
48
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addJsDoc = void 0;
|
|
4
|
+
const cleanup_js_doc_1 = require("./cleanup-js-doc");
|
|
5
|
+
function addJsDoc(options, node, jsDoc) {
|
|
6
|
+
if (options.offline) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
node.addJsDoc((0, cleanup_js_doc_1.cleanupJsDoc)(jsDoc));
|
|
10
|
+
}
|
|
11
|
+
exports.addJsDoc = addJsDoc;
|
|
12
|
+
//# sourceMappingURL=add-js-doc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-js-doc.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/add-js-doc.ts"],"names":[],"mappings":";;;AACA,qDAAgD;AAGhD,SAAgB,QAAQ,CAAC,OAAqC,EAAE,IAAmB,EAAE,KAAa;IAEhG,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO;IACT,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,IAAA,6BAAY,EAAC,KAAK,CAAC,CAAC,CAAC;AACrC,CAAC;AAPD,4BAOC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cleanupJsDoc(jsDoc: string): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cleanupJsDoc = void 0;
|
|
4
|
+
function cleanupJsDoc(jsDoc) {
|
|
5
|
+
const cleanJsDocArray = jsDoc
|
|
6
|
+
.split('\n')
|
|
7
|
+
.map(line => line
|
|
8
|
+
.trim()
|
|
9
|
+
.replace(/^\/\*\*/, '')
|
|
10
|
+
.replace(/^\s?\*\//, '')
|
|
11
|
+
.replace(/^\s?\*\s?/, '')
|
|
12
|
+
.replace(/^\s?\*\s```typescript/, ' *')
|
|
13
|
+
.trim());
|
|
14
|
+
cleanJsDocArray.pop();
|
|
15
|
+
return cleanJsDocArray.join('\n');
|
|
16
|
+
}
|
|
17
|
+
exports.cleanupJsDoc = cleanupJsDoc;
|
|
18
|
+
//# sourceMappingURL=cleanup-js-doc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanup-js-doc.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/cleanup-js-doc.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,KAAa;IAExC,MAAM,eAAe,GAAG,KAAK;SAC1B,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI;SACd,IAAI,EAAE;SACN,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;SACtB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,OAAO,CAAC,uBAAuB,EAAE,IAAI,CAAC;SACtC,IAAI,EAAE,CACR,CAAC;IAEJ,eAAe,CAAC,GAAG,EAAE,CAAC;IAEtB,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEpC,CAAC;AAjBD,oCAiBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_TIME = exports.METHOD_SYSTEM_PROMPT = exports.FUNCTION_SYSTEM_PROMPT = void 0;
|
|
4
|
+
const load_system_prompt_1 = require("./load-system-prompt");
|
|
5
|
+
exports.FUNCTION_SYSTEM_PROMPT = (0, load_system_prompt_1.loadSystemPrompt)('function');
|
|
6
|
+
exports.METHOD_SYSTEM_PROMPT = (0, load_system_prompt_1.loadSystemPrompt)('method');
|
|
7
|
+
const CLASS_SYSTEM_PROMPT = (0, load_system_prompt_1.loadSystemPrompt)('class');
|
|
8
|
+
exports.MAX_TIME = 1000 * 60 * 60 * 0.5;
|
|
9
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/const.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AAE3C,QAAA,sBAAsB,GAAG,IAAA,qCAAgB,EAAC,UAAU,CAAC,CAAC;AACtD,QAAA,oBAAoB,GAAG,IAAA,qCAAgB,EAAC,QAAQ,CAAC,CAAC;AAC/D,MAAM,mBAAmB,GAAG,IAAA,qCAAgB,EAAC,OAAO,CAAC,CAAC;AACzC,QAAA,QAAQ,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC"}
|
|
@@ -3,177 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.documentationGenerator = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const generator_ts_morph_1 = require("@rxap/generator-ts-morph");
|
|
7
|
-
const ts_morph_1 = require("@rxap/ts-morph");
|
|
8
|
-
const workspace_utilities_1 = require("@rxap/workspace-utilities");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const openai_1 = require("openai");
|
|
11
|
-
const path_1 = require("path");
|
|
12
6
|
const process = require("process");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
if (!process.env.OPENAI_API_KEY) {
|
|
16
|
-
throw new Error('Can not find OPENAI_API_KEY environment variable');
|
|
17
|
-
}
|
|
18
|
-
const configuration = new openai_1.Configuration(Object.assign(Object.assign({}, param), { apiKey: process.env.OPENAI_API_KEY }));
|
|
19
|
-
return new openai_1.OpenAIApi(configuration);
|
|
20
|
-
}
|
|
21
|
-
function loadSystemPrompt(name) {
|
|
22
|
-
const filePath = (0, path_1.join)(__dirname, 'system-prompts', `${name}.txt`);
|
|
23
|
-
if (!(0, fs_1.existsSync)(filePath)) {
|
|
24
|
-
throw new Error(`Can not find system prompt file '${filePath}'`);
|
|
25
|
-
}
|
|
26
|
-
return (0, fs_1.readFileSync)(filePath).toString();
|
|
27
|
-
}
|
|
28
|
-
const FUNCTION_SYSTEM_PROMPT = loadSystemPrompt('function');
|
|
29
|
-
const METHOD_SYSTEM_PROMPT = loadSystemPrompt('method');
|
|
30
|
-
const CLASS_SYSTEM_PROMPT = loadSystemPrompt('class');
|
|
31
|
-
function hasJsDoc(node) {
|
|
32
|
-
return node.getJsDocs().length > 0;
|
|
33
|
-
}
|
|
34
|
-
function prompt(options, systemPrompt, prompt) {
|
|
35
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
if (options.offline) {
|
|
37
|
-
return '';
|
|
38
|
-
}
|
|
39
|
-
return (0, simple_prompt_1.SimplePrompt)(systemPrompt, prompt, getOpenAi());
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function cleanupJsDoc(jsDoc) {
|
|
43
|
-
const cleanJsDocArray = jsDoc
|
|
44
|
-
.split('\n')
|
|
45
|
-
.map(line => line
|
|
46
|
-
.trim()
|
|
47
|
-
.replace(/^\/\*\*/, '')
|
|
48
|
-
.replace(/^\s?\*\//, '')
|
|
49
|
-
.replace(/^\s?\*\s?/, '')
|
|
50
|
-
.trim());
|
|
51
|
-
cleanJsDocArray.pop();
|
|
52
|
-
return cleanJsDocArray.join('\n');
|
|
53
|
-
}
|
|
54
|
-
function addJsDoc(options, node, jsDoc) {
|
|
55
|
-
if (options.offline) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
node.addJsDoc(cleanupJsDoc(jsDoc));
|
|
59
|
-
}
|
|
60
|
-
function processMethod(options, project, sourceFile, methodDeclaration) {
|
|
61
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
console.log(`====== Process method: \x1b[36m${methodDeclaration.getName()}\x1b[0m`);
|
|
63
|
-
if (hasJsDoc(methodDeclaration)) {
|
|
64
|
-
console.log(`\x1b[33mMethod has already a documentation\x1b[0m`);
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
const methodText = methodDeclaration.getText();
|
|
68
|
-
console.log('Method text:');
|
|
69
|
-
console.log(methodText);
|
|
70
|
-
const jsDoc = yield prompt(options, METHOD_SYSTEM_PROMPT, methodText);
|
|
71
|
-
console.log('Method documentation:');
|
|
72
|
-
console.log(jsDoc);
|
|
73
|
-
addJsDoc(options, methodDeclaration, jsDoc);
|
|
74
|
-
return true;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
function processClass(options, project, sourceFile, classDeclaration) {
|
|
78
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
console.log(`====== Process class: \x1b[36m${classDeclaration.getName()}\x1b[0m`);
|
|
80
|
-
let changed = false;
|
|
81
|
-
for (const md of classDeclaration.getMethods()) {
|
|
82
|
-
const scope = md.getScope();
|
|
83
|
-
if (scope === 'public' || scope === undefined) {
|
|
84
|
-
const hasChanged = yield processMethod(options, project, sourceFile, md);
|
|
85
|
-
changed = changed || hasChanged;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return changed;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
function processFunction(options, project, sourceFile, functionDeclaration) {
|
|
92
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
console.log(`====== Process function: \x1b[36m${functionDeclaration.getName()}\x1b[0m`);
|
|
94
|
-
if (hasJsDoc(functionDeclaration)) {
|
|
95
|
-
console.log(`\x1b[33mFunction has already a documentation\x1b[0m`);
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
const functionText = functionDeclaration.getText();
|
|
99
|
-
console.log('Function text:');
|
|
100
|
-
console.log(functionText);
|
|
101
|
-
const jsDoc = yield prompt(options, FUNCTION_SYSTEM_PROMPT, functionText);
|
|
102
|
-
console.log('Function documentation:');
|
|
103
|
-
console.log(jsDoc);
|
|
104
|
-
addJsDoc(options, functionDeclaration, jsDoc);
|
|
105
|
-
return true;
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
function processSourceFile(options, project, sourceFile) {
|
|
109
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
console.log(`====== Process source file: \x1b[35m${sourceFile.getFilePath()}\x1b[0m`);
|
|
111
|
-
let changed = false;
|
|
112
|
-
for (const fd of sourceFile.getFunctions()) {
|
|
113
|
-
const hasChanged = yield processFunction(options, project, sourceFile, fd);
|
|
114
|
-
changed = changed || hasChanged;
|
|
115
|
-
}
|
|
116
|
-
for (const cd of sourceFile.getClasses()) {
|
|
117
|
-
const hasChanged = yield processClass(options, project, sourceFile, cd);
|
|
118
|
-
changed = changed || hasChanged;
|
|
119
|
-
}
|
|
120
|
-
return changed;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
function skipSourceFile(sourceFile, filter) {
|
|
124
|
-
if (sourceFile.getBaseName() === 'index.ts') {
|
|
125
|
-
// console.log(`\x1b[33mSkip index file: \x1b[0m${ sourceFile.getFilePath() }`);
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
if (sourceFile.getBaseName().endsWith('.spec.ts')) {
|
|
129
|
-
// console.log(`\x1b[33mSkip spec file: \x1b[0m${ sourceFile.getFilePath() }`);
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
if (sourceFile.getBaseName().endsWith('.stories.ts')) {
|
|
133
|
-
// console.log(`\x1b[33mSkip stories file: \x1b[0m${ sourceFile.getFilePath() }`);
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
if (sourceFile.getBaseName().endsWith('.cy.ts')) {
|
|
137
|
-
// console.log(`\x1b[33mSkip cypress file: \x1b[0m${ sourceFile.getFilePath() }`);
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
if (filter) {
|
|
141
|
-
if (!sourceFile.getFilePath().includes(filter)) {
|
|
142
|
-
// console.log(`\x1b[33mSkip file: \x1b[0m${ sourceFile.getFilePath() }`);
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
function processProject(options, projectName, tree) {
|
|
149
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
const projectSourceRoot = (0, workspace_utilities_1.GetProjectSourceRoot)(tree, projectName);
|
|
151
|
-
const project = (0, ts_morph_1.CreateProject)();
|
|
152
|
-
(0, generator_ts_morph_1.AddDir)(tree, projectSourceRoot, project);
|
|
153
|
-
const start = Date.now();
|
|
154
|
-
for (const sourceFile of project.getSourceFiles()) {
|
|
155
|
-
if (skipSourceFile(sourceFile, options.filter)) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
try {
|
|
159
|
-
const changed = yield processSourceFile(options, project, sourceFile);
|
|
160
|
-
if (changed) {
|
|
161
|
-
(0, workspace_utilities_1.CoerceFile)(tree, (0, path_1.join)(projectSourceRoot, sourceFile.getFilePath()), sourceFile.getFullText(), true);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
catch (e) {
|
|
165
|
-
console.error(`\x1b[31mError processing file: \x1b[0m${sourceFile.getFilePath()}`);
|
|
166
|
-
console.error(e.message);
|
|
167
|
-
console.error(e.stack);
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
if (Date.now() - start > MAX_TIME) {
|
|
171
|
-
console.log(`\x1b[33mMax time reached: \x1b[0m${MAX_TIME}`);
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
7
|
+
const open_ai_instance_1 = require("./open-ai-instance");
|
|
8
|
+
const process_project_1 = require("./process-project");
|
|
177
9
|
function skipProject(project, projectName, options) {
|
|
178
10
|
var _a;
|
|
179
11
|
if ((_a = options.projects) === null || _a === void 0 ? void 0 : _a.length) {
|
|
@@ -181,21 +13,31 @@ function skipProject(project, projectName, options) {
|
|
|
181
13
|
}
|
|
182
14
|
return false;
|
|
183
15
|
}
|
|
184
|
-
const MAX_TIME = 1000 * 60 * 60 * 0.5;
|
|
185
16
|
function documentationGenerator(tree, options) {
|
|
186
17
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
18
|
+
var _a, _b, _c;
|
|
19
|
+
const openaiApiKey = (_a = options.openaiApiKey) !== null && _a !== void 0 ? _a : process.env.OPENAI_API_KEY;
|
|
20
|
+
const openaiOrganization = (_b = options.openaiOrgId) !== null && _b !== void 0 ? _b : process.env.OPENAI_ORG_ID;
|
|
21
|
+
const openaiProjectId = (_c = options.openaiProjectId) !== null && _c !== void 0 ? _c : process.env.OPENAI_PROJECT_ID;
|
|
22
|
+
if (!openaiApiKey) {
|
|
191
23
|
throw new Error('Can not find OPENAI_API_KEY environment variable');
|
|
192
24
|
}
|
|
193
|
-
|
|
25
|
+
if (!openaiOrganization) {
|
|
26
|
+
throw new Error('Can not find OPENAI_ORGANIZATION environment variable');
|
|
27
|
+
}
|
|
28
|
+
if (!openaiProjectId) {
|
|
29
|
+
throw new Error('Can not find OPENAI_PROJECT_ID environment variable');
|
|
30
|
+
}
|
|
31
|
+
yield (0, open_ai_instance_1.createOpenApi)({
|
|
32
|
+
apiKey: openaiApiKey,
|
|
33
|
+
organization: openaiOrganization,
|
|
34
|
+
project: openaiProjectId,
|
|
35
|
+
});
|
|
194
36
|
for (const [projectName, project] of (0, devkit_1.getProjects)(tree).entries()) {
|
|
195
37
|
if (skipProject(project, projectName, options)) {
|
|
196
38
|
continue;
|
|
197
39
|
}
|
|
198
|
-
yield processProject(options, projectName, tree);
|
|
40
|
+
yield (0, process_project_1.processProject)(options, projectName, tree);
|
|
199
41
|
}
|
|
200
42
|
});
|
|
201
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAIoB;AACpB,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAIoB;AACpB,mCAAmC;AACnC,yDAAmD;AACnD,uDAAmD;AAGnD,SAAS,WAAW,CAAC,OAA6B,EAAE,WAAmB,EA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AC;QAEnD,CAAC;IAEH,CAAC;CAAA;AArCD,wDAqCC;AAED,kBAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-js-doc.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/has-js-doc.ts"],"names":[],"mappings":";;;AAEA,SAAgB,QAAQ,CAAC,IAAmB;IAC1C,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AACrC,CAAC;AAFD,4BAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadSystemPrompt(name: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadSystemPrompt = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
function loadSystemPrompt(name) {
|
|
7
|
+
const filePath = (0, path_1.join)(__dirname, 'system-prompts', `${name}.txt`);
|
|
8
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
9
|
+
throw new Error(`Can not find system prompt file '${filePath}'`);
|
|
10
|
+
}
|
|
11
|
+
return (0, fs_1.readFileSync)(filePath).toString();
|
|
12
|
+
}
|
|
13
|
+
exports.loadSystemPrompt = loadSystemPrompt;
|
|
14
|
+
//# sourceMappingURL=load-system-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-system-prompt.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/load-system-prompt.ts"],"names":[],"mappings":";;;AAAA,2BAGY;AACZ,+BAA4B;AAE5B,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,gBAAgB,EAAE,GAAI,IAAK,MAAM,CAAC,CAAC;IACpE,IAAI,CAAC,IAAA,eAAU,EAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,oCAAqC,QAAS,GAAG,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,IAAA,iBAAY,EAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC3C,CAAC;AAND,4CAMC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOpenAi = exports.createOpenApi = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const openai_1 = require("openai");
|
|
6
|
+
let OPENAI_INSTANCE = null;
|
|
7
|
+
function createOpenApi(param) {
|
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
if (OPENAI_INSTANCE) {
|
|
10
|
+
return OPENAI_INSTANCE;
|
|
11
|
+
}
|
|
12
|
+
OPENAI_INSTANCE = new openai_1.OpenAI(param);
|
|
13
|
+
yield OPENAI_INSTANCE.models.list()
|
|
14
|
+
.catch(() => console.error('Error listing models'))
|
|
15
|
+
.then(models => {
|
|
16
|
+
if (models) {
|
|
17
|
+
console.log('Models:', models.data.map(model => model.id));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return OPENAI_INSTANCE;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.createOpenApi = createOpenApi;
|
|
24
|
+
function getOpenAi() {
|
|
25
|
+
if (!OPENAI_INSTANCE) {
|
|
26
|
+
throw new Error('OpenAI instance is not created');
|
|
27
|
+
}
|
|
28
|
+
return OPENAI_INSTANCE;
|
|
29
|
+
}
|
|
30
|
+
exports.getOpenAi = getOpenAi;
|
|
31
|
+
//# sourceMappingURL=open-ai-instance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-ai-instance.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/open-ai-instance.ts"],"names":[],"mappings":";;;;AAAA,mCAAgC;AAGhC,IAAI,eAAe,GAAkB,IAAI,CAAC;AAE1C,SAAsB,aAAa,CAAC,KAAoB;;QAEtD,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,eAAe,CAAC;QACzB,CAAC;QAED,eAAe,GAAG,IAAI,eAAM,CAAC,KAAK,CAAC,CAAC;QAEpC,MAAM,eAAe,CAAC,MAAM,CAAC,IAAI,EAAE;aAChC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;aAClD,IAAI,CAAC,MAAM,CAAC,EAAE;YACb,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC,CAAC,CAAC;QAEL,OAAO,eAAe,CAAC;IAEzB,CAAC;CAAA;AAlBD,sCAkBC;AAED,SAAgB,SAAS;IACvB,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AALD,8BAKC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processClass = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const process_method_1 = require("./process-method");
|
|
6
|
+
function processClass(options, classDeclaration) {
|
|
7
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
8
|
+
console.log(`====== Process class: \x1b[36m${classDeclaration.getName()}\x1b[0m`);
|
|
9
|
+
for (const methodDefinition of classDeclaration.getMethods()) {
|
|
10
|
+
yield (0, process_method_1.processMethod)(options, methodDefinition);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.processClass = processClass;
|
|
15
|
+
//# sourceMappingURL=process-class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-class.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/process-class.ts"],"names":[],"mappings":";;;;AACA,qDAAiD;AAGjD,SAAsB,YAAY,CAChC,OAAqC,EACrC,gBAAkC;;QAGlC,OAAO,CAAC,GAAG,CAAC,iCAAkC,gBAAgB,CAAC,OAAO,EAAG,SAAS,CAAC,CAAC;QAEpF,KAAK,MAAM,gBAAgB,IAAI,gBAAgB,CAAC,UAAU,EAAE,EAAE,CAAC;YAC7D,MAAM,IAAA,8BAAa,EAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;QACjD,CAAC;IAEH,CAAC;CAAA;AAXD,oCAWC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processFunction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const add_js_doc_1 = require("./add-js-doc");
|
|
6
|
+
const const_1 = require("./const");
|
|
7
|
+
const has_js_doc_1 = require("./has-js-doc");
|
|
8
|
+
const prompt_1 = require("./prompt");
|
|
9
|
+
function processFunction(options, functionDeclaration) {
|
|
10
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
console.log(`====== Process function: \x1b[36m${functionDeclaration.getName()}\x1b[0m`);
|
|
12
|
+
if ((0, has_js_doc_1.hasJsDoc)(functionDeclaration)) {
|
|
13
|
+
console.log(`\x1b[33mFunction has already a documentation\x1b[0m`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const functionText = functionDeclaration.getText();
|
|
17
|
+
try {
|
|
18
|
+
const jsDoc = yield (0, prompt_1.prompt)(options, const_1.FUNCTION_SYSTEM_PROMPT, functionText);
|
|
19
|
+
(0, add_js_doc_1.addJsDoc)(options, functionDeclaration, jsDoc);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.error(`\x1b[31mError processing function: \x1b[0m${functionDeclaration.getName()}`);
|
|
23
|
+
console.error(e.message);
|
|
24
|
+
console.error(e.stack);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.processFunction = processFunction;
|
|
30
|
+
//# sourceMappingURL=process-function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-function.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/process-function.ts"],"names":[],"mappings":";;;;AAKA,6CAAwC;AACxC,mCAAiD;AACjD,6CAAwC;AACxC,qCAAkC;AAGlC,SAAsB,eAAe,CACnC,OAAqC,EACrC,mBAAwC;;QAGxC,OAAO,CAAC,GAAG,CAAC,oCAAqC,mBAAmB,CAAC,OAAO,EAAG,SAAS,CAAC,CAAC;QAE1F,IAAI,IAAA,qBAAQ,EAAC,mBAAmB,CAAC,EAAE,CAAC;YAClC,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;YACnE,OAAO;QACT,CAAC;QAED,MAAM,YAAY,GAAG,mBAAmB,CAAC,OAAO,EAAE,CAAC;QAEnD,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,IAAA,eAAM,EACxB,OAAO,EACP,8BAAsB,EACtB,YAAY,CACb,CAAC;YACF,IAAA,qBAAQ,EAAC,OAAO,EAAE,mBAAmB,EAAE,KAAK,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,6CAA8C,mBAAmB,CAAC,OAAO,EAAG,EAAE,CAAC,CAAC;YAC9F,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YACzB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACvB,OAAO;QACT,CAAC;IAEH,CAAC;CAAA;AA5BD,0CA4BC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processMethod = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const add_js_doc_1 = require("./add-js-doc");
|
|
6
|
+
const const_1 = require("./const");
|
|
7
|
+
const has_js_doc_1 = require("./has-js-doc");
|
|
8
|
+
const prompt_1 = require("./prompt");
|
|
9
|
+
function processMethod(options, methodDeclaration) {
|
|
10
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
console.log(`====== Process method: \x1b[36m${methodDeclaration.getName()}\x1b[0m`);
|
|
12
|
+
if ((0, has_js_doc_1.hasJsDoc)(methodDeclaration)) {
|
|
13
|
+
console.log(`\x1b[33mMethod has already a documentation\x1b[0m`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const methodText = methodDeclaration.getText();
|
|
17
|
+
try {
|
|
18
|
+
const jsDoc = yield (0, prompt_1.prompt)(options, const_1.METHOD_SYSTEM_PROMPT, methodText);
|
|
19
|
+
(0, add_js_doc_1.addJsDoc)(options, methodDeclaration, jsDoc);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.error(`\x1b[31mError processing method: \x1b[0m${methodDeclaration.getName()}`);
|
|
23
|
+
console.error(e.message);
|
|
24
|
+
console.error(e.stack);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.processMethod = processMethod;
|
|
30
|
+
//# sourceMappingURL=process-method.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-method.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/process-method.ts"],"names":[],"mappings":";;;;AAKA,6CAAwC;AACxC,mCAA+C;AAC/C,6CAAwC;AACxC,qCAAkC;AAGlC,SAAsB,aAAa,CACjC,OAAqC,EACrC,iBAAoC;;QAGpC,OAAO,CAAC,GAAG,CAAC,kCAAmC,iBAAiB,CAAC,OAAO,EAAG,SAAS,CAAC,CAAC;QAEtF,IAAI,IAAA,qBAAQ,EAAC,iBAAiB,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;YACjE,OAAO;QACT,CAAC;QAED,MAAM,UAAU,GAAG,iBAAiB,CAAC,OAAO,EAAE,CAAC;QAE/C,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,IAAA,eAAM,EACxB,OAAO,EACP,4BAAoB,EACpB,UAAU,CACX,CAAC;YAEF,IAAA,qBAAQ,EAAC,OAAO,EAAE,iBAAiB,EAAE,KAAK,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,2CAA4C,iBAAiB,CAAC,OAAO,EAAG,EAAE,CAAC,CAAC;YAC1F,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YACzB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACvB,OAAO;QACT,CAAC;IAEH,CAAC;CAAA;AA7BD,sCA6BC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processProject = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const workspace_ts_morph_1 = require("@rxap/workspace-ts-morph");
|
|
6
|
+
const ts_morph_1 = require("@rxap/ts-morph");
|
|
7
|
+
const workspace_utilities_1 = require("@rxap/workspace-utilities");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const const_1 = require("./const");
|
|
10
|
+
const process_source_file_1 = require("./process-source-file");
|
|
11
|
+
const skip_source_file_1 = require("./skip-source-file");
|
|
12
|
+
function processProject(options, projectName, tree) {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const projectSourceRoot = (0, workspace_utilities_1.GetProjectSourceRoot)(tree, projectName);
|
|
15
|
+
const project = (0, ts_morph_1.CreateProject)();
|
|
16
|
+
(0, workspace_ts_morph_1.AddDir)(tree, projectSourceRoot, project);
|
|
17
|
+
const start = Date.now();
|
|
18
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
19
|
+
if ((0, skip_source_file_1.skipSourceFile)(sourceFile, options.filter)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
yield (0, process_source_file_1.processSourceFile)(options, sourceFile);
|
|
24
|
+
(0, workspace_utilities_1.CoerceFile)(tree, (0, path_1.join)(projectSourceRoot, sourceFile.getFilePath()), sourceFile.getFullText(), true);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.error(`\x1b[31mError processing file: \x1b[0m${sourceFile.getFilePath()}`);
|
|
28
|
+
console.error(e.message);
|
|
29
|
+
console.error(e.stack);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
if (Date.now() - start > const_1.MAX_TIME) {
|
|
33
|
+
console.log(`\x1b[33mMax time reached: \x1b[0m${const_1.MAX_TIME}`);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.processProject = processProject;
|
|
40
|
+
//# sourceMappingURL=process-project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-project.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/process-project.ts"],"names":[],"mappings":";;;;AACA,iEAAkD;AAClD,6CAA+C;AAC/C,mEAGmC;AACnC,+BAA4B;AAC5B,mCAAmC;AACnC,+DAA0D;AAE1D,yDAAoD;AAEpD,SAAsB,cAAc,CAAC,O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
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processSourceFile = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const process_class_1 = require("./process-class");
|
|
6
|
+
const process_function_1 = require("./process-function");
|
|
7
|
+
function processSourceFile(options, sourceFile) {
|
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
console.log(`====== Process source file: \x1b[35m${sourceFile.getFilePath()}\x1b[0m`);
|
|
10
|
+
for (const functionDeclaration of sourceFile.getFunctions()) {
|
|
11
|
+
yield (0, process_function_1.processFunction)(options, functionDeclaration);
|
|
12
|
+
}
|
|
13
|
+
for (const classDeclaration of sourceFile.getClasses()) {
|
|
14
|
+
yield (0, process_class_1.processClass)(options, classDeclaration);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.processSourceFile = processSourceFile;
|
|
19
|
+
//# sourceMappingURL=process-source-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-source-file.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/process-source-file.ts"],"names":[],"mappings":";;;;AAIA,mDAA+C;AAC/C,yDAAqD;AAGrD,SAAsB,iBAAiB,CACrC,OAAqC,EACrC,UAAsB;;QAGtB,OAAO,CAAC,GAAG,CAAC,uCAAwC,UAAU,CAAC,WAAW,EAAG,SAAS,CAAC,CAAC;QAExF,KAAK,MAAM,mBAAmB,IAAI,UAAU,CAAC,YAAY,EAAE,EAAE,CAAC;YAC5D,MAAM,IAAA,kCAAe,EAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QACtD,CAAC;QAED,KAAK,MAAM,gBAAgB,IAAI,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC;YACvD,MAAM,IAAA,4BAAY,EAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAChD,CAAC;IAGH,CAAC;CAAA;AAhBD,8CAgBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function prompt(options: any, systemPrompt: string, prompt: string): Promise<string>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prompt = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const open_ai_instance_1 = require("./open-ai-instance");
|
|
6
|
+
const simple_prompt_1 = require("./simple-prompt");
|
|
7
|
+
function prompt(options, systemPrompt, prompt) {
|
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
if (options.offline) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
return (0, simple_prompt_1.SimplePrompt)(systemPrompt, prompt, (0, open_ai_instance_1.getOpenAi)());
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.prompt = prompt;
|
|
16
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/prompt.ts"],"names":[],"mappings":";;;;AAAA,yDAA+C;AAC/C,mDAA+C;AAE/C,SAAsB,MAAM,CAAC,OAAO,EAAE,YAAoB,EAAE,MAAc;;QAExE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,IAAA,4BAAY,EACjB,YAAY,EACZ,MAAM,EACN,IAAA,4BAAS,GAAE,CACZ,CAAC;IACJ,CAAC;CAAA;AAXD,wBAWC"}
|
|
@@ -23,6 +23,14 @@
|
|
|
23
23
|
"openaiApiKey": {
|
|
24
24
|
"type": "string",
|
|
25
25
|
"description": "The openai api key"
|
|
26
|
+
},
|
|
27
|
+
"openaiOrgId": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "The openai organization id"
|
|
30
|
+
},
|
|
31
|
+
"openaiProjectId": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"description": "The openai project id"
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
36
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { OpenAI } from 'openai';
|
|
2
|
+
import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions';
|
|
3
|
+
export type Model = 'whisper-1' | 'dall-e-2' | 'gpt-3.5-turbo-16k' | 'tts-1-hd-1106' | 'tts-1-hd' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-0125-preview' | 'gpt-4-turbo-preview' | 'gpt-4-turbo' | 'gpt-3.5-turbo-instruct-0914' | 'gpt-4o' | 'gpt-3.5-turbo-instruct' | 'text-embedding-3-small' | 'tts-1' | 'gpt-4' | 'text-embedding-3-large' | 'gpt-4-1106-preview' | 'babbage-002' | 'gpt-4-0613' | 'gpt-3.5-turbo-0125' | 'tts-1-1106' | 'dall-e-3' | 'text-embedding-ada-002' | 'davinci-002' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'gpt-4o-2024-05-13';
|
|
4
|
+
export interface SimplePromptOptions {
|
|
3
5
|
max_tokens?: number;
|
|
4
|
-
model?:
|
|
6
|
+
model?: Model;
|
|
5
7
|
}
|
|
6
|
-
export declare function
|
|
8
|
+
export declare function IsAllDefined(options: SimplePromptOptions): options is Required<SimplePromptOptions>;
|
|
9
|
+
export declare function AssertAllDefined(options: SimplePromptOptions): asserts options is Required<SimplePromptOptions>;
|
|
10
|
+
export declare function SimplePrompt(systemPrompt: string, prompt: string, openai: OpenAI, options?: Partial<ChatCompletionCreateParamsBase>): Promise<string>;
|
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimplePrompt = void 0;
|
|
3
|
+
exports.SimplePrompt = exports.AssertAllDefined = exports.IsAllDefined = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const gpt_3_encoder_1 = require("gpt-3-encoder");
|
|
6
6
|
const tokenLimits = {
|
|
7
|
+
'gpt-4-4o': 128000,
|
|
8
|
+
'gpt-4-turbo': 128000,
|
|
7
9
|
'gpt-4': 8192,
|
|
8
10
|
'gpt-3.5-turbo': 4096,
|
|
9
11
|
'gpt-3.5-turbo-16k': 16384,
|
|
10
12
|
};
|
|
13
|
+
function IsAllDefined(options) {
|
|
14
|
+
return options.max_tokens !== undefined && options.model !== undefined;
|
|
15
|
+
}
|
|
16
|
+
exports.IsAllDefined = IsAllDefined;
|
|
17
|
+
function AssertAllDefined(options) {
|
|
18
|
+
if (!IsAllDefined(options)) {
|
|
19
|
+
throw new Error(`\x1b[31mOptions are not all defined\x1b[0m`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.AssertAllDefined = AssertAllDefined;
|
|
11
23
|
function SimplePrompt(systemPrompt_1, prompt_1, openai_1) {
|
|
12
24
|
return tslib_1.__awaiter(this, arguments, void 0, function* (systemPrompt, prompt, openai, options = {
|
|
13
25
|
max_tokens: 1024,
|
|
14
|
-
model: 'gpt-4',
|
|
26
|
+
model: 'gpt-4-turbo',
|
|
15
27
|
}) {
|
|
16
28
|
var _a, _b, _c, _d;
|
|
17
29
|
const systemPromptLength = (0, gpt_3_encoder_1.encode)(systemPrompt).length;
|
|
18
30
|
const promptLength = (0, gpt_3_encoder_1.encode)(prompt).length;
|
|
19
31
|
const inputLength = Math.floor((systemPromptLength + promptLength) * 1.1);
|
|
20
|
-
(_a = options.model) !== null && _a !== void 0 ? _a : (options.model = 'gpt-
|
|
32
|
+
(_a = options.model) !== null && _a !== void 0 ? _a : (options.model = 'gpt-4o');
|
|
21
33
|
(_b = options.max_tokens) !== null && _b !== void 0 ? _b : (options.max_tokens = 1024);
|
|
22
34
|
if (!tokenLimits[options.model]) {
|
|
23
35
|
throw new Error(`\x1b[31mModel '${options.model}' is not supported.\x1b[0m`);
|
|
@@ -36,7 +48,10 @@ function SimplePrompt(systemPrompt_1, prompt_1, openai_1) {
|
|
|
36
48
|
}
|
|
37
49
|
let content;
|
|
38
50
|
try {
|
|
39
|
-
const response = yield openai.
|
|
51
|
+
const response = yield openai.chat.completions.create({
|
|
52
|
+
max_tokens: options.max_tokens,
|
|
53
|
+
model: options.model,
|
|
54
|
+
messages: [
|
|
40
55
|
{
|
|
41
56
|
'role': 'system',
|
|
42
57
|
'content': systemPrompt,
|
|
@@ -45,8 +60,13 @@ function SimplePrompt(systemPrompt_1, prompt_1, openai_1) {
|
|
|
45
60
|
'role': 'user',
|
|
46
61
|
'content': prompt,
|
|
47
62
|
},
|
|
48
|
-
],
|
|
49
|
-
|
|
63
|
+
],
|
|
64
|
+
temperature: 0,
|
|
65
|
+
top_p: 1,
|
|
66
|
+
frequency_penalty: 0,
|
|
67
|
+
presence_penalty: 0,
|
|
68
|
+
});
|
|
69
|
+
content = (_c = response.choices[0].message) === null || _c === void 0 ? void 0 : _c.content;
|
|
50
70
|
}
|
|
51
71
|
catch (e) {
|
|
52
72
|
console.log((_d = e.response) === null || _d === void 0 ? void 0 : _d.data);
|
|
@@ -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":";;;;AAAA,iDAAuC;AAIvC,MAAM,WAAW,GAAG;IAClB,UAAU,EAAE,MAAO;IACnB,aAAa,EAAE,MAAO;IACtB,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,IAAI;IACrB,mBAAmB,EAAE,KAAK;CAC3B,CAAC;AASF,SAAgB,YAAY,CAAC,OAA4B;IACvD,OAAO,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,CA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SourceFile(sourceFile, filter) {
|
|
5
|
+
if (sourceFile.getBaseName() === 'index.ts') {
|
|
6
|
+
// console.log(`\x1b[33mSkip index file: \x1b[0m${ sourceFile.getFilePath() }`);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (sourceFile.getBaseName().endsWith('.spec.ts')) {
|
|
10
|
+
// console.log(`\x1b[33mSkip spec file: \x1b[0m${ sourceFile.getFilePath() }`);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (sourceFile.getBaseName().endsWith('.stories.ts')) {
|
|
14
|
+
// console.log(`\x1b[33mSkip stories file: \x1b[0m${ sourceFile.getFilePath() }`);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (sourceFile.getBaseName().endsWith('.cy.ts')) {
|
|
18
|
+
// console.log(`\x1b[33mSkip cypress file: \x1b[0m${ sourceFile.getFilePath() }`);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (filter) {
|
|
22
|
+
if (!sourceFile.getFilePath().includes(filter)) {
|
|
23
|
+
// console.log(`\x1b[33mSkip file: \x1b[0m${ sourceFile.getFilePath() }`);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
exports.skipSourceFile = skipSourceFile;
|
|
30
|
+
//# sourceMappingURL=skip-source-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-source-file.js","sourceRoot":"","sources":["../../../../../../../packages/plugin/gpt/src/generators/documentation/skip-source-file.ts"],"names":[],"mappings":";;;AAEA,SAAgB,cAAc,CAAC,UAAsB,EAAE,MAAe;IACpE,IAAI,UAAU,CAAC,WAAW,EAAE,KAAK,UAAU,EAAE,CAAC;QAC5C,gFAAgF;QAChF,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAClD,+EAA+E;QAC/E,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;QACrD,kFAAkF;QAClF,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChD,kFAAkF;QAClF,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC/C,0EAA0E;YAC1E,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAxBD,wCAwBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
You're a software developer with a particular task at hand: to generate succinct, insightful, and comprehensive documentation for a TypeScript
|
|
1
|
+
You're a software developer with a particular task at hand: to generate succinct, insightful, and comprehensive documentation for a TypeScript functions. Your work should be presented in the form of a documentation comment. Please note, the output of your task should solely consist of the documentation comment, excluding any code or non-documentation elements. Remember not to alter the logic of the function - your main focus is on producing precise and understandable documentation. The TypeScript function to be documented is outlined below:
|