chatgpt-api/docs/classes/ChatGPTAPIBrowser.md

273 wiersze
5.8 KiB
Markdown
Czysty Zwykły widok Historia

2022-12-15 23:15:38 +00:00
[chatgpt](../readme.md) / [Exports](../modules.md) / ChatGPTAPIBrowser
# Class: ChatGPTAPIBrowser
2022-12-17 09:57:22 +00:00
## Hierarchy
- [`AChatGPTAPI`](AChatGPTAPI.md)
**`ChatGPTAPIBrowser`**
2022-12-15 23:15:38 +00:00
## Table of contents
### Constructors
- [constructor](ChatGPTAPIBrowser.md#constructor)
2022-12-17 09:57:22 +00:00
### Accessors
- [isChatPage](ChatGPTAPIBrowser.md#ischatpage)
2022-12-15 23:15:38 +00:00
### Methods
- [\_onRequest](ChatGPTAPIBrowser.md#_onrequest)
- [\_onResponse](ChatGPTAPIBrowser.md#_onresponse)
2022-12-17 09:57:22 +00:00
- [closeSession](ChatGPTAPIBrowser.md#closesession)
2022-12-15 23:15:38 +00:00
- [getIsAuthenticated](ChatGPTAPIBrowser.md#getisauthenticated)
2022-12-17 09:57:22 +00:00
- [initSession](ChatGPTAPIBrowser.md#initsession)
- [refreshSession](ChatGPTAPIBrowser.md#refreshsession)
- [resetSession](ChatGPTAPIBrowser.md#resetsession)
2022-12-15 23:15:38 +00:00
- [resetThread](ChatGPTAPIBrowser.md#resetthread)
- [sendMessage](ChatGPTAPIBrowser.md#sendmessage)
## Constructors
### constructor
**new ChatGPTAPIBrowser**(`opts`)
2022-12-17 09:57:22 +00:00
Creates a new client for automating the ChatGPT webapp.
2022-12-15 23:15:38 +00:00
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `opts` | `Object` | - |
2022-12-16 07:38:20 +00:00
| `opts.captchaToken?` | `string` | **`Default Value`** `undefined` * |
2022-12-15 23:15:38 +00:00
| `opts.debug?` | `boolean` | **`Default Value`** `false` * |
| `opts.email` | `string` | - |
2022-12-17 09:57:22 +00:00
| `opts.executablePath?` | `string` | **`Default Value`** `undefined` * |
2022-12-16 07:38:20 +00:00
| `opts.isGoogleLogin?` | `boolean` | **`Default Value`** `false` * |
2022-12-15 23:15:38 +00:00
| `opts.markdown?` | `boolean` | **`Default Value`** `true` * |
2022-12-16 07:38:20 +00:00
| `opts.minimize?` | `boolean` | **`Default Value`** `true` * |
2022-12-15 23:15:38 +00:00
| `opts.password` | `string` | - |
2022-12-17 09:57:22 +00:00
#### Overrides
[AChatGPTAPI](AChatGPTAPI.md).[constructor](AChatGPTAPI.md#constructor)
2022-12-15 23:15:38 +00:00
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:36](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L36)
2022-12-17 09:57:22 +00:00
## Accessors
### isChatPage
`get` **isChatPage**(): `boolean`
#### Returns
`boolean`
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:524](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L524)
2022-12-15 23:15:38 +00:00
## Methods
### \_onRequest
**_onRequest**(`request`): `void`
#### Parameters
| Name | Type |
| :------ | :------ |
| `request` | `HTTPRequest` |
#### Returns
`void`
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:173](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L173)
2022-12-15 23:15:38 +00:00
___
### \_onResponse
**_onResponse**(`response`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `response` | `HTTPResponse` |
#### Returns
`Promise`<`void`\>
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:210](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L210)
2022-12-15 23:15:38 +00:00
___
2022-12-17 09:57:22 +00:00
### closeSession
**closeSession**(): `Promise`<`void`\>
Closes the active session.
**`Throws`**
2022-12-15 23:15:38 +00:00
2022-12-17 09:57:22 +00:00
An error if it fails.
2022-12-15 23:15:38 +00:00
#### Returns
`Promise`<`void`\>
2022-12-17 09:57:22 +00:00
#### Overrides
[AChatGPTAPI](AChatGPTAPI.md).[closeSession](AChatGPTAPI.md#closesession)
2022-12-15 23:15:38 +00:00
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:512](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L512)
2022-12-15 23:15:38 +00:00
___
### getIsAuthenticated
**getIsAuthenticated**(): `Promise`<`boolean`\>
#### Returns
`Promise`<`boolean`\>
2022-12-17 09:57:22 +00:00
`true` if the client is authenticated with a valid session or `false`
otherwise.
#### Overrides
[AChatGPTAPI](AChatGPTAPI.md).[getIsAuthenticated](AChatGPTAPI.md#getisauthenticated)
2022-12-15 23:15:38 +00:00
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:302](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L302)
2022-12-15 23:15:38 +00:00
___
2022-12-17 09:57:22 +00:00
### initSession
**initSession**(): `Promise`<`void`\>
Performs any async initialization work required to ensure that this API is
properly authenticated.
2022-12-15 23:15:38 +00:00
2022-12-17 09:57:22 +00:00
**`Throws`**
An error if the session failed to initialize properly.
2022-12-15 23:15:38 +00:00
#### Returns
`Promise`<`void`\>
2022-12-17 09:57:22 +00:00
#### Overrides
[AChatGPTAPI](AChatGPTAPI.md).[initSession](AChatGPTAPI.md#initsession)
2022-12-15 23:15:38 +00:00
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:94](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L94)
2022-12-15 23:15:38 +00:00
___
2022-12-17 09:57:22 +00:00
### refreshSession
2022-12-15 23:15:38 +00:00
2022-12-17 09:57:22 +00:00
**refreshSession**(): `Promise`<`void`\>
Attempts to handle 403 errors by refreshing the page.
2022-12-15 23:15:38 +00:00
#### Returns
2022-12-17 09:57:22 +00:00
`Promise`<`void`\>
#### Overrides
[AChatGPTAPI](AChatGPTAPI.md).[refreshSession](AChatGPTAPI.md#refreshsession)
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:282](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L282)
2022-12-17 09:57:22 +00:00
___
### resetSession
**resetSession**(): `Promise`<`void`\>
Attempts to handle 401 errors by re-authenticating.
#### Returns
`Promise`<`void`\>
#### Overrides
[AChatGPTAPI](AChatGPTAPI.md).[resetSession](AChatGPTAPI.md#resetsession)
2022-12-15 23:15:38 +00:00
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:263](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L263)
2022-12-15 23:15:38 +00:00
___
### resetThread
**resetThread**(): `Promise`<`void`\>
#### Returns
`Promise`<`void`\>
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:504](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L504)
2022-12-15 23:15:38 +00:00
___
### sendMessage
2022-12-17 09:57:22 +00:00
**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`.
2022-12-15 23:15:38 +00:00
#### Parameters
2022-12-17 09:57:22 +00:00
| Name | Type | Description |
| :------ | :------ | :------ |
| `message` | `string` | The prompt message to send |
| `opts` | [`SendMessageOptions`](../modules.md#sendmessageoptions) | - |
2022-12-15 23:15:38 +00:00
#### Returns
2022-12-17 09:57:22 +00:00
`Promise`<[`ChatResponse`](../modules.md#chatresponse)\>
The response from ChatGPT, including `conversationId`, `messageId`, and
the `response` text.
#### Overrides
[AChatGPTAPI](AChatGPTAPI.md).[sendMessage](AChatGPTAPI.md#sendmessage)
2022-12-15 23:15:38 +00:00
#### Defined in
2022-12-17 10:02:22 +00:00
[src/chatgpt-api-browser.ts:379](https://github.com/transitive-bullshit/chatgpt-api/blob/88efa64/src/chatgpt-api-browser.ts#L379)