From c2e24bbff4d876d17d963bf75e88eb1e81871aa1 Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Sun, 19 Feb 2023 03:06:50 +0800 Subject: [PATCH 1/5] Generate readme & modify example to reflect v2.0.0 --- README.md | 13 +++++++++---- examples/basic/package-lock.json | 15 +++++++-------- examples/basic/package.json | 3 +-- examples/basic/src/index.ts | 5 +---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ad021d0..7344935 100644 --- a/README.md +++ b/README.md @@ -42,15 +42,20 @@ By default the `chatgpt-prompts` persists the instance of the prompt you are usi ```typescript import { createChatGPTPrompt } from "chatgpt-prompts"; -import { ChatGPTAPI } from "chatgpt"; const run = async () => { - const instance = new ChatGPTAPI({ + /** + * @description ChatGPT Prompt, accepts the same parameters as the + * ChatGPTAPI constructor, but returns a promise that resolves to a + * ChatMessage. + * + * @see {@link https://github.com/transitive-bullshit/chatgpt-api/blob/main/docs/classes/ChatGPTAPI.md#constructor} + * + */ + const prompts = createChatGPTPrompt({ apiKey: "OPEN_AI_API_KEY", }); - const prompt = createChatGPTPrompt(instance); - // Use the Accountant prompt of ChatGPT let res = await prompt.accountant("Why am I still broke as a software engineer?"); console.log(res.text); diff --git a/examples/basic/package-lock.json b/examples/basic/package-lock.json index eac3a2b..4161901 100644 --- a/examples/basic/package-lock.json +++ b/examples/basic/package-lock.json @@ -9,8 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "chatgpt": "^4.1.1", - "chatgpt-prompts": "^1.1.1" + "chatgpt-prompts": "^2.0.0" }, "devDependencies": { "nodemon": "^2.0.20", @@ -186,9 +185,9 @@ } }, "node_modules/chatgpt-prompts": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/chatgpt-prompts/-/chatgpt-prompts-1.2.0.tgz", - "integrity": "sha512-s2x3wEqJ3RqTnSJvj+lkDDjKLBQC+TTHMfW2Vtt8rN0zUXA1PtfdoqvGAvfuW2YQrL6LsWhalKtPGW9DWoNskQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chatgpt-prompts/-/chatgpt-prompts-2.0.0.tgz", + "integrity": "sha512-cnrs1mqB62yVgiEwI3L87FngKu9U/u6j4LpNC8I1lhk36aqHw6W0ReD3y3jhBRAnTxlqIMa1+g1tXaW+H2MbUw==", "dependencies": { "chatgpt": "^4.1.1" }, @@ -796,9 +795,9 @@ } }, "chatgpt-prompts": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/chatgpt-prompts/-/chatgpt-prompts-1.2.0.tgz", - "integrity": "sha512-s2x3wEqJ3RqTnSJvj+lkDDjKLBQC+TTHMfW2Vtt8rN0zUXA1PtfdoqvGAvfuW2YQrL6LsWhalKtPGW9DWoNskQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chatgpt-prompts/-/chatgpt-prompts-2.0.0.tgz", + "integrity": "sha512-cnrs1mqB62yVgiEwI3L87FngKu9U/u6j4LpNC8I1lhk36aqHw6W0ReD3y3jhBRAnTxlqIMa1+g1tXaW+H2MbUw==", "requires": { "chatgpt": "^4.1.1" } diff --git a/examples/basic/package.json b/examples/basic/package.json index 4de61a7..7b5fcf0 100644 --- a/examples/basic/package.json +++ b/examples/basic/package.json @@ -17,7 +17,6 @@ "typescript": "^4.9.5" }, "dependencies": { - "chatgpt": "^4.1.1", - "chatgpt-prompts": "^1.1.1" + "chatgpt-prompts": "^2.0.0" } } diff --git a/examples/basic/src/index.ts b/examples/basic/src/index.ts index 1a7fa85..ca66463 100644 --- a/examples/basic/src/index.ts +++ b/examples/basic/src/index.ts @@ -1,13 +1,10 @@ -import { ChatGPTAPI } from "chatgpt"; import { createChatGPTPrompt } from "chatgpt-prompts"; const run = async () => { - const instance = new ChatGPTAPI({ + const prompt = createChatGPTPrompt({ apiKey: "OPEN_AI_API_KEY", }); - const prompt = createChatGPTPrompt(instance); - let res = await prompt.accountant("Why am I still broke as a software engineer?"); console.log(res.text); From f3968ad445e67939304c7312ee2d16d5d55e2221 Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Sun, 19 Feb 2023 03:20:15 +0800 Subject: [PATCH 2/5] Cleanup generators --- generators/src/constants.ts | 1 - generators/src/index.ts | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/generators/src/constants.ts b/generators/src/constants.ts index 75a3185..5715805 100644 --- a/generators/src/constants.ts +++ b/generators/src/constants.ts @@ -1,6 +1,5 @@ import path from "path"; -// export const url = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"; export const promptsFile = "./artifacts/prompts.txt"; export const methodImportsFile = path.join("./artifacts/imports.txt"); export const typesFile = path.join("./artifacts/types.txt"); diff --git a/generators/src/index.ts b/generators/src/index.ts index d37d8a2..2351884 100644 --- a/generators/src/index.ts +++ b/generators/src/index.ts @@ -1,24 +1,24 @@ -import ejs from "ejs"; -import * as fs from "fs"; -import { funcTemplate, methodImportTemplate, typeTemplate } from "./template"; import { promptsFile, methodImportsFile, templateMarkdownFile, readmeFile, typesFile } from "./constants"; import { PromptCsvField } from "./types"; import createReadmeGenerator from "./readme-generator"; import createPromptsGenerator from "./prompts-generator"; -const generateReadme = async (prompts: PromptCsvField[]) => { +const generateReadme = async (prompts: PromptCsvField[]): Promise => { const readmeGenerator = createReadmeGenerator(templateMarkdownFile, readmeFile); const readmePrompts = readmeGenerator.format(prompts); readmeGenerator.generate(readmePrompts); }; -const generateCode = async (instance: ReturnType, prompts: PromptCsvField[]) => { +const generateCode = async ( + instance: ReturnType, + prompts: PromptCsvField[] +): Promise => { instance.writeInterface(typesFile, prompts); instance.writePromptsFunctions(promptsFile, prompts); instance.writeMainImports(methodImportsFile, prompts); }; -const main = async () => { +const main = async (): Promise => { const promptsGenerator = createPromptsGenerator(); const prompts = await promptsGenerator.getPrompts(); From 29e4a70ca6e7b2d99ffcbfd558ad8f43c1be916a Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Sun, 19 Feb 2023 03:24:25 +0800 Subject: [PATCH 3/5] Cleanup exports of prompts-generator & readme-generator --- generators/src/prompts-generator.ts | 6 +++--- generators/src/readme-generator.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/generators/src/prompts-generator.ts b/generators/src/prompts-generator.ts index 11e3be4..36251ea 100644 --- a/generators/src/prompts-generator.ts +++ b/generators/src/prompts-generator.ts @@ -44,9 +44,9 @@ const createPromptsGenerator = () => { const url = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"; return { getPrompts: () => getPrompts(url).then((prompts) => makeUniquePrompts(prompts)), - writeInterface: (filePath: string, prompts: PromptCsvField[]) => writeInterface(filePath, prompts), - writePromptsFunctions: writePromptsFunctions, - writeMainImports: writeMainImports, + writeInterface, + writePromptsFunctions, + writeMainImports, }; }; diff --git a/generators/src/readme-generator.ts b/generators/src/readme-generator.ts index be267bf..b15deb9 100644 --- a/generators/src/readme-generator.ts +++ b/generators/src/readme-generator.ts @@ -3,6 +3,11 @@ import ejs from "ejs"; import { PromptCsvField } from "./types"; import { funcTemplate } from "./template"; +interface GeneratablePrompt { + code: string; + prompt: PromptCsvField; +} + const generate = (template: string, path: string) => { return async (prompts: GeneratablePrompt[]) => { const data = await ejs.renderFile(template, { data: prompts }); @@ -17,15 +22,10 @@ const format = (prompts: PromptCsvField[]) => { }); }; -interface GeneratablePrompt { - code: string; - prompt: PromptCsvField; -} - const createReadmeGenerator = (template: string, path: string) => { return { generate: (prompts: GeneratablePrompt[]) => generate(template, path)(prompts), - format: (prompts: PromptCsvField[]) => format(prompts), + format, }; }; From 2f4e66741088a98f1098e4ceda7313623dd697a9 Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Sun, 19 Feb 2023 03:27:37 +0800 Subject: [PATCH 4/5] Write type for PromptGenerator --- generators/src/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/generators/src/index.ts b/generators/src/index.ts index 2351884..b108894 100644 --- a/generators/src/index.ts +++ b/generators/src/index.ts @@ -3,16 +3,15 @@ import { PromptCsvField } from "./types"; import createReadmeGenerator from "./readme-generator"; import createPromptsGenerator from "./prompts-generator"; +type PromptGenerator = ReturnType; + const generateReadme = async (prompts: PromptCsvField[]): Promise => { const readmeGenerator = createReadmeGenerator(templateMarkdownFile, readmeFile); const readmePrompts = readmeGenerator.format(prompts); readmeGenerator.generate(readmePrompts); }; -const generateCode = async ( - instance: ReturnType, - prompts: PromptCsvField[] -): Promise => { +const generateCode = async (instance: PromptGenerator, prompts: PromptCsvField[]): Promise => { instance.writeInterface(typesFile, prompts); instance.writePromptsFunctions(promptsFile, prompts); instance.writeMainImports(methodImportsFile, prompts); From 6337aa90dbc53fd13e8e02d1028b1344bf9506f1 Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Mon, 20 Feb 2023 22:52:23 +0800 Subject: [PATCH 5/5] 2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fb7588c..4fda500 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chatgpt-prompts", - "version": "2.0.0", + "version": "2.0.1", "description": "A NodeJS ChatGPT prompts library", "type": "module", "source": "./src/index.ts",