Commit ed92e9de authored by Travis Fischer's avatar Travis Fischer

chore: update docs

parent c9cef796
...@@ -36,7 +36,7 @@ Creates a new client wrapper around the unofficial ChatGPT REST API. ...@@ -36,7 +36,7 @@ Creates a new client wrapper around the unofficial ChatGPT REST API.
#### Defined in #### Defined in
[chatgpt-api.ts:29](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/chatgpt-api.ts#L29) [chatgpt-api.ts:31](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/chatgpt-api.ts#L31)
## Methods ## Methods
...@@ -50,7 +50,7 @@ Creates a new client wrapper around the unofficial ChatGPT REST API. ...@@ -50,7 +50,7 @@ Creates a new client wrapper around the unofficial ChatGPT REST API.
#### Defined in #### Defined in
[chatgpt-api.ts:72](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/chatgpt-api.ts#L72) [chatgpt-api.ts:74](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/chatgpt-api.ts#L74)
___ ___
...@@ -64,7 +64,7 @@ ___ ...@@ -64,7 +64,7 @@ ___
#### Defined in #### Defined in
[chatgpt-api.ts:63](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/chatgpt-api.ts#L63) [chatgpt-api.ts:65](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/chatgpt-api.ts#L65)
___ ___
...@@ -78,7 +78,7 @@ ___ ...@@ -78,7 +78,7 @@ ___
#### Defined in #### Defined in
[chatgpt-api.ts:163](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/chatgpt-api.ts#L163) [chatgpt-api.ts:165](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/chatgpt-api.ts#L165)
___ ___
...@@ -104,4 +104,4 @@ the response. ...@@ -104,4 +104,4 @@ the response.
#### Defined in #### Defined in
[chatgpt-api.ts:84](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/chatgpt-api.ts#L84) [chatgpt-api.ts:86](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/chatgpt-api.ts#L86)
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#### Defined in #### Defined in
[types.ts:104](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L104) [types.ts:104](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L104)
___ ___
...@@ -53,7 +53,7 @@ ___ ...@@ -53,7 +53,7 @@ ___
#### Defined in #### Defined in
[types.ts:1](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L1) [types.ts:1](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L1)
___ ___
...@@ -75,7 +75,7 @@ https://chat.openapi.com/backend-api/conversation ...@@ -75,7 +75,7 @@ https://chat.openapi.com/backend-api/conversation
#### Defined in #### Defined in
[types.ts:129](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L129) [types.ts:129](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L129)
___ ___
...@@ -93,7 +93,7 @@ ___ ...@@ -93,7 +93,7 @@ ___
#### Defined in #### Defined in
[types.ts:246](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L246) [types.ts:246](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L246)
___ ___
...@@ -118,7 +118,7 @@ ___ ...@@ -118,7 +118,7 @@ ___
#### Defined in #### Defined in
[types.ts:252](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L252) [types.ts:252](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L252)
___ ___
...@@ -135,7 +135,7 @@ ___ ...@@ -135,7 +135,7 @@ ___
#### Defined in #### Defined in
[types.ts:265](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L265) [types.ts:265](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L265)
___ ___
...@@ -157,7 +157,7 @@ https://chat.openapi.com/backend-api/conversation/message_feedback ...@@ -157,7 +157,7 @@ https://chat.openapi.com/backend-api/conversation/message_feedback
#### Defined in #### Defined in
[types.ts:188](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L188) [types.ts:188](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L188)
___ ___
...@@ -167,7 +167,7 @@ ___ ...@@ -167,7 +167,7 @@ ___
#### Defined in #### Defined in
[types.ts:244](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L244) [types.ts:244](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L244)
___ ___
...@@ -187,7 +187,7 @@ ___ ...@@ -187,7 +187,7 @@ ___
#### Defined in #### Defined in
[types.ts:217](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L217) [types.ts:217](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L217)
___ ___
...@@ -197,7 +197,7 @@ ___ ...@@ -197,7 +197,7 @@ ___
#### Defined in #### Defined in
[types.ts:215](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L215) [types.ts:215](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L215)
___ ___
...@@ -207,7 +207,7 @@ ___ ...@@ -207,7 +207,7 @@ ___
#### Defined in #### Defined in
[types.ts:270](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L270) [types.ts:270](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L270)
___ ___
...@@ -225,7 +225,7 @@ ___ ...@@ -225,7 +225,7 @@ ___
#### Defined in #### Defined in
[types.ts:72](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L72) [types.ts:72](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L72)
___ ___
...@@ -243,7 +243,7 @@ https://chat.openapi.com/backend-api/models ...@@ -243,7 +243,7 @@ https://chat.openapi.com/backend-api/models
#### Defined in #### Defined in
[types.ts:65](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L65) [types.ts:65](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L65)
___ ___
...@@ -262,7 +262,7 @@ https://chat.openapi.com/backend-api/moderations ...@@ -262,7 +262,7 @@ https://chat.openapi.com/backend-api/moderations
#### Defined in #### Defined in
[types.ts:92](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L92) [types.ts:92](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L92)
___ ___
...@@ -282,7 +282,7 @@ https://chat.openapi.com/backend-api/moderations ...@@ -282,7 +282,7 @@ https://chat.openapi.com/backend-api/moderations
#### Defined in #### Defined in
[types.ts:109](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L109) [types.ts:109](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L109)
___ ___
...@@ -300,7 +300,7 @@ ___ ...@@ -300,7 +300,7 @@ ___
#### Defined in #### Defined in
[types.ts:156](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L156) [types.ts:156](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L156)
___ ___
...@@ -317,7 +317,7 @@ ___ ...@@ -317,7 +317,7 @@ ___
#### Defined in #### Defined in
[types.ts:173](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L173) [types.ts:173](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L173)
___ ___
...@@ -327,7 +327,7 @@ ___ ...@@ -327,7 +327,7 @@ ___
#### Defined in #### Defined in
[types.ts:3](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L3) [types.ts:3](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L3)
___ ___
...@@ -347,7 +347,7 @@ https://chat.openapi.com/api/auth/session ...@@ -347,7 +347,7 @@ https://chat.openapi.com/api/auth/session
#### Defined in #### Defined in
[types.ts:8](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L8) [types.ts:8](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L8)
___ ___
...@@ -369,7 +369,7 @@ ___ ...@@ -369,7 +369,7 @@ ___
#### Defined in #### Defined in
[types.ts:25](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/types.ts#L25) [types.ts:25](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L25)
## Functions ## Functions
...@@ -389,4 +389,4 @@ ___ ...@@ -389,4 +389,4 @@ ___
#### Defined in #### Defined in
[utils.ts:4](https://github.com/transitive-bullshit/chatgpt-api/blob/549e9b4/src/utils.ts#L4) [utils.ts:4](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/utils.ts#L4)
chatgpt / [Exports](modules.md) chatgpt / [Exports](modules.md)
<p align="center">
<img alt="Example usage" src="/media/demo.gif">
</p>
# ChatGPT API <!-- omit in toc --> # ChatGPT API <!-- omit in toc -->
> Node.js client for the unofficial [ChatGPT](https://openai.com/blog/chatgpt/) API. > Node.js client for the unofficial [ChatGPT](https://openai.com/blog/chatgpt/) API.
...@@ -23,21 +27,23 @@ You can use it to start building projects powered by ChatGPT like chatbots, webs ...@@ -23,21 +27,23 @@ You can use it to start building projects powered by ChatGPT like chatbots, webs
## How it works ## How it works
This package requires a valid session token from OpenAI's ChatGPT webapp to access it's unofficial REST API. This package requires a valid session token from ChatGPT to access it's unofficial REST API.
To get a session token:
1. Go to https://chat.openai.com/chat and log in or sign up 1. Go to https://chat.openai.com/chat and log in or sign up.
2. Open the dev tools console 2. Open dev tools.
3. Open `Application` > `Cookies` 3. Open `Application` > `Cookies`.
![ChatGPT cookies](./media/cookies.png) ![ChatGPT cookies](./media/session-token.png)
4. Copy the value for `__Secure-next-auth.session-token` and save it to your environment. 4. Copy the value for `__Secure-next-auth.session-token` and save it to your environment.
If you want to run the built-in demo, If you want to run the built-in demo, store this value as `SESSION_TOKEN` in a local `.env` file.
> **Note** > **Note**
> This package will switch to using the official API once it's released. > This package will switch to using the official API once it's released.
> **Note** > **Note**
> Prior to v1.0.0, this package used headless Chromium 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). > 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).
## Install ## Install
...@@ -55,7 +61,7 @@ pnpm add chatgpt ...@@ -55,7 +61,7 @@ pnpm add chatgpt
import { ChatGPTAPI } from 'chatgpt' import { ChatGPTAPI } from 'chatgpt'
async function example() { async function example() {
const api = new ChatGPTAPI() const api = new ChatGPTAPI({ sessionToken: process.env.SESSION_TOKEN })
// ensure the API is properly authenticated (optional) // ensure the API is properly authenticated (optional)
await api.ensureAuth() await api.ensureAuth()
...@@ -70,6 +76,15 @@ async function example() { ...@@ -70,6 +76,15 @@ async function example() {
} }
``` ```
By default, the response will be formatted as markdown. If you want to work with plaintext only, you can use:
```ts
const api = new ChatGPTAPI({
sessionToken: process.env.SESSION_TOKEN,
markdown: false
})
```
A full [example](./src/example.ts) is included for testing purposes: A full [example](./src/example.ts) is included for testing purposes:
```bash ```bash
...@@ -93,13 +108,15 @@ All of these awesome projects use the `chatgpt` package. 🤯 ...@@ -93,13 +108,15 @@ All of these awesome projects use the `chatgpt` package. 🤯
- [Chrome Extension](https://github.com/gragland/chatgpt-everywhere) ([demo](https://twitter.com/gabe_ragland/status/1599466486422470656)) - [Chrome Extension](https://github.com/gragland/chatgpt-everywhere) ([demo](https://twitter.com/gabe_ragland/status/1599466486422470656))
- [VSCode Extension](https://github.com/mpociot/chatgpt-vscode) ([demo](https://twitter.com/marcelpociot/status/1599180144551526400)) - [VSCode Extension](https://github.com/mpociot/chatgpt-vscode) ([demo](https://twitter.com/marcelpociot/status/1599180144551526400))
- [Go Telegram Bot](https://github.com/m1guelpf/chatgpt-telegram) - [Go Telegram Bot](https://github.com/m1guelpf/chatgpt-telegram)
- [Github ProBot](https://github.com/oceanlvr/ChatGPTBot)
- [Lovelines.xyz](https://lovelines.xyz) - [Lovelines.xyz](https://lovelines.xyz)
If you create a cool integration, feel free to open a PR and add it to the list. If you create a cool integration, feel free to open a PR and add it to the list.
## Credit ## Credit
- Inspired by this [Go module](https://github.com/danielgross/whatsapp-gpt) by [Daniel Gross](https://github.com/danielgross) - Huge thanks to [@RomanHotsiy](https://github.com/RomanHotsiy), [@ElijahPepe](https://github.com/ElijahPepe), [@wong2](https://github.com/wong2), 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)
## License ## License
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment