chatgpt-api/docs/classes/ChatGPTAPI.md

2.0 KiB

chatgpt / Exports / ChatGPTAPI

Class: ChatGPTAPI

Table of contents

Constructors

Methods

Constructors

constructor

new ChatGPTAPI(opts)

Creates a new client wrapper around OpenAI's completion API using the unofficial ChatGPT model.

Parameters

Name Type Description
opts Object -
opts.apiBaseUrl? string Default Value 'https://api.openai.com' *
opts.apiKey string -
opts.completionParams? CompletionParams -
opts.debug? boolean Default Value false *
opts.getMessageById? GetMessageByIdFunction -
opts.messageStore? Keyv<any, Record<string, unknown>> -
opts.upsertMessage? UpsertMessageFunction -

Defined in

src/chatgpt-api.ts:36

Methods

sendMessage

sendMessage(text, opts?): Promise<ChatMessage>

Sends a message to ChatGPT, waits for the response to resolve, and returns the response.

If you want to receive a stream of partial responses, use opts.onProgress. If you want to receive the full response, including message and conversation IDs, you can use opts.onConversationResponse or use the ChatGPTAPI.getConversation helper.

Parameters

Name Type
text string
opts SendMessageOptions

Returns

Promise<ChatMessage>

The response from ChatGPT

Defined in

src/chatgpt-api.ts:109