Skip to content

Kypaku/gpt-simple-api

Repository files navigation

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> 

Projects that use it:

GPTCraft

GPTCraft Chrome Extension

Vue-Gpt-Playground

GPT ProjectInsight

About

A simple client GPT API written in Typescript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published