2022-12-03 00:04:53 +00:00
|
|
|
[chatgpt](../readme.md) / [Exports](../modules.md) / ChatGPTAPI
|
|
|
|
|
|
|
|
# Class: ChatGPTAPI
|
|
|
|
|
|
|
|
## Table of contents
|
|
|
|
|
|
|
|
### Constructors
|
|
|
|
|
|
|
|
- [constructor](ChatGPTAPI.md#constructor)
|
|
|
|
|
|
|
|
### Methods
|
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
- [ensureAuth](ChatGPTAPI.md#ensureauth)
|
|
|
|
- [getIsAuthenticated](ChatGPTAPI.md#getisauthenticated)
|
|
|
|
- [refreshAccessToken](ChatGPTAPI.md#refreshaccesstoken)
|
2022-12-03 00:04:53 +00:00
|
|
|
- [sendMessage](ChatGPTAPI.md#sendmessage)
|
|
|
|
|
|
|
|
## Constructors
|
|
|
|
|
|
|
|
### constructor
|
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
• **new ChatGPTAPI**(`opts`)
|
|
|
|
|
|
|
|
Creates a new client wrapper around the unofficial ChatGPT REST API.
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
#### Parameters
|
|
|
|
|
|
|
|
| Name | Type | Description |
|
|
|
|
| :------ | :------ | :------ |
|
|
|
|
| `opts` | `Object` | - |
|
2022-12-05 05:13:36 +00:00
|
|
|
| `opts.apiBaseUrl?` | `string` | **`Default Value`** `'https://chat.openai.com/api'` * |
|
|
|
|
| `opts.backendApiBaseUrl?` | `string` | **`Default Value`** `'https://chat.openai.com/backend-api'` * |
|
2022-12-03 00:04:53 +00:00
|
|
|
| `opts.markdown?` | `boolean` | **`Default Value`** `true` * |
|
2022-12-05 05:13:36 +00:00
|
|
|
| `opts.sessionToken` | `string` | = **Required** OpenAI session token which can be found in a valid session's cookies (see readme for instructions) |
|
|
|
|
| `opts.userAgent?` | `string` | **`Default Value`** `'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'` * |
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
#### Defined in
|
|
|
|
|
2022-12-06 08:40:40 +00:00
|
|
|
[chatgpt-api.ts:31](https://github.com/transitive-bullshit/chatgpt-api/blob/80d77a3/src/chatgpt-api.ts#L31)
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
## Methods
|
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
### ensureAuth
|
2022-12-03 00:04:53 +00:00
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
▸ **ensureAuth**(): `Promise`<`string`\>
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
#### Returns
|
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
`Promise`<`string`\>
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
#### Defined in
|
|
|
|
|
2022-12-06 08:40:40 +00:00
|
|
|
[chatgpt-api.ts:74](https://github.com/transitive-bullshit/chatgpt-api/blob/80d77a3/src/chatgpt-api.ts#L74)
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
___
|
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
### getIsAuthenticated
|
2022-12-03 00:04:53 +00:00
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
▸ **getIsAuthenticated**(): `Promise`<`boolean`\>
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
#### Returns
|
|
|
|
|
|
|
|
`Promise`<`boolean`\>
|
|
|
|
|
|
|
|
#### Defined in
|
|
|
|
|
2022-12-06 08:40:40 +00:00
|
|
|
[chatgpt-api.ts:65](https://github.com/transitive-bullshit/chatgpt-api/blob/80d77a3/src/chatgpt-api.ts#L65)
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
___
|
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
### refreshAccessToken
|
2022-12-03 00:04:53 +00:00
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
▸ **refreshAccessToken**(): `Promise`<`string`\>
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
#### Returns
|
|
|
|
|
|
|
|
`Promise`<`string`\>
|
|
|
|
|
|
|
|
#### Defined in
|
|
|
|
|
2022-12-06 08:40:40 +00:00
|
|
|
[chatgpt-api.ts:165](https://github.com/transitive-bullshit/chatgpt-api/blob/80d77a3/src/chatgpt-api.ts#L165)
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
___
|
|
|
|
|
|
|
|
### sendMessage
|
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
▸ **sendMessage**(`message`, `opts?`): `Promise`<`string`\>
|
|
|
|
|
|
|
|
Sends a message to ChatGPT, waits for the response to resolve, and returns
|
|
|
|
the response.
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
#### Parameters
|
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
| Name | Type | Description |
|
|
|
|
| :------ | :------ | :------ |
|
|
|
|
| `message` | `string` | The plaintext message to send. |
|
|
|
|
| `opts` | `Object` | - |
|
2022-12-06 04:53:20 +00:00
|
|
|
| `opts.conversationId?` | `string` | Optional ID of the previous message in a conversation |
|
2022-12-05 05:13:36 +00:00
|
|
|
| `opts.onProgress?` | (`partialResponse`: `string`) => `void` | - |
|
2022-12-03 00:04:53 +00:00
|
|
|
|
|
|
|
#### Returns
|
|
|
|
|
|
|
|
`Promise`<`string`\>
|
|
|
|
|
|
|
|
#### Defined in
|
|
|
|
|
2022-12-06 08:40:40 +00:00
|
|
|
[chatgpt-api.ts:86](https://github.com/transitive-bullshit/chatgpt-api/blob/80d77a3/src/chatgpt-api.ts#L86)
|