gpt-simple-api-ts
v1.0.46
Published
A simple client GPT API written in TypeScript
Downloads
63
Readme
gpt-simple-api
A simple client OpenAI API written in Typescript.
Install
npm i gpt-simple-api-ts
Example:
// import SimpleAPI from 'gpt-simple-api-ts'
const SimpleAPI = require('gpt-simple-api-ts')
const api = new SimpleAPI({key: process.env.OPENAI_API_KEY})
async function main () {
const res = await api.getFirst("Give me a reason")
console.log("main", res)
}
main()
Methods:
setApiKey(key: string)
Sets the key To get an API KEY you need to register new OPEN API account and then visit https://platform.openai.com/account/api-keys
Models
async getModels(): Promise<null | string[]>
Streams:
async getStream(promt: string, fData, fEnd, opts): Promise<any>
abortStream
Text generation
Get text response from GPT:
async getFirst(promt: string, opts?: CreateCompletionRequest): Promise<string | undefined>
Get several text completions:
async get(promt: string, opts?: CreateCompletionRequest): Promise<null | string[]>
Completions:
async getCompletions(prompt: string, opts?: Partial<CreateCompletionRequest>): Promise<null | string[]>
Transcribe audio
async transcribe(formData): Promise<string | undefined>
Code
Get code completions:
async getCode(promt: string, opts?: CreateCompletionRequest): Promise<null | string[]>
Get one code complettion:
async getCodeFirst(promt: string, opts?: CreateCompletionRequest): Promise<string | undefined>