| import * as axios from 'axios'; | ||
| import * as openai from 'openai'; | ||
| import { Struct } from 'superstruct'; | ||
| declare class Writebot { | ||
| private static types; | ||
| private static openai; | ||
| static initialize({ apiKey, types }: { | ||
| apiKey: string; | ||
| types?: any[]; | ||
| }): void; | ||
| static write(type: WriterType | string, params: unknown): Promise<axios.AxiosResponse<openai.CreateCompletionResponse, any>>; | ||
| } | ||
| type WriterType = { | ||
| makeQuery: (params: unknown) => string; | ||
| config: { | ||
| type: string; | ||
| params: Struct<any, object>; | ||
| }; | ||
| }; | ||
| export { Writebot, WriterType }; |
+102
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var __async = (__this, __arguments, generator) => { | ||
| return new Promise((resolve, reject) => { | ||
| var fulfilled = (value) => { | ||
| try { | ||
| step(generator.next(value)); | ||
| } catch (e) { | ||
| reject(e); | ||
| } | ||
| }; | ||
| var rejected = (value) => { | ||
| try { | ||
| step(generator.throw(value)); | ||
| } catch (e) { | ||
| reject(e); | ||
| } | ||
| }; | ||
| var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); | ||
| step((generator = generator.apply(__this, __arguments)).next()); | ||
| }); | ||
| }; | ||
| // Writebot.ts | ||
| var Writebot_exports = {}; | ||
| __export(Writebot_exports, { | ||
| Writebot: () => Writebot | ||
| }); | ||
| module.exports = __toCommonJS(Writebot_exports); | ||
| var import_superstruct = require("superstruct"); | ||
| // openai.ts | ||
| var import_openai = require("openai"); | ||
| var OpenAI = class { | ||
| constructor(apiKey) { | ||
| this.createDavinciCompletion = (_0) => __async(this, [_0], function* ({ prompt, maxToken = 144, temperature = 0.7 }) { | ||
| return yield this.openai.createCompletion({ | ||
| model: "text-davinci-003", | ||
| prompt, | ||
| temperature, | ||
| max_tokens: maxToken | ||
| }); | ||
| }); | ||
| const configuration = new import_openai.Configuration({ | ||
| apiKey | ||
| }); | ||
| this.openai = new import_openai.OpenAIApi(configuration); | ||
| } | ||
| }; | ||
| // Writebot.ts | ||
| var Writebot = class { | ||
| static initialize({ apiKey, types }) { | ||
| this.openai = new OpenAI(apiKey); | ||
| this.types = types ? types : null; | ||
| } | ||
| static write(type, params) { | ||
| return __async(this, null, function* () { | ||
| var _a; | ||
| let writerType; | ||
| if (typeof type === "string") { | ||
| writerType = (_a = Writebot.types) == null ? void 0 : _a.find((value) => value.config.type === type); | ||
| if (writerType === void 0) { | ||
| throw new Error(`Type ${type} not found.`); | ||
| } | ||
| } else { | ||
| writerType = type; | ||
| } | ||
| try { | ||
| const writerParams = writerType.config.params; | ||
| (0, import_superstruct.assert)(params, writerParams); | ||
| } catch (e) { | ||
| if (e instanceof import_superstruct.StructError) { | ||
| const { message } = e; | ||
| throw new Error(`Typing verification for type ${writerType.config.type} failed. ${message}.`); | ||
| } | ||
| } | ||
| const prompt = writerType.makeQuery(params); | ||
| return this.openai.createDavinciCompletion({ prompt }); | ||
| }); | ||
| } | ||
| }; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Writebot | ||
| }); |
+41
| import { assert, Infer, Struct, StructError } from 'superstruct'; | ||
| import { OpenAI } from './openai'; | ||
| export class Writebot { | ||
| private static types: WriterType[] | null; | ||
| private static openai: OpenAI; | ||
| static initialize({ apiKey, types }: { apiKey: string, types?: any[] }) { | ||
| this.openai = new OpenAI(apiKey); | ||
| this.types = types ? types : null; | ||
| } | ||
| static async write(type: WriterType | string, params: unknown) { | ||
| let writerType; | ||
| if (typeof type === 'string') { | ||
| writerType = Writebot.types?.find(value => value.config.type === type); | ||
| if (writerType === undefined) { | ||
| throw new Error(`Type ${type} not found.`); | ||
| } | ||
| } else { | ||
| writerType = type; | ||
| } | ||
| try { | ||
| const writerParams = writerType.config.params; | ||
| assert(params, writerParams); | ||
| } catch (e: unknown) { | ||
| if (e instanceof StructError) { | ||
| const { message } = e; | ||
| throw new Error(`Typing verification for type ${writerType.config.type} failed. ${message}.`); | ||
| } | ||
| } | ||
| const prompt = writerType.makeQuery(params as Infer<typeof writerType.config.params>); | ||
| return this.openai.createDavinciCompletion({ prompt }); | ||
| } | ||
| } | ||
| export type WriterType= { makeQuery: (params: unknown) => string, config: { type: string, params: Struct<any, object> } }; |
+14
-14
| $ tsup *.ts --format cjs --dts | ||
| CLI Building entry: Writer.ts, index.ts, openai.ts | ||
| CLI Using tsconfig: tsconfig.json | ||
| CLI tsup v6.5.0 | ||
| CLI Target: es6 | ||
| CJS Build start | ||
| CJS dist/index.js 3.18 KB | ||
| CJS dist/Writer.js 3.16 KB | ||
| CJS dist/openai.js 2.06 KB | ||
| CJS ⚡️ Build success in 44ms | ||
| DTS Build start | ||
| DTS ⚡️ Build success in 1559ms | ||
| DTS dist/Writer.d.ts 596.00 B | ||
| DTS dist/index.d.ts 105.00 B | ||
| DTS dist/openai.d.ts 447.00 B | ||
| [34mCLI[39m Building entry: Writebot.ts, index.ts, openai.ts | ||
| [34mCLI[39m Using tsconfig: tsconfig.json | ||
| [34mCLI[39m tsup v6.5.0 | ||
| [34mCLI[39m Target: es6 | ||
| [34mCJS[39m Build start | ||
| [32mCJS[39m [1mdist/Writebot.js [22m[32m3.18 KB[39m | ||
| [32mCJS[39m [1mdist/index.js [22m[32m3.22 KB[39m | ||
| [32mCJS[39m [1mdist/openai.js [22m[32m2.06 KB[39m | ||
| [32mCJS[39m ⚡️ Build success in 104ms | ||
| [34mDTS[39m Build start | ||
| [32mDTS[39m ⚡️ Build success in 6679ms | ||
| [32mDTS[39m [1mdist/Writebot.d.ts [22m[32m600.00 B[39m | ||
| [32mDTS[39m [1mdist/index.d.ts [22m[32m130.00 B[39m | ||
| [32mDTS[39m [1mdist/openai.d.ts [22m[32m447.00 B[39m |
+15
-17
| $ TIMING=1 eslint "**/*.ts*" | ||
| (node:17829) [ESLINT_LEGACY_ECMAFEATURES] DeprecationWarning: The 'ecmaFeatures' config file property is deprecated and has no effect. (found in "../../.eslintrc.js » eslint-config-custom") | ||
| (node:1971) [ESLINT_LEGACY_ECMAFEATURES] DeprecationWarning: The 'ecmaFeatures' config file property is deprecated and has no effect. (found in "../../.eslintrc.js » eslint-config-custom") | ||
| (Use `node --trace-deprecation ...` to show where the warning was created) | ||
| /home/samy/Programming/dev/writer.js/packages/writebot/Writer.ts | ||
| 1:25 warning 'object' is defined but never used @typescript-eslint/no-unused-vars | ||
| 1:33 warning 'string' is defined but never used @typescript-eslint/no-unused-vars | ||
| /home/runner/work/writerbot/writerbot/packages/writebot/Writebot.ts | ||
| 8:66 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any | ||
| 41:106 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any | ||
| /home/samy/Programming/dev/writer.js/packages/writebot/dist/Writer.d.ts | ||
| /home/runner/work/writerbot/writerbot/packages/writebot/dist/Writebot.d.ts | ||
| 10:17 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any | ||
@@ -16,18 +14,18 @@ 12:124 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any | ||
| /home/samy/Programming/dev/writer.js/packages/writebot/dist/openai.d.ts | ||
| /home/runner/work/writerbot/writerbot/packages/writebot/dist/openai.d.ts | ||
| 12:149 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any | ||
| ✖ 8 problems (0 errors, 8 warnings) | ||
| ✖ 6 problems (0 errors, 6 warnings) | ||
| Rule | Time (ms) | Relative | ||
| :-----------------------------------------------|----------:|--------: | ||
| @typescript-eslint/no-unused-vars | 37.017 | 70.8% | ||
| react/display-name | 2.949 | 5.6% | ||
| object-curly-spacing | 1.179 | 2.3% | ||
| react/no-direct-mutation-state | 1.179 | 2.3% | ||
| react/require-render-return | 1.089 | 2.1% | ||
| @typescript-eslint/object-curly-spacing | 0.931 | 1.8% | ||
| @typescript-eslint/no-explicit-any | 0.855 | 1.6% | ||
| @typescript-eslint/adjacent-overload-signatures | 0.688 | 1.3% | ||
| @typescript-eslint/no-loss-of-precision | 0.605 | 1.2% | ||
| prefer-const | 0.517 | 1.0% | ||
| @typescript-eslint/no-unused-vars | 14.654 | 45.1% | ||
| react/display-name | 3.538 | 10.9% | ||
| react/no-direct-mutation-state | 1.529 | 4.7% | ||
| object-curly-spacing | 1.393 | 4.3% | ||
| @typescript-eslint/object-curly-spacing | 1.089 | 3.4% | ||
| react/require-render-return | 1.050 | 3.2% | ||
| @typescript-eslint/no-explicit-any | 0.998 | 3.1% | ||
| @typescript-eslint/adjacent-overload-signatures | 0.750 | 2.3% | ||
| @typescript-eslint/no-loss-of-precision | 0.701 | 2.2% | ||
| @typescript-eslint/no-empty-function | 0.610 | 1.9% |
+6
-0
| # writerjs | ||
| ## 0.3.0 | ||
| ### Minor Changes | ||
| - f648bba: Changed default export and naming | ||
| ## 0.2.0 | ||
@@ -4,0 +10,0 @@ |
+1
-1
@@ -1,4 +0,4 @@ | ||
| export { Writer, WriterType } from './Writer.js'; | ||
| export { Writebot, WriterType, Writebot as default } from './Writebot.js'; | ||
| import 'axios'; | ||
| import 'openai'; | ||
| import 'superstruct'; |
+7
-6
@@ -43,7 +43,8 @@ "use strict"; | ||
| __export(writebot_exports, { | ||
| Writer: () => Writer | ||
| Writebot: () => Writebot, | ||
| default: () => Writebot | ||
| }); | ||
| module.exports = __toCommonJS(writebot_exports); | ||
| // Writer.ts | ||
| // Writebot.ts | ||
| var import_superstruct = require("superstruct"); | ||
@@ -70,4 +71,4 @@ | ||
| // Writer.ts | ||
| var Writer = class { | ||
| // Writebot.ts | ||
| var Writebot = class { | ||
| static initialize({ apiKey, types }) { | ||
@@ -82,3 +83,3 @@ this.openai = new OpenAI(apiKey); | ||
| if (typeof type === "string") { | ||
| writerType = (_a = Writer.types) == null ? void 0 : _a.find((value) => value.config.type === type); | ||
| writerType = (_a = Writebot.types) == null ? void 0 : _a.find((value) => value.config.type === type); | ||
| if (writerType === void 0) { | ||
@@ -106,3 +107,3 @@ throw new Error(`Type ${type} not found.`); | ||
| 0 && (module.exports = { | ||
| Writer | ||
| Writebot | ||
| }); |
+2
-1
@@ -1,1 +0,2 @@ | ||
| export * from './Writer'; | ||
| export * from './Writebot'; | ||
| export { Writebot as default } from './Writebot'; |
+1
-1
| { | ||
| "name": "writebot", | ||
| "version": "0.2.0", | ||
| "version": "0.3.0", | ||
| "main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
| $ TIMING=1 eslint "**/*.ts*" --fix | ||
| (node:76467) [ESLINT_LEGACY_ECMAFEATURES] DeprecationWarning: The 'ecmaFeatures' config file property is deprecated and has no effect. (found in "../../.eslintrc.js » eslint-config-custom") | ||
| (Use `node --trace-deprecation ...` to show where the warning was created) | ||
| /home/samy/Programming/dev/writer.js/packages/writerjs/Writer.ts | ||
| 1:25 warning 'object' is defined but never used @typescript-eslint/no-unused-vars | ||
| 1:33 warning 'string' is defined but never used @typescript-eslint/no-unused-vars | ||
| 41:106 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any | ||
| /home/samy/Programming/dev/writer.js/packages/writerjs/dist/Writer.d.ts | ||
| 12:124 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any | ||
| 18:24 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any | ||
| /home/samy/Programming/dev/writer.js/packages/writerjs/dist/openai.d.ts | ||
| 12:149 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any | ||
| ✖ 6 problems (0 errors, 6 warnings) | ||
| Rule | Time (ms) | Relative | ||
| :-----------------------------------------------|----------:|--------: | ||
| @typescript-eslint/no-unused-vars | 10.322 | 45.1% | ||
| react/display-name | 2.565 | 11.2% | ||
| object-curly-spacing | 1.040 | 4.5% | ||
| react/no-direct-mutation-state | 0.899 | 3.9% | ||
| react/require-render-return | 0.808 | 3.5% | ||
| @typescript-eslint/object-curly-spacing | 0.762 | 3.3% | ||
| @typescript-eslint/no-explicit-any | 0.651 | 2.8% | ||
| @typescript-eslint/adjacent-overload-signatures | 0.588 | 2.6% | ||
| @typescript-eslint/no-loss-of-precision | 0.508 | 2.2% | ||
| prefer-const | 0.466 | 2.0% |
| import * as axios from 'axios'; | ||
| import * as openai from 'openai'; | ||
| import { Struct } from 'superstruct'; | ||
| declare class Writer { | ||
| private static types; | ||
| private static openai; | ||
| static initialize({ apiKey, types }: { | ||
| apiKey: string; | ||
| types?: any[]; | ||
| }): void; | ||
| static write(type: WriterType | string, params: unknown): Promise<axios.AxiosResponse<openai.CreateCompletionResponse, any>>; | ||
| } | ||
| type WriterType = { | ||
| makeQuery: (params: unknown) => string; | ||
| config: { | ||
| type: string; | ||
| params: Struct<any, object>; | ||
| }; | ||
| }; | ||
| export { Writer, WriterType }; |
-102
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var __async = (__this, __arguments, generator) => { | ||
| return new Promise((resolve, reject) => { | ||
| var fulfilled = (value) => { | ||
| try { | ||
| step(generator.next(value)); | ||
| } catch (e) { | ||
| reject(e); | ||
| } | ||
| }; | ||
| var rejected = (value) => { | ||
| try { | ||
| step(generator.throw(value)); | ||
| } catch (e) { | ||
| reject(e); | ||
| } | ||
| }; | ||
| var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); | ||
| step((generator = generator.apply(__this, __arguments)).next()); | ||
| }); | ||
| }; | ||
| // Writer.ts | ||
| var Writer_exports = {}; | ||
| __export(Writer_exports, { | ||
| Writer: () => Writer | ||
| }); | ||
| module.exports = __toCommonJS(Writer_exports); | ||
| var import_superstruct = require("superstruct"); | ||
| // openai.ts | ||
| var import_openai = require("openai"); | ||
| var OpenAI = class { | ||
| constructor(apiKey) { | ||
| this.createDavinciCompletion = (_0) => __async(this, [_0], function* ({ prompt, maxToken = 144, temperature = 0.7 }) { | ||
| return yield this.openai.createCompletion({ | ||
| model: "text-davinci-003", | ||
| prompt, | ||
| temperature, | ||
| max_tokens: maxToken | ||
| }); | ||
| }); | ||
| const configuration = new import_openai.Configuration({ | ||
| apiKey | ||
| }); | ||
| this.openai = new import_openai.OpenAIApi(configuration); | ||
| } | ||
| }; | ||
| // Writer.ts | ||
| var Writer = class { | ||
| static initialize({ apiKey, types }) { | ||
| this.openai = new OpenAI(apiKey); | ||
| this.types = types ? types : null; | ||
| } | ||
| static write(type, params) { | ||
| return __async(this, null, function* () { | ||
| var _a; | ||
| let writerType; | ||
| if (typeof type === "string") { | ||
| writerType = (_a = Writer.types) == null ? void 0 : _a.find((value) => value.config.type === type); | ||
| if (writerType === void 0) { | ||
| throw new Error(`Type ${type} not found.`); | ||
| } | ||
| } else { | ||
| writerType = type; | ||
| } | ||
| try { | ||
| const writerParams = writerType.config.params; | ||
| (0, import_superstruct.assert)(params, writerParams); | ||
| } catch (e) { | ||
| if (e instanceof import_superstruct.StructError) { | ||
| const { message } = e; | ||
| throw new Error(`Typing verification for type ${writerType.config.type} failed. ${message}.`); | ||
| } | ||
| } | ||
| const prompt = writerType.makeQuery(params); | ||
| return this.openai.createDavinciCompletion({ prompt }); | ||
| }); | ||
| } | ||
| }; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Writer | ||
| }); |
-41
| import { assert, Infer, object, string, Struct, StructError } from 'superstruct'; | ||
| import { OpenAI } from './openai'; | ||
| export class Writer { | ||
| private static types: WriterType[] | null; | ||
| private static openai: OpenAI; | ||
| static initialize({ apiKey, types }: { apiKey: string, types?: any[] }) { | ||
| this.openai = new OpenAI(apiKey); | ||
| this.types = types ? types : null; | ||
| } | ||
| static async write(type: WriterType | string, params: unknown) { | ||
| let writerType; | ||
| if (typeof type === 'string') { | ||
| writerType = Writer.types?.find(value => value.config.type === type); | ||
| if (writerType === undefined) { | ||
| throw new Error(`Type ${type} not found.`); | ||
| } | ||
| } else { | ||
| writerType = type; | ||
| } | ||
| try { | ||
| const writerParams = writerType.config.params; | ||
| assert(params, writerParams); | ||
| } catch (e: unknown) { | ||
| if (e instanceof StructError) { | ||
| const { message } = e; | ||
| throw new Error(`Typing verification for type ${writerType.config.type} failed. ${message}.`); | ||
| } | ||
| } | ||
| const prompt = writerType.makeQuery(params as Infer<typeof writerType.config.params>); | ||
| return this.openai.createDavinciCompletion({ prompt }); | ||
| } | ||
| } | ||
| export type WriterType= { makeQuery: (params: unknown) => string, config: { type: string, params: Struct<any, object> } }; |
| Arguments: | ||
| /home/samy/.nvm/versions/node/v18.12.1/bin/node /usr/local/bin/yarn add tsup | ||
| PATH: | ||
| /home/samy/.nvm/versions/node/v18.12.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/samy/.local/share/JetBrains/Toolbox/scripts:/home/samy/Programming/dev/writer.js/node_modules/.bin | ||
| Yarn version: | ||
| 1.22.19 | ||
| Node version: | ||
| 18.12.1 | ||
| Platform: | ||
| linux x64 | ||
| Trace: | ||
| SyntaxError: /home/samy/Programming/dev/writer.js/packages/writerjs/package.json: Unexpected token } in JSON at position 237 | ||
| at JSON.parse (<anonymous>) | ||
| at /usr/local/lib/node_modules/yarn/lib/cli.js:1629:59 | ||
| at Generator.next (<anonymous>) | ||
| at step (/usr/local/lib/node_modules/yarn/lib/cli.js:310:30) | ||
| at /usr/local/lib/node_modules/yarn/lib/cli.js:321:13 | ||
| npm manifest: | ||
| { | ||
| "name": "writerjs", | ||
| "version": "0.0.0", | ||
| "main": "./index.ts", | ||
| "types": "./index.ts", | ||
| "license": "MIT", | ||
| "scripts": { | ||
| "lint": "TIMING=1 eslint \"**/*.ts*\"", | ||
| "lint:fix": "TIMING=1 eslint \"**/*.ts*\" --fix", | ||
| "" | ||
| }, | ||
| "devDependencies": { | ||
| "eslint": "^7.32.0", | ||
| "eslint-config-custom": "*", | ||
| "tsconfig": "*", | ||
| "typescript": "^4.5.2" | ||
| }, | ||
| "dependencies": { | ||
| "openai": "^3.1.0", | ||
| "superstruct": "^1.0.3" | ||
| } | ||
| } | ||
| yarn manifest: | ||
| No manifest | ||
| Lockfile: | ||
| No lockfile |
365
0.55%15338
-16.76%14
-12.5%