@rxap/plugin-gpt 16.0.1-dev.2 → 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 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.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
+
6
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)
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.3 @rxap/generator-utilities@^1.1.0-dev.2 gpt-3-encoder@^1.1.4 openai@^3.3.0 ts-morph@^18.0.0
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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rxap/plugin-gpt",
3
- "version": "16.0.1-dev.2",
4
- "type": "commonjs",
3
+ "version": "16.0.1-dev.3",
4
+ "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "directory": "../../../dist/packages/plugin/gpt"
@@ -40,14 +40,14 @@
40
40
  "peerDependencies": {
41
41
  "@nx/devkit": "^16.5.0",
42
42
  "@rxap/generator-ts-morph": "^1.0.1-dev.3",
43
- "@rxap/generator-utilities": "^1.1.0-dev.2",
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.1",
48
- "@rxap/utilities": "16.0.0-dev.6",
49
- "@rxap/workspace-ts-morph": "0.1.0-dev.0",
50
- "@rxap/workspace-utilities": "0.1.0-dev.3"
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": [
@@ -57,12 +57,12 @@
57
57
  },
58
58
  {
59
59
  "package": "@rxap/generator-utilities",
60
- "version": "1.1.0-dev.2"
60
+ "version": "1.1.0-dev.4"
61
61
  }
62
62
  ]
63
63
  },
64
64
  "schematics": "./generators.json",
65
- "gitHead": "8f010d8945a8bd56c8968c2af129b1e0b2f656cf",
65
+ "gitHead": "bbab80e59acbe435a02e69c9fec022780cf4640d",
66
66
  "main": "./src/index.js",
67
67
  "types": "./src/index.d.ts"
68
68
  }
@@ -1,26 +1,25 @@
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");
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 openai_1.Configuration(Object.assign(Object.assign({}, param), { apiKey: process.env.OPENAI_API_KEY }));
16
- return new openai_1.OpenAIApi(configuration);
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 = (0, path_1.join)(__dirname, 'system-prompts', `${name}.txt`);
20
- if (!(0, fs_1.existsSync)(filePath)) {
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 (0, fs_1.readFileSync)(filePath).toString();
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
- 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
- });
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
- 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
- });
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
- 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
- }
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
- return changed;
86
- });
78
+ }
79
+ return changed;
87
80
  }
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
- });
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
- 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
- });
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
- 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;
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
- var _a;
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
- 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);
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
- exports.documentationGenerator = documentationGenerator;
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":";;;;AAAA,uCAIoB;AAEpB,uCASkB;AAClB,iEAAkD;AAClD,mEAAiE;AACjE,mCAAmC;AACnC,mCAIgB;AAChB,mDAA+C;AAC/C,+BAA4B;AAC5B,2BAGY;AAEZ,SAAS,SAAS,CAAC,QAAiD,EAAE;IAGpE,MAAM,aAAa,GAAG,IAAI,sBAAa,iCAClC,KAAK,KACR,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,IAClC,CAAC;IACH,OAAO,IAAI,kBAAS,CAAC,aAAa,CAAC,CAAC;AAEtC,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY;IACpC,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,gBAAgB,EAAE,GAAI,IAAK,MAAM,CAAC,CAAC;IACpE,IAAI,CAAC,IAAA,eAAU,EAAC,QAAQ,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,oCAAqC,QAAS,GAAG,CAAC,CAAC;KACpE;IACD,OAAO,IAAA,iBAAY,EAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC3C,CAAC;AAED,MAAM,sBAAsB,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAC5D,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AACxD,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAEtD,SAAS,QAAQ,CAAC,IAAmB;IACnC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AACrC,CAAC;AAED,SAAe,MAAM,CAAC,OAAO,EAAE,YAAoB,EAAE,MAAc;;QAEjE,IAAI,OAAO,CAAC,OAAO,EAAE;YACnB,OAAO,EAAE,CAAC;SACX;QAED,OAAO,IAAA,4BAAY,EACj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GAAG,EAAE,GAAG,KAAK,GAAG,QAAQ,EAAE;gBACjC,OAAO,CAAC,GAAG,CAAC,oCAAqC,QAAS,EAAE,CAAC,CAAC;gBAC9D,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
+ {"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,MAA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M;SACP;KACF;AAEH,CAAC;AAED,SAAS,WAAW,CAAC,OAA6B,EAAE,WAAmB,EAAE,OAAqC;IAE5G,IAAI,OAAO,CAAC,QAAQ,EAAE,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,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"}
@@ -1,7 +1,5 @@
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;
1
+ import { convertNxGenerator } from '@nx/devkit';
2
+ import generator from './generator';
3
+ const schematic = convertNxGenerator(generator);
4
+ export default schematic;
7
5
  //# 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,uCAAgD;AAChD,2CAAoC;AAEpC,MAAM,SAAS,GAAG,IAAA,2BAAkB,EAAC,mBAAS,CAAC,CAAC;AAChD,kBAAe,SAAS,CAAC"}
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
- "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");
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
- 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`);
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
- 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
- });
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":";;;;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,CAAC,KAAK,CAAC,CAAC,kBAAkB,GAAG,YAAY,CAAC,GAAG,GAAG,CAAC,CAAC;QAE1E,MAAA,OAAO,CAAC,KAAK,oCAAb,OAAO,CAAC,KAAK,GAAK,OAAO,EAAC;QAC1B,MAAA,OAAO,CAAC,UAAU,oCAAlB,OAAO,CAAC,UAAU,GAAK,IAAI,EAAC;QAE5B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,kBAAmB,OAAO,CAAC,KAAM,4BAA4B,CAAC,CA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ED,OAAO,OAAO,CAAC;;CAEhB;AAxED,oCAwEC"}
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;CAC3B,CAAC;AAOF,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,YAAoB,EACpB,MAAc,EACd,MAAiB,EACjB,UAA8B;IAC5B,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,OAAO;CACf;IAID,MAAM,kBAAkB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC;IACvD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;IAE3C,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,kBAAkB,GAAG,YAAY,CAAC,GAAG,GAAG,CAAC,CAAC;IAE1E,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC;IAC1B,OAAO,CAAC,UAAU,KAAK,IAAI,CAAC;IAE5B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,kBAAmB,OAAO,CAAC,KAAM,4BAA4B,CAAC,CAAC;KAChF;IAED,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE9C,IAAI,WAAW,GAAG,UAAU,GAAG,GAAG,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,yBAA0B,WAAY,wCAAyC,UAAU;YACzG,GAAI,SAAS,CAAC,CAAC;KAChB;IAED,IAAI,OAAO,CAAC,UAAU,EAAE;QACtB,IAAI,OAAO,CAAC,UAAU,GAAG,UAAU,GAAG,WAAW,EAAE;YACjD,OA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