Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
pacholoamit committed Feb 20, 2023
2 parents 66c638d + 6337aa9 commit 5e9937d
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 35 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions examples/basic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"typescript": "^4.9.5"
},
"dependencies": {
"chatgpt": "^4.1.1",
"chatgpt-prompts": "^1.1.1"
"chatgpt-prompts": "^2.0.0"
}
}
5 changes: 1 addition & 4 deletions examples/basic/src/index.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
1 change: 0 additions & 1 deletion generators/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
11 changes: 5 additions & 6 deletions generators/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
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[]) => {
type PromptGenerator = ReturnType<typeof createPromptsGenerator>;

const generateReadme = async (prompts: PromptCsvField[]): Promise<void> => {
const readmeGenerator = createReadmeGenerator(templateMarkdownFile, readmeFile);
const readmePrompts = readmeGenerator.format(prompts);
readmeGenerator.generate(readmePrompts);
};

const generateCode = async (instance: ReturnType<typeof createPromptsGenerator>, prompts: PromptCsvField[]) => {
const generateCode = async (instance: PromptGenerator, prompts: PromptCsvField[]): Promise<void> => {
instance.writeInterface(typesFile, prompts);
instance.writePromptsFunctions(promptsFile, prompts);
instance.writeMainImports(methodImportsFile, prompts);
};

const main = async () => {
const main = async (): Promise<void> => {
const promptsGenerator = createPromptsGenerator();
const prompts = await promptsGenerator.getPrompts();

Expand Down
6 changes: 3 additions & 3 deletions generators/src/prompts-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};

Expand Down
12 changes: 6 additions & 6 deletions generators/src/readme-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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,
};
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 5e9937d

Please sign in to comment.