chore: update docs

pull/25/head
Travis Fischer 2022-12-05 22:53:20 -06:00
rodzic cf5e775713
commit 56c71299ca
3 zmienionych plików z 60 dodań i 60 usunięć

Wyświetl plik

@ -36,7 +36,7 @@ Creates a new client wrapper around the unofficial ChatGPT REST API.
#### Defined in #### Defined in
[chatgpt-api.ts:31](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/chatgpt-api.ts#L31) [chatgpt-api.ts:31](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/chatgpt-api.ts#L31)
## Methods ## Methods
@ -50,7 +50,7 @@ Creates a new client wrapper around the unofficial ChatGPT REST API.
#### Defined in #### Defined in
[chatgpt-api.ts:74](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/chatgpt-api.ts#L74) [chatgpt-api.ts:74](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/chatgpt-api.ts#L74)
___ ___
@ -64,7 +64,7 @@ ___
#### Defined in #### Defined in
[chatgpt-api.ts:65](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/chatgpt-api.ts#L65) [chatgpt-api.ts:65](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/chatgpt-api.ts#L65)
___ ___
@ -78,7 +78,7 @@ ___
#### Defined in #### Defined in
[chatgpt-api.ts:165](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/chatgpt-api.ts#L165) [chatgpt-api.ts:165](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/chatgpt-api.ts#L165)
___ ___
@ -95,7 +95,7 @@ the response.
| :------ | :------ | :------ | | :------ | :------ | :------ |
| `message` | `string` | The plaintext message to send. | | `message` | `string` | The plaintext message to send. |
| `opts` | `Object` | - | | `opts` | `Object` | - |
| `opts.conversationId?` | `string` | - | | `opts.conversationId?` | `string` | Optional ID of the previous message in a conversation |
| `opts.onProgress?` | (`partialResponse`: `string`) => `void` | - | | `opts.onProgress?` | (`partialResponse`: `string`) => `void` | - |
#### Returns #### Returns
@ -104,4 +104,4 @@ the response.
#### Defined in #### Defined in
[chatgpt-api.ts:86](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/chatgpt-api.ts#L86) [chatgpt-api.ts:86](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/chatgpt-api.ts#L86)

Wyświetl plik

@ -43,7 +43,7 @@
#### Defined in #### Defined in
[types.ts:104](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L104) [types.ts:109](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L109)
___ ___
@ -53,7 +53,7 @@ ___
#### Defined in #### Defined in
[types.ts:1](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L1) [types.ts:1](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L1)
___ ___
@ -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/c9cef79/src/types.ts#L129) [types.ts:134](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L134)
___ ___
@ -93,7 +93,7 @@ ___
#### Defined in #### Defined in
[types.ts:246](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L246) [types.ts:251](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L251)
___ ___
@ -118,7 +118,7 @@ ___
#### Defined in #### Defined in
[types.ts:252](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L252) [types.ts:257](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L257)
___ ___
@ -135,7 +135,7 @@ ___
#### Defined in #### Defined in
[types.ts:265](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L265) [types.ts:270](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L270)
___ ___
@ -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/c9cef79/src/types.ts#L188) [types.ts:193](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L193)
___ ___
@ -167,7 +167,7 @@ ___
#### Defined in #### Defined in
[types.ts:244](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L244) [types.ts:249](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L249)
___ ___
@ -187,7 +187,7 @@ ___
#### Defined in #### Defined in
[types.ts:217](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L217) [types.ts:222](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L222)
___ ___
@ -197,7 +197,7 @@ ___
#### Defined in #### Defined in
[types.ts:215](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L215) [types.ts:220](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L220)
___ ___
@ -207,7 +207,7 @@ ___
#### Defined in #### Defined in
[types.ts:270](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L270) [types.ts:275](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L275)
___ ___
@ -225,7 +225,7 @@ ___
#### Defined in #### Defined in
[types.ts:72](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L72) [types.ts:77](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L77)
___ ___
@ -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/c9cef79/src/types.ts#L65) [types.ts:70](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L70)
___ ___
@ -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/c9cef79/src/types.ts#L92) [types.ts:97](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L97)
___ ___
@ -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/c9cef79/src/types.ts#L109) [types.ts:114](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L114)
___ ___
@ -300,7 +300,7 @@ ___
#### Defined in #### Defined in
[types.ts:156](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L156) [types.ts:161](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L161)
___ ___
@ -317,7 +317,7 @@ ___
#### Defined in #### Defined in
[types.ts:173](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L173) [types.ts:178](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L178)
___ ___
@ -327,7 +327,7 @@ ___
#### Defined in #### Defined in
[types.ts:3](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L3) [types.ts:3](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L3)
___ ___
@ -342,12 +342,13 @@ https://chat.openapi.com/api/auth/session
| Name | Type | Description | | Name | Type | Description |
| :------ | :------ | :------ | | :------ | :------ | :------ |
| `accessToken` | `string` | The access token | | `accessToken` | `string` | The access token |
| `error?` | `string` \| ``null`` | If there was an error associated with this request |
| `expires` | `string` | ISO date of the expiration date of the access token | | `expires` | `string` | ISO date of the expiration date of the access token |
| `user` | [`User`](modules.md#user) | Object of the current user | | `user` | [`User`](modules.md#user) | Authenticated user |
#### Defined in #### Defined in
[types.ts:8](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L8) [types.ts:8](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L8)
___ ___
@ -369,7 +370,7 @@ ___
#### Defined in #### Defined in
[types.ts:25](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/types.ts#L25) [types.ts:30](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/types.ts#L30)
## Functions ## Functions
@ -389,4 +390,4 @@ ___
#### Defined in #### Defined in
[utils.ts:4](https://github.com/transitive-bullshit/chatgpt-api/blob/c9cef79/src/utils.ts#L4) [utils.ts:4](https://github.com/transitive-bullshit/chatgpt-api/blob/cf5e775/src/utils.ts#L4)

Wyświetl plik

@ -11,10 +11,10 @@ chatgpt / [Exports](modules.md)
[![NPM](https://img.shields.io/npm/v/chatgpt.svg)](https://www.npmjs.com/package/chatgpt) [![Build Status](https://github.com/transitive-bullshit/chatgpt-api/actions/workflows/test.yml/badge.svg)](https://github.com/transitive-bullshit/chatgpt-api/actions/workflows/test.yml) [![MIT License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/transitive-bullshit/chatgpt-api/blob/main/license) [![Prettier Code Formatting](https://img.shields.io/badge/code_style-prettier-brightgreen.svg)](https://prettier.io) [![NPM](https://img.shields.io/npm/v/chatgpt.svg)](https://www.npmjs.com/package/chatgpt) [![Build Status](https://github.com/transitive-bullshit/chatgpt-api/actions/workflows/test.yml/badge.svg)](https://github.com/transitive-bullshit/chatgpt-api/actions/workflows/test.yml) [![MIT License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/transitive-bullshit/chatgpt-api/blob/main/license) [![Prettier Code Formatting](https://img.shields.io/badge/code_style-prettier-brightgreen.svg)](https://prettier.io)
- [Intro](#intro) - [Intro](#intro)
- [How it works](#how-it-works)
- [Install](#install) - [Install](#install)
- [Usage](#usage) - [Usage](#usage)
- [Docs](#docs) - [Docs](#docs)
- [How it works](#how-it-works)
- [Examples](#examples) - [Examples](#examples)
- [Credit](#credit) - [Credit](#credit)
- [License](#license) - [License](#license)
@ -25,34 +25,10 @@ This package is a Node.js wrapper around [ChatGPT](https://openai.com/blog/chatg
You can use it to start building projects powered by ChatGPT like chatbots, websites, etc... You can use it to start building projects powered by ChatGPT like chatbots, websites, etc...
## How it works
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.
2. Open dev tools.
3. Open `Application` > `Cookies`.
![ChatGPT cookies](./media/session-token.png)
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, store this value as `SESSION_TOKEN` in a local `.env` file.
> **Note**
> This package will switch to using the official API once it's released.
> **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).
## Install ## Install
```bash ```bash
npm install --save chatgpt npm install chatgpt
# or
yarn add chatgpt
# or
pnpm add chatgpt
``` ```
## Usage ## Usage
@ -61,9 +37,10 @@ pnpm add chatgpt
import { ChatGPTAPI } from 'chatgpt' import { ChatGPTAPI } from 'chatgpt'
async function example() { 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 (optional) // ensure the API is properly authenticated
await api.ensureAuth() await api.ensureAuth()
// send a message and wait for the response // send a message and wait for the response
@ -85,31 +62,53 @@ const api = new ChatGPTAPI({
}) })
``` ```
A full [example](./src/example.ts) is included for testing purposes: A full [demo](./src/demo.ts) is included for testing purposes:
```bash ```bash
# 1. clone repo # 1. clone repo
# 2. install node deps # 2. install node deps
# 3. set `SESSION_TOKEN` in .env # 3. set `SESSION_TOKEN` in .env
# 4. run: # 4. run:
npx tsx src/example.ts npx tsx src/demo.ts
``` ```
## Docs ## Docs
See the [auto-generated docs](./docs/classes/ChatGPTAPI.md) for more info on methods and parameters. See the [auto-generated docs](./docs/classes/ChatGPTAPI.md) for more info on methods and parameters.
## How it works
**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.
2. Open dev tools.
3. Open `Application` > `Cookies`.
![ChatGPT cookies](./media/session-token.png)
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, store this value as `SESSION_TOKEN` in a local `.env` file.
> **Note**
> This package will switch to using the official API once it's released.
> **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).
## Examples ## Examples
All of these awesome projects use the `chatgpt` package. 🤯 All of these awesome projects are built using the `chatgpt` package. 🤯
- [Twitter Bot](https://github.com/transitive-bullshit/chatgpt-twitter-bot) powered by ChatGPT ✨ - [Twitter Bot](https://github.com/transitive-bullshit/chatgpt-twitter-bot) powered by ChatGPT ✨
- Mention [@ChatGPTBot](https://twitter.com/ChatGPTBot) on Twitter with your prompt to try it out - 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)) - [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) - [GitHub ProBot](https://github.com/oceanlvr/ChatGPTBot)
- [Discord Bot](https://github.com/onury5506/Discord-ChatGPT-Bot)
- [Lovelines.xyz](https://lovelines.xyz) - [Lovelines.xyz](https://lovelines.xyz)
- [EXM smart contracts](https://github.com/decentldotland/molecule)
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.
@ -122,4 +121,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) MIT © [Travis Fischer](https://transitivebullsh.it)
Support my open source work by <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 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>