A simple client OpenAI API written in Typescript.
npm i gpt-simple-api-ts
// 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()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
async getModels(): Promise<null | string[]> async getStream(promt: string, fData, fEnd, opts): Promise<any> abortStreamGet 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[]>async transcribe(formData): Promise<string | undefined> 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>