kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
chore: update ts docs
rodzic
2937409f15
commit
df1db26415
|
@ -0,0 +1,167 @@
|
|||
[chatgpt](../readme.md) / [Exports](../modules.md) / AChatGPTAPI
|
||||
|
||||
# Class: AChatGPTAPI
|
||||
|
||||
## Hierarchy
|
||||
|
||||
- **`AChatGPTAPI`**
|
||||
|
||||
↳ [`ChatGPTAPI`](ChatGPTAPI.md)
|
||||
|
||||
↳ [`ChatGPTAPIBrowser`](ChatGPTAPIBrowser.md)
|
||||
|
||||
## Table of contents
|
||||
|
||||
### Constructors
|
||||
|
||||
- [constructor](AChatGPTAPI.md#constructor)
|
||||
|
||||
### Methods
|
||||
|
||||
- [closeSession](AChatGPTAPI.md#closesession)
|
||||
- [getIsAuthenticated](AChatGPTAPI.md#getisauthenticated)
|
||||
- [initSession](AChatGPTAPI.md#initsession)
|
||||
- [refreshSession](AChatGPTAPI.md#refreshsession)
|
||||
- [resetSession](AChatGPTAPI.md#resetsession)
|
||||
- [sendMessage](AChatGPTAPI.md#sendmessage)
|
||||
|
||||
## Constructors
|
||||
|
||||
### constructor
|
||||
|
||||
• **new AChatGPTAPI**()
|
||||
|
||||
## Methods
|
||||
|
||||
### closeSession
|
||||
|
||||
▸ `Abstract` **closeSession**(): `Promise`<`void`\>
|
||||
|
||||
Closes the active session.
|
||||
|
||||
**`Throws`**
|
||||
|
||||
An error if it fails.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`void`\>
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/abstract-chatgpt-api.ts:69](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/abstract-chatgpt-api.ts#L69)
|
||||
|
||||
___
|
||||
|
||||
### getIsAuthenticated
|
||||
|
||||
▸ `Abstract` **getIsAuthenticated**(): `Promise`<`boolean`\>
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`boolean`\>
|
||||
|
||||
`true` if the client is authenticated with a valid session or `false`
|
||||
otherwise.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/abstract-chatgpt-api.ts:39](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/abstract-chatgpt-api.ts#L39)
|
||||
|
||||
___
|
||||
|
||||
### initSession
|
||||
|
||||
▸ `Abstract` **initSession**(): `Promise`<`void`\>
|
||||
|
||||
Performs any async initialization work required to ensure that this API is
|
||||
properly authenticated.
|
||||
|
||||
**`Throws`**
|
||||
|
||||
An error if the session failed to initialize properly.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`void`\>
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/abstract-chatgpt-api.ts:10](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/abstract-chatgpt-api.ts#L10)
|
||||
|
||||
___
|
||||
|
||||
### refreshSession
|
||||
|
||||
▸ `Abstract` **refreshSession**(): `Promise`<`any`\>
|
||||
|
||||
Refreshes the current ChatGPT session.
|
||||
|
||||
Useful for bypassing 403 errors when Cloudflare clearance tokens expire.
|
||||
|
||||
**`Throws`**
|
||||
|
||||
An error if it fails.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`any`\>
|
||||
|
||||
Access credentials for the new session.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/abstract-chatgpt-api.ts:49](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/abstract-chatgpt-api.ts#L49)
|
||||
|
||||
___
|
||||
|
||||
### resetSession
|
||||
|
||||
▸ **resetSession**(): `Promise`<`any`\>
|
||||
|
||||
Closes the current ChatGPT session and starts a new one.
|
||||
|
||||
Useful for bypassing 401 errors when sessions expire.
|
||||
|
||||
**`Throws`**
|
||||
|
||||
An error if it fails.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`any`\>
|
||||
|
||||
Access credentials for the new session.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/abstract-chatgpt-api.ts:59](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/abstract-chatgpt-api.ts#L59)
|
||||
|
||||
___
|
||||
|
||||
### sendMessage
|
||||
|
||||
▸ `Abstract` **sendMessage**(`message`, `opts?`): `Promise`<[`ChatResponse`](../modules.md#chatresponse)\>
|
||||
|
||||
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`.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `message` | `string` | The prompt message to send |
|
||||
| `opts?` | [`SendMessageOptions`](../modules.md#sendmessageoptions) | - |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`ChatResponse`](../modules.md#chatresponse)\>
|
||||
|
||||
The response from ChatGPT, including `conversationId`, `messageId`, and
|
||||
the `response` text.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/abstract-chatgpt-api.ts:30](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/abstract-chatgpt-api.ts#L30)
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
# Class: ChatGPTAPI
|
||||
|
||||
## Hierarchy
|
||||
|
||||
- [`AChatGPTAPI`](AChatGPTAPI.md)
|
||||
|
||||
↳ **`ChatGPTAPI`**
|
||||
|
||||
## Table of contents
|
||||
|
||||
### Constructors
|
||||
|
@ -17,10 +23,11 @@
|
|||
|
||||
### Methods
|
||||
|
||||
- [ensureAuth](ChatGPTAPI.md#ensureauth)
|
||||
- [getConversation](ChatGPTAPI.md#getconversation)
|
||||
- [closeSession](ChatGPTAPI.md#closesession)
|
||||
- [getIsAuthenticated](ChatGPTAPI.md#getisauthenticated)
|
||||
- [refreshAccessToken](ChatGPTAPI.md#refreshaccesstoken)
|
||||
- [initSession](ChatGPTAPI.md#initsession)
|
||||
- [refreshSession](ChatGPTAPI.md#refreshsession)
|
||||
- [resetSession](ChatGPTAPI.md#resetsession)
|
||||
- [sendMessage](ChatGPTAPI.md#sendmessage)
|
||||
- [sendModeration](ChatGPTAPI.md#sendmoderation)
|
||||
|
||||
|
@ -51,9 +58,13 @@ to obtain your `clearanceToken`.
|
|||
| `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/108.0.0.0 Safari/537.36'` * |
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[constructor](AChatGPTAPI.md#constructor)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:45](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L45)
|
||||
[src/chatgpt-api.ts:45](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L45)
|
||||
|
||||
## Accessors
|
||||
|
||||
|
@ -69,7 +80,7 @@ Gets the current Cloudflare clearance token (`cf_clearance` cookie value).
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:137](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L137)
|
||||
[src/chatgpt-api.ts:143](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L143)
|
||||
|
||||
___
|
||||
|
||||
|
@ -85,7 +96,7 @@ Gets the current session token.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:132](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L132)
|
||||
[src/chatgpt-api.ts:138](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L138)
|
||||
|
||||
___
|
||||
|
||||
|
@ -101,7 +112,7 @@ Gets the currently signed-in user, if authenticated, `null` otherwise.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:127](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L127)
|
||||
[src/chatgpt-api.ts:133](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L133)
|
||||
|
||||
___
|
||||
|
||||
|
@ -117,51 +128,31 @@ Gets the current user agent.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:142](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L142)
|
||||
[src/chatgpt-api.ts:148](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L148)
|
||||
|
||||
## Methods
|
||||
|
||||
### ensureAuth
|
||||
### closeSession
|
||||
|
||||
▸ **ensureAuth**(): `Promise`<`string`\>
|
||||
▸ **closeSession**(): `Promise`<`void`\>
|
||||
|
||||
Refreshes the client's access token which will succeed only if the session
|
||||
is still valid.
|
||||
Closes the active session.
|
||||
|
||||
**`Throws`**
|
||||
|
||||
An error if it fails.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`string`\>
|
||||
`Promise`<`void`\>
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[closeSession](AChatGPTAPI.md#closesession)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:359](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L359)
|
||||
|
||||
___
|
||||
|
||||
### getConversation
|
||||
|
||||
▸ **getConversation**(`opts?`): [`ChatGPTConversation`](ChatGPTConversation.md)
|
||||
|
||||
Gets a new ChatGPTConversation instance, which can be used to send multiple
|
||||
messages as part of a single conversation.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `opts` | `Object` | - |
|
||||
| `opts.conversationId?` | `string` | Optional ID of the previous message in a conversation |
|
||||
| `opts.parentMessageId?` | `string` | Optional ID of the previous message in a conversation |
|
||||
|
||||
#### Returns
|
||||
|
||||
[`ChatGPTConversation`](ChatGPTConversation.md)
|
||||
|
||||
The new conversation instance
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:465](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L465)
|
||||
[src/chatgpt-api.ts:470](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L470)
|
||||
|
||||
___
|
||||
|
||||
|
@ -176,15 +167,40 @@ ___
|
|||
`true` if the client has a valid acces token or `false` if refreshing
|
||||
the token fails.
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[getIsAuthenticated](AChatGPTAPI.md#getisauthenticated)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:346](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L346)
|
||||
[src/chatgpt-api.ts:367](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L367)
|
||||
|
||||
___
|
||||
|
||||
### refreshAccessToken
|
||||
### initSession
|
||||
|
||||
▸ **refreshAccessToken**(): `Promise`<`string`\>
|
||||
▸ **initSession**(): `Promise`<`void`\>
|
||||
|
||||
Refreshes the client's access token which will succeed only if the session
|
||||
is valid.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`void`\>
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[initSession](AChatGPTAPI.md#initsession)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:156](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L156)
|
||||
|
||||
___
|
||||
|
||||
### refreshSession
|
||||
|
||||
▸ **refreshSession**(): `Promise`<`string`\>
|
||||
|
||||
Attempts to refresh the current access token using the ChatGPT
|
||||
`sessionToken` cookie.
|
||||
|
@ -202,15 +218,47 @@ An error if refreshing the access token fails.
|
|||
|
||||
A valid access token
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[refreshSession](AChatGPTAPI.md#refreshsession)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:373](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L373)
|
||||
[src/chatgpt-api.ts:386](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L386)
|
||||
|
||||
___
|
||||
|
||||
### resetSession
|
||||
|
||||
▸ **resetSession**(): `Promise`<`any`\>
|
||||
|
||||
Closes the current ChatGPT session and starts a new one.
|
||||
|
||||
Useful for bypassing 401 errors when sessions expire.
|
||||
|
||||
**`Throws`**
|
||||
|
||||
An error if it fails.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`any`\>
|
||||
|
||||
Access credentials for the new session.
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[resetSession](AChatGPTAPI.md#resetsession)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/abstract-chatgpt-api.ts:59](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/abstract-chatgpt-api.ts#L59)
|
||||
|
||||
___
|
||||
|
||||
### sendMessage
|
||||
|
||||
▸ **sendMessage**(`message`, `opts?`): `Promise`<`string`\>
|
||||
▸ **sendMessage**(`message`, `opts?`): `Promise`<[`ChatResponse`](../modules.md#chatresponse)\>
|
||||
|
||||
Sends a message to ChatGPT, waits for the response to resolve, and returns
|
||||
the response.
|
||||
|
@ -229,13 +277,17 @@ helper.
|
|||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`string`\>
|
||||
`Promise`<[`ChatResponse`](../modules.md#chatresponse)\>
|
||||
|
||||
The response from ChatGPT
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[sendMessage](AChatGPTAPI.md#sendmessage)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:167](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L167)
|
||||
[src/chatgpt-api.ts:180](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L180)
|
||||
|
||||
___
|
||||
|
||||
|
@ -255,4 +307,4 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api.ts:303](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api.ts#L303)
|
||||
[src/chatgpt-api.ts:324](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api.ts#L324)
|
||||
|
|
|
@ -2,20 +2,31 @@
|
|||
|
||||
# Class: ChatGPTAPIBrowser
|
||||
|
||||
## Hierarchy
|
||||
|
||||
- [`AChatGPTAPI`](AChatGPTAPI.md)
|
||||
|
||||
↳ **`ChatGPTAPIBrowser`**
|
||||
|
||||
## Table of contents
|
||||
|
||||
### Constructors
|
||||
|
||||
- [constructor](ChatGPTAPIBrowser.md#constructor)
|
||||
|
||||
### Accessors
|
||||
|
||||
- [isChatPage](ChatGPTAPIBrowser.md#ischatpage)
|
||||
|
||||
### Methods
|
||||
|
||||
- [\_onRequest](ChatGPTAPIBrowser.md#_onrequest)
|
||||
- [\_onResponse](ChatGPTAPIBrowser.md#_onresponse)
|
||||
- [close](ChatGPTAPIBrowser.md#close)
|
||||
- [closeSession](ChatGPTAPIBrowser.md#closesession)
|
||||
- [getIsAuthenticated](ChatGPTAPIBrowser.md#getisauthenticated)
|
||||
- [handle403Error](ChatGPTAPIBrowser.md#handle403error)
|
||||
- [init](ChatGPTAPIBrowser.md#init)
|
||||
- [initSession](ChatGPTAPIBrowser.md#initsession)
|
||||
- [refreshSession](ChatGPTAPIBrowser.md#refreshsession)
|
||||
- [resetSession](ChatGPTAPIBrowser.md#resetsession)
|
||||
- [resetThread](ChatGPTAPIBrowser.md#resetthread)
|
||||
- [sendMessage](ChatGPTAPIBrowser.md#sendmessage)
|
||||
|
||||
|
@ -25,25 +36,43 @@
|
|||
|
||||
• **new ChatGPTAPIBrowser**(`opts`)
|
||||
|
||||
Creates a new client wrapper for automating the ChatGPT webapp.
|
||||
Creates a new client for automating the ChatGPT webapp.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `opts` | `Object` | - |
|
||||
| `opts.browserPath?` | `string` | **`Default Value`** `undefined` * |
|
||||
| `opts.captchaToken?` | `string` | **`Default Value`** `undefined` * |
|
||||
| `opts.debug?` | `boolean` | **`Default Value`** `false` * |
|
||||
| `opts.email` | `string` | - |
|
||||
| `opts.executablePath?` | `string` | **`Default Value`** `undefined` * |
|
||||
| `opts.isGoogleLogin?` | `boolean` | **`Default Value`** `false` * |
|
||||
| `opts.markdown?` | `boolean` | **`Default Value`** `true` * |
|
||||
| `opts.minimize?` | `boolean` | **`Default Value`** `true` * |
|
||||
| `opts.password` | `string` | - |
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[constructor](AChatGPTAPI.md#constructor)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:32](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api-browser.ts#L32)
|
||||
[src/chatgpt-api-browser.ts:36](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L36)
|
||||
|
||||
## Accessors
|
||||
|
||||
### isChatPage
|
||||
|
||||
• `get` **isChatPage**(): `boolean`
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:524](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L524)
|
||||
|
||||
## Methods
|
||||
|
||||
|
@ -63,7 +92,7 @@ Creates a new client wrapper for automating the ChatGPT webapp.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:153](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api-browser.ts#L153)
|
||||
[src/chatgpt-api-browser.ts:173](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L173)
|
||||
|
||||
___
|
||||
|
||||
|
@ -83,21 +112,31 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:190](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api-browser.ts#L190)
|
||||
[src/chatgpt-api-browser.ts:210](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L210)
|
||||
|
||||
___
|
||||
|
||||
### close
|
||||
### closeSession
|
||||
|
||||
▸ **close**(): `Promise`<`void`\>
|
||||
▸ **closeSession**(): `Promise`<`void`\>
|
||||
|
||||
Closes the active session.
|
||||
|
||||
**`Throws`**
|
||||
|
||||
An error if it fails.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`void`\>
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[closeSession](AChatGPTAPI.md#closesession)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:453](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api-browser.ts#L453)
|
||||
[src/chatgpt-api-browser.ts:512](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L512)
|
||||
|
||||
___
|
||||
|
||||
|
@ -109,37 +148,81 @@ ___
|
|||
|
||||
`Promise`<`boolean`\>
|
||||
|
||||
`true` if the client is authenticated with a valid session or `false`
|
||||
otherwise.
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[getIsAuthenticated](AChatGPTAPI.md#getisauthenticated)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:257](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api-browser.ts#L257)
|
||||
[src/chatgpt-api-browser.ts:302](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L302)
|
||||
|
||||
___
|
||||
|
||||
### handle403Error
|
||||
### initSession
|
||||
|
||||
▸ **handle403Error**(): `Promise`<`void`\>
|
||||
▸ **initSession**(): `Promise`<`void`\>
|
||||
|
||||
Performs any async initialization work required to ensure that this API is
|
||||
properly authenticated.
|
||||
|
||||
**`Throws`**
|
||||
|
||||
An error if the session failed to initialize properly.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`void`\>
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[initSession](AChatGPTAPI.md#initsession)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:238](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api-browser.ts#L238)
|
||||
[src/chatgpt-api-browser.ts:94](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L94)
|
||||
|
||||
___
|
||||
|
||||
### init
|
||||
### refreshSession
|
||||
|
||||
▸ **init**(): `Promise`<`boolean`\>
|
||||
▸ **refreshSession**(): `Promise`<`void`\>
|
||||
|
||||
Attempts to handle 403 errors by refreshing the page.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`boolean`\>
|
||||
`Promise`<`void`\>
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[refreshSession](AChatGPTAPI.md#refreshsession)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:76](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api-browser.ts#L76)
|
||||
[src/chatgpt-api-browser.ts:282](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L282)
|
||||
|
||||
___
|
||||
|
||||
### resetSession
|
||||
|
||||
▸ **resetSession**(): `Promise`<`void`\>
|
||||
|
||||
Attempts to handle 401 errors by re-authenticating.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`void`\>
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[resetSession](AChatGPTAPI.md#resetsession)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:263](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L263)
|
||||
|
||||
___
|
||||
|
||||
|
@ -153,25 +236,37 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:445](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api-browser.ts#L445)
|
||||
[src/chatgpt-api-browser.ts:504](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L504)
|
||||
|
||||
___
|
||||
|
||||
### sendMessage
|
||||
|
||||
▸ **sendMessage**(`message`, `opts?`): `Promise`<`string`\>
|
||||
▸ **sendMessage**(`message`, `opts?`): `Promise`<[`ChatResponse`](../modules.md#chatresponse)\>
|
||||
|
||||
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`.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `message` | `string` |
|
||||
| `opts` | [`SendMessageOptions`](../modules.md#sendmessageoptions) |
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `message` | `string` | The prompt message to send |
|
||||
| `opts` | [`SendMessageOptions`](../modules.md#sendmessageoptions) | - |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`string`\>
|
||||
`Promise`<[`ChatResponse`](../modules.md#chatresponse)\>
|
||||
|
||||
The response from ChatGPT, including `conversationId`, `messageId`, and
|
||||
the `response` text.
|
||||
|
||||
#### Overrides
|
||||
|
||||
[AChatGPTAPI](AChatGPTAPI.md).[sendMessage](AChatGPTAPI.md#sendmessage)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-api-browser.ts:330](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-api-browser.ts#L330)
|
||||
[src/chatgpt-api-browser.ts:379](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/chatgpt-api-browser.ts#L379)
|
||||
|
|
|
@ -1,107 +0,0 @@
|
|||
[chatgpt](../readme.md) / [Exports](../modules.md) / ChatGPTConversation
|
||||
|
||||
# Class: ChatGPTConversation
|
||||
|
||||
A conversation wrapper around the ChatGPTAPI. This allows you to send
|
||||
multiple messages to ChatGPT and receive responses, without having to
|
||||
manually pass the conversation ID and parent message ID for each message.
|
||||
|
||||
## Table of contents
|
||||
|
||||
### Constructors
|
||||
|
||||
- [constructor](ChatGPTConversation.md#constructor)
|
||||
|
||||
### Properties
|
||||
|
||||
- [api](ChatGPTConversation.md#api)
|
||||
- [conversationId](ChatGPTConversation.md#conversationid)
|
||||
- [parentMessageId](ChatGPTConversation.md#parentmessageid)
|
||||
|
||||
### Methods
|
||||
|
||||
- [sendMessage](ChatGPTConversation.md#sendmessage)
|
||||
|
||||
## Constructors
|
||||
|
||||
### constructor
|
||||
|
||||
• **new ChatGPTConversation**(`api`, `opts?`)
|
||||
|
||||
Creates a new conversation wrapper around the ChatGPT API.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `api` | [`ChatGPTAPI`](ChatGPTAPI.md) | The ChatGPT API instance to use |
|
||||
| `opts` | `Object` | - |
|
||||
| `opts.conversationId?` | `string` | Optional ID of a conversation to continue |
|
||||
| `opts.parentMessageId?` | `string` | Optional ID of the previous message in the conversation |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-conversation.ts:21](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-conversation.ts#L21)
|
||||
|
||||
## Properties
|
||||
|
||||
### api
|
||||
|
||||
• **api**: [`ChatGPTAPI`](ChatGPTAPI.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-conversation.ts:10](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-conversation.ts#L10)
|
||||
|
||||
___
|
||||
|
||||
### conversationId
|
||||
|
||||
• **conversationId**: `string` = `undefined`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-conversation.ts:11](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-conversation.ts#L11)
|
||||
|
||||
___
|
||||
|
||||
### parentMessageId
|
||||
|
||||
• **parentMessageId**: `string` = `undefined`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-conversation.ts:12](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-conversation.ts#L12)
|
||||
|
||||
## Methods
|
||||
|
||||
### sendMessage
|
||||
|
||||
▸ **sendMessage**(`message`, `opts?`): `Promise`<`string`\>
|
||||
|
||||
Sends a message to ChatGPT, waits for the response to resolve, and returns
|
||||
the response.
|
||||
|
||||
If this is the first message in the conversation, the conversation ID and
|
||||
parent message ID will be automatically set.
|
||||
|
||||
This allows you to send multiple messages to ChatGPT and receive responses,
|
||||
without having to manually pass the conversation ID and parent message ID
|
||||
for each message.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `message` | `string` | The prompt message to send |
|
||||
| `opts` | [`SendConversationMessageOptions`](../modules.md#sendconversationmessageoptions) | - |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`string`\>
|
||||
|
||||
The response from ChatGPT
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/chatgpt-conversation.ts:48](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/chatgpt-conversation.ts#L48)
|
|
@ -66,7 +66,7 @@ node_modules/.pnpm/typescript@4.9.3/node_modules/typescript/lib/lib.es2022.error
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:298](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L298)
|
||||
[src/types.ts:297](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L297)
|
||||
|
||||
___
|
||||
|
||||
|
@ -76,7 +76,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:297](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L297)
|
||||
[src/types.ts:296](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L296)
|
||||
|
||||
___
|
||||
|
||||
|
@ -86,7 +86,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:295](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L295)
|
||||
[src/types.ts:294](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L294)
|
||||
|
||||
___
|
||||
|
||||
|
@ -96,4 +96,4 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:296](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L296)
|
||||
[src/types.ts:295](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L295)
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
### Classes
|
||||
|
||||
- [AChatGPTAPI](classes/AChatGPTAPI.md)
|
||||
- [ChatGPTAPI](classes/ChatGPTAPI.md)
|
||||
- [ChatGPTAPIBrowser](classes/ChatGPTAPIBrowser.md)
|
||||
- [ChatGPTConversation](classes/ChatGPTConversation.md)
|
||||
- [ChatGPTError](classes/ChatGPTError.md)
|
||||
|
||||
### Type Aliases
|
||||
|
@ -59,7 +59,7 @@
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:109](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L109)
|
||||
[src/types.ts:109](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L109)
|
||||
|
||||
___
|
||||
|
||||
|
@ -72,17 +72,15 @@ ___
|
|||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `conversationId?` | `string` |
|
||||
| `conversationResponse?` | [`ConversationResponseEvent`](modules.md#conversationresponseevent) |
|
||||
| `error` | { `message`: `string` ; `statusCode?`: `number` ; `statusText?`: `string` } |
|
||||
| `error.message` | `string` |
|
||||
| `error.statusCode?` | `number` |
|
||||
| `error.statusText?` | `string` |
|
||||
| `messageId?` | `string` |
|
||||
| `response` | ``null`` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:301](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L301)
|
||||
[src/types.ts:300](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L300)
|
||||
|
||||
___
|
||||
|
||||
|
@ -95,14 +93,12 @@ ___
|
|||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `conversationId` | `string` |
|
||||
| `conversationResponse?` | [`ConversationResponseEvent`](modules.md#conversationresponseevent) |
|
||||
| `error` | ``null`` |
|
||||
| `messageId` | `string` |
|
||||
| `response` | `string` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:309](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L309)
|
||||
[src/types.ts:306](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L306)
|
||||
|
||||
___
|
||||
|
||||
|
@ -112,7 +108,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:1](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L1)
|
||||
[src/types.ts:1](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L1)
|
||||
|
||||
___
|
||||
|
||||
|
@ -134,7 +130,7 @@ https://chat.openapi.com/backend-api/conversation
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:134](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L134)
|
||||
[src/types.ts:134](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L134)
|
||||
|
||||
___
|
||||
|
||||
|
@ -152,7 +148,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:251](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L251)
|
||||
[src/types.ts:251](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L251)
|
||||
|
||||
___
|
||||
|
||||
|
@ -177,7 +173,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:257](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L257)
|
||||
[src/types.ts:257](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L257)
|
||||
|
||||
___
|
||||
|
||||
|
@ -187,7 +183,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:276](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L276)
|
||||
[src/types.ts:276](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L276)
|
||||
|
||||
___
|
||||
|
||||
|
@ -204,7 +200,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:270](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L270)
|
||||
[src/types.ts:270](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L270)
|
||||
|
||||
___
|
||||
|
||||
|
@ -226,7 +222,7 @@ https://chat.openapi.com/backend-api/conversation/message_feedback
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:193](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L193)
|
||||
[src/types.ts:193](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L193)
|
||||
|
||||
___
|
||||
|
||||
|
@ -236,7 +232,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:249](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L249)
|
||||
[src/types.ts:249](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L249)
|
||||
|
||||
___
|
||||
|
||||
|
@ -256,7 +252,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:222](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L222)
|
||||
[src/types.ts:222](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L222)
|
||||
|
||||
___
|
||||
|
||||
|
@ -266,7 +262,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:220](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L220)
|
||||
[src/types.ts:220](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L220)
|
||||
|
||||
___
|
||||
|
||||
|
@ -276,7 +272,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:275](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L275)
|
||||
[src/types.ts:275](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L275)
|
||||
|
||||
___
|
||||
|
||||
|
@ -294,7 +290,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:77](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L77)
|
||||
[src/types.ts:77](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L77)
|
||||
|
||||
___
|
||||
|
||||
|
@ -312,7 +308,7 @@ https://chat.openapi.com/backend-api/models
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:70](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L70)
|
||||
[src/types.ts:70](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L70)
|
||||
|
||||
___
|
||||
|
||||
|
@ -331,7 +327,7 @@ https://chat.openapi.com/backend-api/moderations
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:97](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L97)
|
||||
[src/types.ts:97](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L97)
|
||||
|
||||
___
|
||||
|
||||
|
@ -351,7 +347,7 @@ https://chat.openapi.com/backend-api/moderations
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:114](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L114)
|
||||
[src/types.ts:114](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L114)
|
||||
|
||||
___
|
||||
|
||||
|
@ -373,7 +369,7 @@ to authenticate with the unofficial ChatGPT API.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/openai-auth.ts:20](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/openai-auth.ts#L20)
|
||||
[src/openai-auth.ts:27](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/openai-auth.ts#L27)
|
||||
|
||||
___
|
||||
|
||||
|
@ -391,7 +387,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:161](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L161)
|
||||
[src/types.ts:161](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L161)
|
||||
|
||||
___
|
||||
|
||||
|
@ -408,7 +404,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:178](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L178)
|
||||
[src/types.ts:178](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L178)
|
||||
|
||||
___
|
||||
|
||||
|
@ -418,7 +414,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:3](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L3)
|
||||
[src/types.ts:3](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L3)
|
||||
|
||||
___
|
||||
|
||||
|
@ -428,7 +424,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:289](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L289)
|
||||
[src/types.ts:288](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L288)
|
||||
|
||||
___
|
||||
|
||||
|
@ -444,14 +440,13 @@ ___
|
|||
| `action?` | [`MessageActionType`](modules.md#messageactiontype) |
|
||||
| `conversationId?` | `string` |
|
||||
| `messageId?` | `string` |
|
||||
| `onConversationResponse?` | (`response`: [`ConversationResponseEvent`](modules.md#conversationresponseevent)) => `void` |
|
||||
| `onProgress?` | (`partialResponse`: `string`) => `void` |
|
||||
| `onProgress?` | (`partialResponse`: [`ChatResponse`](modules.md#chatresponse)) => `void` |
|
||||
| `parentMessageId?` | `string` |
|
||||
| `timeoutMs?` | `number` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:278](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L278)
|
||||
[src/types.ts:278](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L278)
|
||||
|
||||
___
|
||||
|
||||
|
@ -472,7 +467,7 @@ https://chat.openapi.com/api/auth/session
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:8](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L8)
|
||||
[src/types.ts:8](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L8)
|
||||
|
||||
___
|
||||
|
||||
|
@ -494,7 +489,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/types.ts:30](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/types.ts#L30)
|
||||
[src/types.ts:30](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/types.ts#L30)
|
||||
|
||||
## Functions
|
||||
|
||||
|
@ -521,7 +516,7 @@ included them in here.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/utils.ts:73](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/utils.ts#L73)
|
||||
[src/utils.ts:73](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/utils.ts#L73)
|
||||
|
||||
___
|
||||
|
||||
|
@ -537,7 +532,7 @@ Gets the default path to chrome's executable for the current platform.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/openai-auth.ts:224](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/openai-auth.ts#L224)
|
||||
[src/openai-auth.ts:299](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/openai-auth.ts#L299)
|
||||
|
||||
___
|
||||
|
||||
|
@ -553,7 +548,7 @@ recognizes it and blocks access.
|
|||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `opts` | `PuppeteerLaunchOptions` & { `captchaToken?`: `string` } |
|
||||
| `opts` | `PuppeteerLaunchOptions` & { `captchaToken?`: `string` ; `nopechaKey?`: `string` } |
|
||||
|
||||
#### Returns
|
||||
|
||||
|
@ -561,7 +556,7 @@ recognizes it and blocks access.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/openai-auth.ts:186](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/openai-auth.ts#L186)
|
||||
[src/openai-auth.ts:201](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/openai-auth.ts#L201)
|
||||
|
||||
___
|
||||
|
||||
|
@ -603,7 +598,7 @@ with your updated credentials.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/openai-auth.ts:42](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/openai-auth.ts#L42)
|
||||
[src/openai-auth.ts:49](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/openai-auth.ts#L49)
|
||||
|
||||
___
|
||||
|
||||
|
@ -623,7 +618,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/utils.ts:39](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/utils.ts#L39)
|
||||
[src/utils.ts:39](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/utils.ts#L39)
|
||||
|
||||
___
|
||||
|
||||
|
@ -643,7 +638,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/utils.ts:12](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/utils.ts#L12)
|
||||
[src/utils.ts:12](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/utils.ts#L12)
|
||||
|
||||
___
|
||||
|
||||
|
@ -663,7 +658,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/utils.ts:29](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/utils.ts#L29)
|
||||
[src/utils.ts:29](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/utils.ts#L29)
|
||||
|
||||
___
|
||||
|
||||
|
@ -683,4 +678,4 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/utils.ts:19](https://github.com/transitive-bullshit/chatgpt-api/blob/d685b78/src/utils.ts#L19)
|
||||
[src/utils.ts:19](https://github.com/transitive-bullshit/chatgpt-api/blob/2937409/src/utils.ts#L19)
|
||||
|
|
|
@ -19,9 +19,10 @@ const api = new ChatGPTAPIBrowser({
|
|||
email: process.env.OPENAI_EMAIL,
|
||||
password: process.env.OPENAI_PASSWORD
|
||||
})
|
||||
await api.init()
|
||||
await api.initSession()
|
||||
|
||||
const response = await api.sendMessage('Hello World!')
|
||||
const result = await api.sendMessage('Hello World!')
|
||||
console.log(result.response)
|
||||
```
|
||||
|
||||
Note that this solution is not lightweight, but it does work a lot more consistently than the REST API-based versions. I'm currently using this solution to power 10 OpenAI accounts concurrently across 10 minimized Chrome windows for my [Twitter bot](https://github.com/transitive-bullshit/chatgpt-twitter-bot). 😂
|
||||
|
@ -88,15 +89,13 @@ async function example() {
|
|||
})
|
||||
|
||||
const api = new ChatGPTAPI({ ...openAIAuth })
|
||||
await api.ensureAuth()
|
||||
await api.initSession()
|
||||
|
||||
// send a message and wait for the response
|
||||
const response = await api.sendMessage(
|
||||
'Write a python version of bubble sort.'
|
||||
)
|
||||
const result = await api.sendMessage('Write a python version of bubble sort.')
|
||||
|
||||
// response is a markdown-formatted string
|
||||
console.log(response)
|
||||
// result.response is a markdown-formatted string
|
||||
console.log(result.response)
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -112,10 +111,10 @@ async function example() {
|
|||
password: process.env.OPENAI_PASSWORD
|
||||
})
|
||||
|
||||
await api.init()
|
||||
await api.initSession()
|
||||
|
||||
const response = await api.sendMessage('Hello World!')
|
||||
console.log(response)
|
||||
const result = await api.sendMessage('Hello World!')
|
||||
console.log(result.response)
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -125,21 +124,30 @@ ChatGPT responses are formatted as markdown by default. If you want to work with
|
|||
const api = new ChatGPTAPI({ ...openAIAuth, markdown: false })
|
||||
```
|
||||
|
||||
If you want to automatically track the conversation, you can use `ChatGPTAPI.getConversation()`:
|
||||
If you want to track the conversation, use the `conversationId` and `messageId` in the result object, and pass them to `sendMessage` as `conversationId` and `parentMessageId` respectively.
|
||||
|
||||
```ts
|
||||
const api = new ChatGPTAPI({ ...openAIAuth, markdown: false })
|
||||
|
||||
const conversation = api.getConversation()
|
||||
await api.initSession()
|
||||
|
||||
// send a message and wait for the response
|
||||
const response0 = await conversation.sendMessage('What is OpenAI?')
|
||||
let res = await conversation.sendMessage('What is OpenAI?')
|
||||
console.log(res.response)
|
||||
|
||||
// send a follow-up
|
||||
const response1 = await conversation.sendMessage('Can you expand on that?')
|
||||
res = await conversation.sendMessage('Can you expand on that?', {
|
||||
conversationId: res.conversationId,
|
||||
parentMessageId: res.messageId
|
||||
})
|
||||
console.log(res.response)
|
||||
|
||||
// send another follow-up
|
||||
const response2 = await conversation.sendMessage('Oh cool; thank you')
|
||||
// send a follow-up
|
||||
res = await conversation.sendMessage('What were we talking about?', {
|
||||
conversationId: res.conversationId,
|
||||
parentMessageId: res.messageId
|
||||
})
|
||||
console.log(res.response)
|
||||
```
|
||||
|
||||
Sometimes, ChatGPT will hang for an extended period of time before beginning to respond. This may be due to rate limiting or it may be due to OpenAI's servers being overloaded.
|
||||
|
@ -153,8 +161,6 @@ const response = await api.sendMessage('this is a timeout test', {
|
|||
})
|
||||
```
|
||||
|
||||
You can stream responses using the `onProgress` or `onConversationResponse` callbacks. See the [docs](./docs/classes/ChatGPTAPI.md) for more details.
|
||||
|
||||
<details>
|
||||
<summary>Usage in CommonJS (Dynamic import)</summary>
|
||||
|
||||
|
@ -169,10 +175,10 @@ async function example() {
|
|||
})
|
||||
|
||||
const api = new ChatGPTAPI({ ...openAIAuth })
|
||||
await api.ensureAuth()
|
||||
await api.initSession()
|
||||
|
||||
const response = await api.sendMessage('Hello World!')
|
||||
console.log(response)
|
||||
const result = await api.sendMessage('Hello World!')
|
||||
console.log(result)
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ test('ChatGPTAPI invalid session token', async (t) => {
|
|||
sessionToken: 'invalid',
|
||||
clearanceToken: 'invalid'
|
||||
})
|
||||
await chatgpt.ensureAuth()
|
||||
await chatgpt.initSession()
|
||||
},
|
||||
{
|
||||
instanceOf: types.ChatGPTError,
|
||||
|
@ -52,7 +52,7 @@ test('ChatGPTAPI valid session token', async (t) => {
|
|||
|
||||
// Don't make any real API calls using our session token if we're running on CI
|
||||
if (!isCI) {
|
||||
await chatgpt.ensureAuth()
|
||||
await chatgpt.initSession()
|
||||
const response = await chatgpt.sendMessage('test')
|
||||
console.log('chatgpt response', response)
|
||||
|
||||
|
@ -74,7 +74,7 @@ if (!isCI) {
|
|||
sessionToken: expiredSessionToken,
|
||||
clearanceToken: 'invalid'
|
||||
})
|
||||
await chatgpt.ensureAuth()
|
||||
await chatgpt.initSession()
|
||||
},
|
||||
{
|
||||
instanceOf: types.ChatGPTError,
|
||||
|
|
Ładowanie…
Reference in New Issue