@rxap/plugin-gpt 16.0.1-dev.0

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 ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 16.0.1-dev.0 (2023-08-01)
7
+
8
+ **Note:** Version bump only for package @rxap/plugin-gpt
package/GETSTARTED.md ADDED
File without changes
package/GUIDES.md ADDED
File without changes
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @rxap/plugin-gpt
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@rxap/plugin-gpt?style=flat-square)](https://www.npmjs.com/package/@rxap/plugin-gpt)
4
+ [![commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](https://commitizen.github.io/cz-cli/)
5
+ [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
6
+ ![Libraries.io dependency status for latest release, scoped npm package](https://img.shields.io/librariesio/release/npm/@rxap/plugin-gpt)
7
+ ![npm](https://img.shields.io/npm/dm/@rxap/plugin-gpt)
8
+ ![NPM](https://img.shields.io/npm/l/@rxap/plugin-gpt)
9
+
10
+ - [Installation](#installation)
11
+ - [Generators](#generators)
12
+
13
+ # Installation
14
+
15
+ **Add the package to your workspace:**
16
+ ```bash
17
+ yarn add @rxap/plugin-gpt
18
+ ```
19
+ **Install peer dependencies:**
20
+ ```bash
21
+ yarn add
22
+ ```
23
+ # Generators
24
+
25
+ ## documentation
26
+ > documentation generator
27
+
28
+ ```bash
29
+ yarn nx g @rxap/plugin-gpt:documentation
30
+ ```
@@ -0,0 +1,9 @@
1
+ {
2
+ "generators": {
3
+ "documentation": {
4
+ "factory": "./src/generators/documentation/generator",
5
+ "schema": "./src/generators/documentation/schema.json",
6
+ "description": "documentation generator"
7
+ }
8
+ }
9
+ }
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@rxap/plugin-gpt",
3
+ "version": "16.0.1-dev.0",
4
+ "type": "commonjs",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "directory": "../../../dist/packages/plugin/gpt"
8
+ },
9
+ "keywords": [
10
+ "rxap",
11
+ "plugin",
12
+ "nx",
13
+ "nx-plugin",
14
+ "gpt",
15
+ "openai",
16
+ "packages"
17
+ ],
18
+ "homepage": "https:/gitlab.com/rxap/packages/packages/plugin/gpt",
19
+ "bugs": {
20
+ "url": "https://gitlab.com/rxap/packages/-/issues",
21
+ "email": "incoming+rxap-packages-14898188-issue-@incoming.gitlab.com"
22
+ },
23
+ "license": "GPL-3.0-or-later",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://gitlab.com/rxap/packages.git",
27
+ "directory": "packages/plugin/gpt"
28
+ },
29
+ "author": {
30
+ "name": "Merzough Münker",
31
+ "email": "mmuenker@digitaix.com"
32
+ },
33
+ "generators": "./generators.json",
34
+ "dependencies": {
35
+ "ignore": "^5.2.4",
36
+ "process": "0.11.10",
37
+ "semver": "^7.3.5",
38
+ "tslib": "2.6.1"
39
+ },
40
+ "peerDependencies": {
41
+ "@nx/devkit": "^16.5.0",
42
+ "@rxap/generator-ts-morph": "^1.0.1-dev.2",
43
+ "@rxap/generator-utilities": "^1.0.1-dev.2",
44
+ "gpt-3-encoder": "^1.1.4",
45
+ "openai": "^3.3.0",
46
+ "ts-morph": "^18.0.0",
47
+ "@rxap/node-utilities": "1.0.1-dev.2",
48
+ "@rxap/utilities": "16.0.0-dev.4",
49
+ "@rxap/workspace-ts-morph": "0.0.2-dev.0",
50
+ "@rxap/workspace-utilities": "0.1.0-dev.0"
51
+ },
52
+ "nx-migrations": {
53
+ "packageGroup": [
54
+ {
55
+ "package": "@rxap/generator-ts-morph",
56
+ "version": "1.0.1-dev.2"
57
+ },
58
+ {
59
+ "package": "@rxap/generator-utilities",
60
+ "version": "1.0.1-dev.2"
61
+ }
62
+ ]
63
+ },
64
+ "gitHead": "ed3a0788894aa734ec2a8e9e957cf73cabe033d6",
65
+ "main": "./src/index.js",
66
+ "types": "./src/index.d.ts"
67
+ }
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { DocumentationGeneratorSchema } from './schema';
3
+ export declare function documentationGenerator(tree: Tree, options: DocumentationGeneratorSchema): Promise<void>;
4
+ export default documentationGenerator;
@@ -0,0 +1,194 @@
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");
14
+ 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);
17
+ }
18
+ function loadSystemPrompt(name) {
19
+ const filePath = (0, path_1.join)(__dirname, 'system-prompts', `${name}.txt`);
20
+ if (!(0, fs_1.existsSync)(filePath)) {
21
+ throw new Error(`Can not find system prompt file '${filePath}'`);
22
+ }
23
+ return (0, fs_1.readFileSync)(filePath).toString();
24
+ }
25
+ const FUNCTION_SYSTEM_PROMPT = loadSystemPrompt('function');
26
+ const METHOD_SYSTEM_PROMPT = loadSystemPrompt('method');
27
+ const CLASS_SYSTEM_PROMPT = loadSystemPrompt('class');
28
+ function hasJsDoc(node) {
29
+ return node.getJsDocs().length > 0;
30
+ }
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
+ });
38
+ }
39
+ function cleanupJsDoc(jsDoc) {
40
+ const cleanJsDocArray = jsDoc
41
+ .split('\n')
42
+ .map(line => line
43
+ .trim()
44
+ .replace(/^\/\*\*/, '')
45
+ .replace(/^\s?\*\//, '')
46
+ .replace(/^\s?\*\s?/, '')
47
+ .trim());
48
+ cleanJsDocArray.pop();
49
+ return cleanJsDocArray.join('\n');
50
+ }
51
+ function addJsDoc(options, node, jsDoc) {
52
+ if (options.offline) {
53
+ return;
54
+ }
55
+ node.addJsDoc(cleanupJsDoc(jsDoc));
56
+ }
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
+ });
73
+ }
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
+ }
84
+ }
85
+ return changed;
86
+ });
87
+ }
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
+ });
104
+ }
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
+ });
119
+ }
120
+ function skipSourceFile(sourceFile) {
121
+ if (sourceFile.getBaseName() === 'index.ts') {
122
+ // console.log(`\x1b[33mSkip index file: \x1b[0m${ sourceFile.getFilePath() }`);
123
+ return true;
124
+ }
125
+ if (sourceFile.getBaseName().endsWith('.spec.ts')) {
126
+ // console.log(`\x1b[33mSkip spec file: \x1b[0m${ sourceFile.getFilePath() }`);
127
+ return true;
128
+ }
129
+ if (sourceFile.getBaseName().endsWith('.stories.ts')) {
130
+ // console.log(`\x1b[33mSkip stories file: \x1b[0m${ sourceFile.getFilePath() }`);
131
+ return true;
132
+ }
133
+ if (sourceFile.getBaseName().endsWith('.cy.ts')) {
134
+ // console.log(`\x1b[33mSkip cypress file: \x1b[0m${ sourceFile.getFilePath() }`);
135
+ return true;
136
+ }
137
+ return false;
138
+ }
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;
170
+ }
171
+ }
172
+ });
173
+ }
174
+ function skipProject(project, projectName, options) {
175
+ var _a;
176
+ if ((_a = options.projects) === null || _a === void 0 ? void 0 : _a.length) {
177
+ return !options.projects.includes(projectName);
178
+ }
179
+ return false;
180
+ }
181
+ 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);
189
+ }
190
+ });
191
+ }
192
+ exports.documentationGenerator = documentationGenerator;
193
+ exports.default = documentationGenerator;
194
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugin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C,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"}
@@ -0,0 +1,4 @@
1
+ export interface DocumentationGeneratorSchema {
2
+ projects: string[];
3
+ offline: boolean;
4
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "Documentation",
4
+ "title": "",
5
+ "type": "object",
6
+ "properties": {
7
+ "projects": {
8
+ "alias": "project",
9
+ "type": "array",
10
+ "description": "A list of projects where the documentation should be generated",
11
+ "items": {
12
+ "type": "string"
13
+ }
14
+ },
15
+ "offline": {
16
+ "type": "boolean",
17
+ "description": "If true, the openai api is not used"
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,6 @@
1
+ import { OpenAIApi } from 'openai';
2
+ export interface SimplePromtOptions {
3
+ max_tokens?: number;
4
+ model?: 'gpt-4' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k';
5
+ }
6
+ export declare function SimplePrompt(systemPrompt: string, prompt: string, openai: OpenAIApi, options?: SimplePromtOptions): Promise<string>;
@@ -0,0 +1,62 @@
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");
6
+ const tokenLimits = {
7
+ 'gpt-4': 8192,
8
+ 'gpt-3.5-turbo': 4096,
9
+ 'gpt-3.5-turbo-16k': 16384,
10
+ };
11
+ function SimplePrompt(systemPrompt, prompt, openai, options = {
12
+ max_tokens: 1024,
13
+ model: 'gpt-4',
14
+ }) {
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`);
24
+ }
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
+ }
61
+ exports.SimplePrompt = SimplePrompt;
62
+ //# sourceMappingURL=simple-prompt.js.map
@@ -0,0 +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,GA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,KAAK,CAAC,oBAAoB,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;SACnD;QAED,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;SACpE;QAED,OAAO,OAAO,CAAC;;CAEhB;AAxED,oCAwEC"}
@@ -0,0 +1 @@
1
+ You're a software developer with a particular task at hand: to generate succinct, insightful, and comprehensive documentation for a TypeScript class methods. 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 or analyze the logic of the class method - your main focus is on producing precise and understandable documentation. The TypeScript class method to be documented is outlined below:
package/src/index.d.ts ADDED
File without changes
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/plugin/gpt/src/index.ts"],"names":[],"mappings":""}