chore: update auto-generated docs

pull/38/head
Travis Fischer 2022-12-06 22:37:56 -06:00
rodzic 92318f1e49
commit f723ae5c4d
4 zmienionych plików z 151 dodań i 61 usunięć

Wyświetl plik

@ -29,6 +29,7 @@ Creates a new client wrapper around the unofficial ChatGPT REST API.
| Name | Type | Description |
| :------ | :------ | :------ |
| `opts` | `Object` | - |
| `opts.accessTokenTTL?` | `number` | **`Default Value`** 60000 (60 seconds) |
| `opts.apiBaseUrl?` | `string` | **`Default Value`** `'https://chat.openai.com/api'` * |
| `opts.backendApiBaseUrl?` | `string` | **`Default Value`** `'https://chat.openai.com/backend-api'` * |
| `opts.markdown?` | `boolean` | **`Default Value`** `true` * |
@ -37,7 +38,7 @@ Creates a new client wrapper around the unofficial ChatGPT REST API.
#### Defined in
[chatgpt-api.ts:32](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-api.ts#L32)
[chatgpt-api.ts:35](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-api.ts#L35)
## Methods
@ -45,13 +46,16 @@ Creates a new client wrapper around the unofficial ChatGPT REST API.
**ensureAuth**(): `Promise`<`string`\>
Refreshes the client's access token which will succeed only if the session
is still valid.
#### Returns
`Promise`<`string`\>
#### Defined in
[chatgpt-api.ts:75](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-api.ts#L75)
[chatgpt-api.ts:221](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-api.ts#L221)
___
@ -78,7 +82,7 @@ The new conversation instance
#### Defined in
[chatgpt-api.ts:233](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-api.ts#L233)
[chatgpt-api.ts:285](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-api.ts#L285)
___
@ -90,9 +94,12 @@ ___
`Promise`<`boolean`\>
`true` if the client has a valid acces token or `false` if refreshing
the token fails.
#### Defined in
[chatgpt-api.ts:66](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-api.ts#L66)
[chatgpt-api.ts:208](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-api.ts#L208)
___
@ -100,13 +107,25 @@ ___
**refreshAccessToken**(): `Promise`<`string`\>
Attempts to refresh the current access token using the ChatGPT
`sessionToken` cookie.
Access tokens will be cached for up to `accessTokenTTL` milliseconds to
prevent refreshing access tokens too frequently.
**`Throws`**
An error if refreshing the access token fails.
#### Returns
`Promise`<`string`\>
A valid access token
#### Defined in
[chatgpt-api.ts:183](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-api.ts#L183)
[chatgpt-api.ts:235](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-api.ts#L235)
___
@ -117,6 +136,11 @@ ___
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`.
If you want to receive the full response, including message and conversation IDs,
you can use `opts.onConversationResponse` or use the `ChatGPTAPI.getConversation`
helper.
#### Parameters
| Name | Type | Description |
@ -132,4 +156,4 @@ The response from ChatGPT
#### Defined in
[chatgpt-api.ts:92](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-api.ts#L92)
[chatgpt-api.ts:94](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-api.ts#L94)

Wyświetl plik

@ -41,7 +41,7 @@ Creates a new conversation wrapper around the ChatGPT API.
#### Defined in
[chatgpt-conversation.ts:21](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-conversation.ts#L21)
[chatgpt-conversation.ts:21](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-conversation.ts#L21)
## Properties
@ -51,7 +51,7 @@ Creates a new conversation wrapper around the ChatGPT API.
#### Defined in
[chatgpt-conversation.ts:10](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-conversation.ts#L10)
[chatgpt-conversation.ts:10](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-conversation.ts#L10)
___
@ -61,7 +61,7 @@ ___
#### Defined in
[chatgpt-conversation.ts:11](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-conversation.ts#L11)
[chatgpt-conversation.ts:11](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-conversation.ts#L11)
___
@ -71,7 +71,7 @@ ___
#### Defined in
[chatgpt-conversation.ts:12](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-conversation.ts#L12)
[chatgpt-conversation.ts:12](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-conversation.ts#L12)
## Methods
@ -104,4 +104,4 @@ The response from ChatGPT
#### Defined in
[chatgpt-conversation.ts:48](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/chatgpt-conversation.ts#L48)
[chatgpt-conversation.ts:48](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/chatgpt-conversation.ts#L48)

Wyświetl plik

@ -46,7 +46,7 @@
#### Defined in
[types.ts:109](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L109)
[types.ts:109](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L109)
___
@ -56,7 +56,7 @@ ___
#### Defined in
[types.ts:1](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L1)
[types.ts:1](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L1)
___
@ -78,7 +78,7 @@ https://chat.openapi.com/backend-api/conversation
#### Defined in
[types.ts:134](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L134)
[types.ts:134](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L134)
___
@ -96,7 +96,7 @@ ___
#### Defined in
[types.ts:251](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L251)
[types.ts:251](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L251)
___
@ -121,7 +121,7 @@ ___
#### Defined in
[types.ts:257](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L257)
[types.ts:257](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L257)
___
@ -138,7 +138,7 @@ ___
#### Defined in
[types.ts:270](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L270)
[types.ts:270](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L270)
___
@ -160,7 +160,7 @@ https://chat.openapi.com/backend-api/conversation/message_feedback
#### Defined in
[types.ts:193](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L193)
[types.ts:193](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L193)
___
@ -170,7 +170,7 @@ ___
#### Defined in
[types.ts:249](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L249)
[types.ts:249](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L249)
___
@ -190,7 +190,7 @@ ___
#### Defined in
[types.ts:222](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L222)
[types.ts:222](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L222)
___
@ -200,7 +200,7 @@ ___
#### Defined in
[types.ts:220](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L220)
[types.ts:220](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L220)
___
@ -210,7 +210,7 @@ ___
#### Defined in
[types.ts:275](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L275)
[types.ts:275](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L275)
___
@ -228,7 +228,7 @@ ___
#### Defined in
[types.ts:77](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L77)
[types.ts:77](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L77)
___
@ -246,7 +246,7 @@ https://chat.openapi.com/backend-api/models
#### Defined in
[types.ts:70](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L70)
[types.ts:70](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L70)
___
@ -265,7 +265,7 @@ https://chat.openapi.com/backend-api/moderations
#### Defined in
[types.ts:97](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L97)
[types.ts:97](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L97)
___
@ -285,7 +285,7 @@ https://chat.openapi.com/backend-api/moderations
#### Defined in
[types.ts:114](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L114)
[types.ts:114](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L114)
___
@ -303,7 +303,7 @@ ___
#### Defined in
[types.ts:161](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L161)
[types.ts:161](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L161)
___
@ -320,7 +320,7 @@ ___
#### Defined in
[types.ts:178](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L178)
[types.ts:178](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L178)
___
@ -330,7 +330,7 @@ ___
#### Defined in
[types.ts:3](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L3)
[types.ts:3](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L3)
___
@ -340,7 +340,7 @@ ___
#### Defined in
[types.ts:285](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L285)
[types.ts:286](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L286)
___
@ -357,10 +357,11 @@ ___
| `onConversationResponse?` | (`response`: [`ConversationResponseEvent`](modules.md#conversationresponseevent)) => `void` |
| `onProgress?` | (`partialResponse`: `string`) => `void` |
| `parentMessageId?` | `string` |
| `timeoutMs?` | `number` |
#### Defined in
[types.ts:277](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L277)
[types.ts:277](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L277)
___
@ -381,7 +382,7 @@ https://chat.openapi.com/api/auth/session
#### Defined in
[types.ts:8](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L8)
[types.ts:8](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L8)
___
@ -403,7 +404,7 @@ ___
#### Defined in
[types.ts:30](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/types.ts#L30)
[types.ts:30](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/types.ts#L30)
## Functions
@ -423,4 +424,4 @@ ___
#### Defined in
[utils.ts:4](https://github.com/transitive-bullshit/chatgpt-api/blob/8e045b2/src/utils.ts#L4)
[utils.ts:4](https://github.com/transitive-bullshit/chatgpt-api/blob/042b2fe/src/utils.ts#L4)

Wyświetl plik

@ -13,11 +13,12 @@ chatgpt / [Exports](modules.md)
- [Intro](#intro)
- [Install](#install)
- [Usage](#usage)
- [Docs](#docs)
- [How it works](#how-it-works)
- [Docs](#docs)
- [Demos](#demos)
- [Session Tokens](#session-tokens)
- [Projects](#projects)
- [Compatibility](#compatibility)
- [Examples](#examples)
- [Credit](#credit)
- [Credits](#credits)
- [License](#license)
## Intro
@ -39,7 +40,9 @@ import { ChatGPTAPI } from 'chatgpt'
async function example() {
// sessionToken is required; see below for details
const api = new ChatGPTAPI({ sessionToken: process.env.SESSION_TOKEN })
const api = new ChatGPTAPI({
sessionToken: process.env.SESSION_TOKEN
})
// ensure the API is properly authenticated
await api.ensureAuth()
@ -54,7 +57,7 @@ async function example() {
}
```
By default, the response will be formatted as markdown. If you want to work with plaintext only, you can use:
The default ChatGPT responses are formatted as markdown. If you want to work with plaintext only, you can use:
```ts
const api = new ChatGPTAPI({
@ -63,7 +66,63 @@ const api = new ChatGPTAPI({
})
```
A full [demo](./src/demo.ts) is included for testing purposes:
If you want to automatically track the conversation, you can use `ChatGPTAPI.getConversation()`:
```ts
const api = new ChatGPTAPI({
sessionToken: process.env.SESSION_TOKEN
})
const conversation = api.getConversation()
// send a message and wait for the response
const response0 = await conversation.sendMessage('What is OpenAI?')
// send a follow-up prompt to the previous message and wait for the response
const response1 = await conversation.sendMessage('Can you expand on that?')
// send another follow-up to the same conversation
const response2 = await conversation.sendMessage('Oh cool; thank you')
```
Sometimes, ChatGPT will hang for an extended period of time before sending it's response. This may be due to rate limiting or it may be due to OpenAI's servers being overloaded.
To mitigate this issues, you can add a timeout like this:
```ts
// timeout after 2 minutes (which will also abort the underlying HTTP request)
const response = await api.sendMessage('this is a timeout test', {
timeoutMs: 2 * 60 * 1000
})
```
<details>
<summary>Usage in CommonJS (Dynamic import)</summary>
```js
async function example() {
// To use ESM in CommonJS, you can use a dynamic import
const { ChatGPTAPI } = await import('chatgpt')
const api = new ChatGPTAPI({
sessionToken: process.env.SESSION_TOKEN
})
await api.ensureAuth()
const response = await api.sendMessage('Hello World!')
console.log(response)
}
```
</details>
### Docs
See the [auto-generated docs](./docs/classes/ChatGPTAPI.md) for more info on methods and parameters.
### Demos
A [basic demo](./src/demo.ts) is included for testing purposes:
```bash
# 1. clone repo
@ -73,11 +132,17 @@ A full [demo](./src/demo.ts) is included for testing purposes:
npx tsx src/demo.ts
```
## Docs
A [conversation demo](./src/demo-conversation.ts) is also included:
See the [auto-generated docs](./docs/classes/ChatGPTAPI.md) for more info on methods and parameters.
```bash
# 1. clone repo
# 2. install node deps
# 3. set `SESSION_TOKEN` in .env
# 4. run:
npx tsx src/demo-conversation.ts
```
## How it works
### Session Tokens
**This package requires a valid session token from ChatGPT to access it's unofficial REST API.**
@ -97,20 +162,7 @@ If you want to run the built-in demo, store this value as `SESSION_TOKEN` in a l
> **Note**
> Prior to v1.0.0, this package used a headless browser via [Playwright](https://playwright.dev/) to automate the web UI. Here are the [docs for the initial browser version](https://github.com/transitive-bullshit/chatgpt-api/tree/v0.4.2).
## Compatibility
This package is ESM-only. It supports:
- Node.js >= 16.8
- If you need Node.js 14 support, use [`v1.4.0`](https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v1.4.0)
- If you need CommonJS support, use [`v1.3.0`](https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v1.3.0)
- Edge runtimes like CF workers and Vercel edge functions
- Modern browsers
- This is mainly intended for chrome extensions where your code is protected to a degree
- **We do not recommend using `chatgpt` from client-side browser code** because it would expose your private session token
- If you want to build a website with `chatgpt`, we recommend using it only from your backend API
## Examples
## Projects
All of these awesome projects are built using the `chatgpt` package. 🤯
@ -118,7 +170,8 @@ All of these awesome projects are built using the `chatgpt` package. 🤯
- Mention [@ChatGPTBot](https://twitter.com/ChatGPTBot) on Twitter with your prompt to try it out
- [Chrome Extension](https://github.com/gragland/chatgpt-everywhere) ([demo](https://twitter.com/gabe_ragland/status/1599466486422470656))
- [VSCode Extension #1](https://github.com/mpociot/chatgpt-vscode) ([demo](https://twitter.com/marcelpociot/status/1599180144551526400))
- [VSCode Extension #2](https://github.com/barnesoir/chatgpt-vscode-plugin)
- [VSCode Extension #2](https://github.com/barnesoir/chatgpt-vscode-plugin) ([marketplace](https://marketplace.visualstudio.com/items?itemName=JayBarnes.chatgpt-vscode-plugin))
- [VSCode Extension #3](https://github.com/gencay/vscode-chatgpt) ([marketplace](https://marketplace.visualstudio.com/items?itemName=gencay.vscode-chatgpt))
- [Raycast Extension](https://github.com/abielzulio/chatgpt-raycast) ([demo](https://twitter.com/abielzulio/status/1600176002042191875))
- [Go Telegram Bot](https://github.com/m1guelpf/chatgpt-telegram)
- [GitHub ProBot](https://github.com/oceanlvr/ChatGPTBot)
@ -130,7 +183,19 @@ All of these awesome projects are built using the `chatgpt` package. 🤯
If you create a cool integration, feel free to open a PR and add it to the list.
## Credit
## Compatibility
This package is ESM-only. It supports:
- Node.js >= 16.8
- If you need Node.js 14 support, use [`v1.4.0`](https://github.com/transitive-bullshit/chatgpt-api/releases/tag/v1.4.0)
- Edge runtimes like CF workers and Vercel edge functions
- Modern browsers
- Mainly chrome extensions where your code is protected to a degree
- **We do not recommend using `chatgpt` from client-side browser code** because it would expose your private session token
- If you want to build a website using `chatgpt`, we recommend using it only from your backend API
## Credits
- Huge thanks to [@RomanHotsiy](https://github.com/RomanHotsiy), [@ElijahPepe](https://github.com/ElijahPepe), and all the other contributors 💪
- The original browser version was inspired by this [Go module](https://github.com/danielgross/whatsapp-gpt) by [Daniel Gross](https://github.com/danielgross)
@ -140,4 +205,4 @@ If you create a cool integration, feel free to open a PR and add it to the list.
MIT © [Travis Fischer](https://transitivebullsh.it)
If you found this project interesting, please consider supporting my open source work by [sponsoring me](https://github.com/sponsors/transitive-bullshit) or <a href="https://twitter.com/transitive_bs">following me on twitter <img src="https://storage.googleapis.com/saasify-assets/twitter-logo.svg" alt="twitter" height="24px" align="center"></a>
If you found this project interesting, please consider [sponsoring me](https://github.com/sponsors/transitive-bullshit) or <a href="https://twitter.com/transitive_bs">following me on twitter <img src="https://storage.googleapis.com/saasify-assets/twitter-logo.svg" alt="twitter" height="24px" align="center"></a>