Comparing version 1.0.5 to 2.1.0
@@ -7,2 +7,3 @@ #!/usr/bin/env node | ||
const checkForCredentials_1 = require("../utility/debug/checkForCredentials"); | ||
const removeLastSentence_1 = require("../utility/string/removeLastSentence"); | ||
const replaceNewlineEscapes_1 = require("../utility/string/replaceNewlineEscapes"); | ||
@@ -17,3 +18,4 @@ checkForCredentials_1.checkForCredentials(); | ||
const completion = await getCompletion_1.getCompletion(prompt); | ||
console.log(`\n${completion}`); | ||
const cleaned = removeLastSentence_1.removeLastSentence(prompt + completion); | ||
console.log(`\n${cleaned}`); | ||
})().catch((error) => { | ||
@@ -20,0 +22,0 @@ throw error; |
@@ -1,1 +0,6 @@ | ||
export declare function getCompletion(prompt: string): Promise<string>; | ||
import { CompletionOptions } from "./types/CompletionOptions"; | ||
export declare type AuthOptions = { | ||
openAIKey: string; | ||
openAISecretKey: string; | ||
}; | ||
export declare function getCompletion(prompt: string, options?: Partial<CompletionOptions>, authOptions?: Partial<AuthOptions>): Promise<string>; |
@@ -8,12 +8,20 @@ "use strict"; | ||
const axios_1 = __importDefault(require("axios")); | ||
const mapKeys_1 = __importDefault(require("lodash/mapKeys")); | ||
const openAIConfiguration_1 = require("../../config/openAIConfiguration"); | ||
const removeLastSentence_1 = require("../string/removeLastSentence"); | ||
async function getCompletion(prompt) { | ||
const completionKeyTranslations_1 = require("./literals/completionKeyTranslations"); | ||
async function getCompletion(prompt, options = {}, authOptions = {}) { | ||
var _a; | ||
const translatedOptions = mapKeys_1.default(options, (_x, key) => completionKeyTranslations_1.completionKeyTranslations[key]); | ||
const authKey = (_a = authOptions === null || authOptions === void 0 ? void 0 : authOptions.openAISecretKey) !== null && _a !== void 0 ? _a : openAIConfiguration_1.openAIConfiguration.secretKey; | ||
if (!authKey) { | ||
throw new TypeError("MISSING SECRET KEY: Either specify secret key in environment, or pass in as auth parameter"); | ||
} | ||
const completionResult = (await axios_1.default.post(openAIConfiguration_1.openAIConfiguration.engineCompletionEndpoint, { | ||
prompt, | ||
max_tokens: 100, | ||
...translatedOptions, | ||
}, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${openAIConfiguration_1.openAIConfiguration.secretKey}`, | ||
Authorization: `Bearer ${authKey}`, | ||
}, | ||
@@ -20,0 +28,0 @@ })).data; |
{ | ||
"name": "gpt3", | ||
"version": "1.0.5", | ||
"version": "2.1.0", | ||
"description": "A simple CLI tool to interface with OpenAI's beta API", | ||
@@ -36,2 +36,3 @@ "main": "index.js", | ||
"@types/jest": "^26.0.4", | ||
"@types/lodash": "^4.14.157", | ||
"@typescript-eslint/eslint-plugin": "^3.6.1", | ||
@@ -71,4 +72,5 @@ "@typescript-eslint/parser": "^3.6.1", | ||
"axios": "^0.19.2", | ||
"lodash": "^4.17.19", | ||
"yargs": "^15.4.1" | ||
} | ||
} |
# GPT3 CLI API | ||
A simple CLI tool to interface with OpenAI's beta API. | ||
A simple NodeJS wrapper library and CLI to interface with OpenAI's Beta API. Written in Typescript. | ||
## Requirements | ||
Your API key and secret key must be defined in your environment under `OPENAI_KEY` and `OPENAI_SECRET_KEY` respectively. | ||
When using the CLI, the API key and secret key must be defined in your environment under `OPENAI_KEY` and `OPENAI_SECRET_KEY` respectively. | ||
When using this package as a library, you may either provide the keys in the environment as above, or provide them as a final `auth` parameter. | ||
## Installation | ||
If CLI: | ||
```sh | ||
@@ -15,4 +19,10 @@ npm i -g gpt3 | ||
## Usage | ||
If programmatic: | ||
``` | ||
npm i gpt3 | ||
``` | ||
## CLI Usage | ||
You pass in the starter text as the first parameter, and the tool returns the completion. | ||
@@ -24,2 +34,22 @@ | ||
"Once upon a time, there was a thing that did this, etc, foobar." | ||
``` | ||
``` | ||
## Programmatic Usage | ||
```ts | ||
import { getCompletion } from "gpt3"; | ||
const result = await getCompletion("Once upon a time, "); | ||
// etc. | ||
``` | ||
## Limitations and Future Work | ||
Features not supported, but which I eventually plan to: | ||
* Streaming | ||
* Simple filtering, optional clean-up logic | ||
* Automatic truth checking | ||
* Search API | ||
* Fine-tuning API (Once it comes out) | ||
* Pre-selected prompt generation logic |
9848
26
165
53
3
33
+ Addedlodash@^4.17.19
+ Addedlodash@4.17.21(transitive)