chatgpt / Exports / ChatGPTAPI
• new ChatGPTAPI(opts
)
Creates a new client wrapper around OpenAI's completion API using the unofficial ChatGPT model.
Name | Type | Description |
---|---|---|
opts |
Object |
- |
opts.apiBaseUrl? |
string |
Default Value 'https://api.openai.com' * |
opts.apiKey |
string |
- |
opts.assistantLabel? |
string |
Default Value 'ChatGPT' * |
opts.completionParams? |
Partial <CompletionParams > |
- |
opts.debug? |
boolean |
Default Value false * |
opts.getMessageById? |
GetMessageByIdFunction |
- |
opts.maxModelTokens? |
number |
Default Value 4096 * |
opts.maxResponseTokens? |
number |
Default Value 1000 * |
opts.messageStore? |
Keyv <any , Record <string , unknown >> |
- |
opts.upsertMessage? |
UpsertMessageFunction |
- |
opts.userLabel? |
string |
Default Value 'User' * |
▸ sendMessage(text
, opts?
): Promise
<ChatMessage
>
Sends a message to ChatGPT, waits for the response to resolve, and returns the response.
If you want your response to have historical context, you must provide a valid parentMessageId
.
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.
Set debug: true
in the ChatGPTAPI
constructor to log more info on the full prompt sent to the OpenAI completions API. You can override the promptPrefix
and promptSuffix
in opts
to customize the prompt.
Name | Type |
---|---|
text |
string |
opts |
SendMessageOptions |
Promise
<ChatMessage
>
The response from ChatGPT