chatgpt / Exports / ChatGPTAPI
• new ChatGPTAPI(opts
)
Creates a new client wrapper around OpenAI's chat completion API, mimicing the official ChatGPT webapp's functionality as closely as possible.
Name | Type |
---|---|
opts |
ChatGPTAPIOptions |
• get
apiKey(): string
string
• set
apiKey(apiKey
): void
Name | Type |
---|---|
apiKey |
string |
void
• get
apiOrg(): string
string
• set
apiOrg(apiOrg
): void
Name | Type |
---|---|
apiOrg |
string |
void
▸ sendMessage(text
, opts?
): Promise
<ChatMessage
>
Sends a message to the OpenAI chat completions endpoint, 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
.
Set debug: true
in the ChatGPTAPI
constructor to log more info on the full prompt sent to the OpenAI chat completions API. You can override the systemMessage
in opts
to customize the assistant's instructions.
Name | Type |
---|---|
text |
string |
opts |
SendMessageOptions |
Promise
<ChatMessage
>
The response from ChatGPT