Commit 71c95073 authored by Travis Fischer's avatar Travis Fischer

chore: update ts docs

parent 4a0f780d
......@@ -49,7 +49,7 @@ An error if it fails.
#### Defined in
[src/abstract-chatgpt-api.ts:69](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/abstract-chatgpt-api.ts#L69)
[src/abstract-chatgpt-api.ts:69](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/abstract-chatgpt-api.ts#L69)
___
......@@ -66,7 +66,7 @@ otherwise.
#### Defined in
[src/abstract-chatgpt-api.ts:39](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/abstract-chatgpt-api.ts#L39)
[src/abstract-chatgpt-api.ts:39](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/abstract-chatgpt-api.ts#L39)
___
......@@ -87,7 +87,7 @@ An error if the session failed to initialize properly.
#### Defined in
[src/abstract-chatgpt-api.ts:10](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/abstract-chatgpt-api.ts#L10)
[src/abstract-chatgpt-api.ts:10](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/abstract-chatgpt-api.ts#L10)
___
......@@ -111,7 +111,7 @@ Access credentials for the new session.
#### Defined in
[src/abstract-chatgpt-api.ts:49](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/abstract-chatgpt-api.ts#L49)
[src/abstract-chatgpt-api.ts:49](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/abstract-chatgpt-api.ts#L49)
___
......@@ -135,7 +135,7 @@ Access credentials for the new session.
#### Defined in
[src/abstract-chatgpt-api.ts:59](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/abstract-chatgpt-api.ts#L59)
[src/abstract-chatgpt-api.ts:59](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/abstract-chatgpt-api.ts#L59)
___
......@@ -164,4 +164,4 @@ the `response` text.
#### Defined in
[src/abstract-chatgpt-api.ts:30](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/abstract-chatgpt-api.ts#L30)
[src/abstract-chatgpt-api.ts:30](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/abstract-chatgpt-api.ts#L30)
......@@ -64,7 +64,7 @@ to obtain your `clearanceToken`.
#### Defined in
[src/chatgpt-api.ts:45](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L45)
[src/chatgpt-api.ts:45](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L45)
## Accessors
......@@ -80,7 +80,7 @@ Gets the current Cloudflare clearance token (`cf_clearance` cookie value).
#### Defined in
[src/chatgpt-api.ts:143](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L143)
[src/chatgpt-api.ts:143](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L143)
___
......@@ -96,7 +96,7 @@ Gets the current session token.
#### Defined in
[src/chatgpt-api.ts:138](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L138)
[src/chatgpt-api.ts:138](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L138)
___
......@@ -112,7 +112,7 @@ Gets the currently signed-in user, if authenticated, `null` otherwise.
#### Defined in
[src/chatgpt-api.ts:133](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L133)
[src/chatgpt-api.ts:133](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L133)
___
......@@ -128,7 +128,7 @@ Gets the current user agent.
#### Defined in
[src/chatgpt-api.ts:148](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L148)
[src/chatgpt-api.ts:148](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L148)
## Methods
......@@ -152,7 +152,7 @@ An error if it fails.
#### Defined in
[src/chatgpt-api.ts:470](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L470)
[src/chatgpt-api.ts:470](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L470)
___
......@@ -173,7 +173,7 @@ the token fails.
#### Defined in
[src/chatgpt-api.ts:367](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L367)
[src/chatgpt-api.ts:367](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L367)
___
......@@ -194,7 +194,7 @@ is valid.
#### Defined in
[src/chatgpt-api.ts:156](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L156)
[src/chatgpt-api.ts:156](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L156)
___
......@@ -224,7 +224,7 @@ A valid access token
#### Defined in
[src/chatgpt-api.ts:386](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L386)
[src/chatgpt-api.ts:386](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L386)
___
......@@ -252,7 +252,7 @@ Access credentials for the new session.
#### Defined in
[src/abstract-chatgpt-api.ts:59](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/abstract-chatgpt-api.ts#L59)
[src/abstract-chatgpt-api.ts:59](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/abstract-chatgpt-api.ts#L59)
___
......@@ -287,7 +287,7 @@ The response from ChatGPT
#### Defined in
[src/chatgpt-api.ts:180](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L180)
[src/chatgpt-api.ts:180](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L180)
___
......@@ -307,4 +307,4 @@ ___
#### Defined in
[src/chatgpt-api.ts:324](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api.ts#L324)
[src/chatgpt-api.ts:324](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api.ts#L324)
......@@ -61,7 +61,7 @@ Creates a new client for automating the ChatGPT webapp.
#### Defined in
[src/chatgpt-api-browser.ts:40](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L40)
[src/chatgpt-api-browser.ts:44](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L44)
## Accessors
......@@ -75,7 +75,7 @@ Creates a new client for automating the ChatGPT webapp.
#### Defined in
[src/chatgpt-api-browser.ts:696](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L696)
[src/chatgpt-api-browser.ts:741](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L741)
## Methods
......@@ -95,7 +95,7 @@ Creates a new client for automating the ChatGPT webapp.
#### Defined in
[src/chatgpt-api-browser.ts:218](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L218)
[src/chatgpt-api-browser.ts:249](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L249)
___
......@@ -115,7 +115,7 @@ ___
#### Defined in
[src/chatgpt-api-browser.ts:255](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L255)
[src/chatgpt-api-browser.ts:286](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L286)
___
......@@ -139,7 +139,7 @@ An error if it fails.
#### Defined in
[src/chatgpt-api-browser.ts:642](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L642)
[src/chatgpt-api-browser.ts:687](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L687)
___
......@@ -160,7 +160,7 @@ otherwise.
#### Defined in
[src/chatgpt-api-browser.ts:391](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L391)
[src/chatgpt-api-browser.ts:422](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L422)
___
......@@ -185,7 +185,7 @@ An error if the session failed to initialize properly.
#### Defined in
[src/chatgpt-api-browser.ts:114](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L114)
[src/chatgpt-api-browser.ts:119](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L119)
___
......@@ -205,7 +205,7 @@ Attempts to handle 403 errors by refreshing the page.
#### Defined in
[src/chatgpt-api-browser.ts:333](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L333)
[src/chatgpt-api-browser.ts:364](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L364)
___
......@@ -225,7 +225,7 @@ Attempts to handle 401 errors by re-authenticating.
#### Defined in
[src/chatgpt-api-browser.ts:314](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L314)
[src/chatgpt-api-browser.ts:345](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L345)
___
......@@ -239,7 +239,7 @@ ___
#### Defined in
[src/chatgpt-api-browser.ts:634](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L634)
[src/chatgpt-api-browser.ts:679](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L679)
___
......@@ -272,4 +272,4 @@ the `response` text.
#### Defined in
[src/chatgpt-api-browser.ts:468](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/chatgpt-api-browser.ts#L468)
[src/chatgpt-api-browser.ts:499](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/chatgpt-api-browser.ts#L499)
......@@ -66,7 +66,7 @@ node_modules/.pnpm/typescript@4.9.3/node_modules/typescript/lib/lib.es2022.error
#### Defined in
[src/types.ts:297](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/types.ts#L297)
[src/types.ts:297](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/types.ts#L297)
___
......@@ -76,7 +76,7 @@ ___
#### Defined in
[src/types.ts:296](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/types.ts#L296)
[src/types.ts:296](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/types.ts#L296)
___
......@@ -86,7 +86,7 @@ ___
#### Defined in
[src/types.ts:294](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/types.ts#L294)
[src/types.ts:294](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/types.ts#L294)
___
......@@ -96,4 +96,4 @@ ___
#### Defined in
[src/types.ts:295](https://github.com/transitive-bullshit/chatgpt-api/blob/025e7e3/src/types.ts#L295)
[src/types.ts:295](https://github.com/transitive-bullshit/chatgpt-api/blob/4a0f780/src/types.ts#L295)
This diff is collapsed.
chatgpt / [Exports](modules.md)
# Update December 18, 2022 <!-- omit in toc -->
# Update January 12, 2023 <!-- omit in toc -->
On December 11th, OpenAI added Cloudflare protections that make it more difficult to access the unofficial API.
To circumvent these protections, we've added a **fully automated browser-based solution**, which uses Puppeteer and CAPTCHA solvers under the hood. 🔥
This package works to access ChatGPT pretty consistently, even after OpenAI added Cloudflare protections. To circumvent these protections, we've added a **fully automated browser-based solution**, which uses Puppeteer and CAPTCHA solvers under the hood. 🔥
```ts
import { ChatGPTAPIBrowser } from 'chatgpt'
......@@ -19,12 +17,18 @@ const result = await api.sendMessage('Hello World!')
console.log(result.response)
```
This solution is not lightweight, but it does work a lot more consistently than the previous REST API-based approach. For example, I'm currently using this approach to automate 10 concurrent OpenAI accounts for my [Twitter bot](https://github.com/transitive-bullshit/chatgpt-twitter-bot). 😂
To use the updated version, **make sure you're using the latest version of this package and Node.js >= 18**. Then update your code following the examples below, paying special attention to the sections on [Authentication](#authentication), [Restrictions](#restrictions), and [CAPTCHAs](#captchas).
This solution is not lightweight, but it does work a lot more consistently than the previous REST API-based approach. For example, I'm currently using this approach to automate N concurrent OpenAI accounts for my [Twitter bot](https://github.com/transitive-bullshit/chatgpt-twitter-bot). 😂
We recently added support for CAPTCHA automation using either [nopecha](https://nopecha.com/) or [2captcha](https://2captcha.com). Keep in mind that this package will be updated to use the official API as soon as it's released, so things should get much easier over time. 💪
There are some restrictions to be aware of, however:
- Cloudflare doesn't like requests coming from data center IPs, so you'll either have to run it locally or use a residential IP proxy.
- You should only have one `sendMessage` request at a time per browser instance and OpenAI account.
- It can be difficult to reliably process `sendMessage` requests after awhile. My best advice for handling this is to wrap your usage in some basic retry logic as well as a daemon which restarts your Node.js process every hour or so. This is unfortunately a byproduct of there not being an official API, so keep that in mind before using this in production.
If you run into any issues, we do have a pretty active [Discord](https://discord.gg/v9gERj825w) with a bunch of ChatGPT hackers from the Node.js & Python communities.
Lastly, please consider starring this repo and <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> to help support the project.
Thanks && cheers,
......@@ -90,7 +94,7 @@ async function example() {
```
<details>
<summary>Or, if you want to use the REST-based version:</summary>
<summary>Or, if you want to use the REST-based version: (not advised at this time)</summary>
```ts
import { ChatGPTAPI, getOpenAIAuth } from 'chatgpt'
......@@ -199,7 +203,21 @@ A [basic demo](./demos/demo.ts) is included for testing purposes:
npx tsx demos/demo.ts
```
A [conversation demo](./demos/demo-conversation.ts) is also included:
A [google auth demo](./demos/demo-google-auth.ts):
```bash
npx tsx demos/demo-google-auth.ts
```
A [demo showing on progress handler](./demos/demo-on-progress.ts):
```bash
npx tsx demos/demo-on-progress.ts
```
The on progress demo uses the optional `onProgress` parameter to `sendMessage` to receive intermediary results as ChatGPT is "typing".
A [conversation demo](./demos/demo-conversation.ts):
```bash
npx tsx demos/demo-conversation.ts
......@@ -299,6 +317,7 @@ All of these awesome projects are built using the `chatgpt` package. 🤯
- [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
- [ChatGPT API Server](https://github.com/waylaidwanderer/node-chatgpt-api) - API server for this package with support for multiple OpenAI accounts, proxies, and load-balancing requests between accounts.
- [Lovelines.xyz](https://lovelines.xyz?ref=chatgpt-api)
- [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), [updated version](https://github.com/timkmecl/chatgpt-vscode), [marketplace](https://marketplace.visualstudio.com/items?itemName=timkmecl.chatgpt))
......@@ -336,7 +355,8 @@ All of these awesome projects are built using the `chatgpt` package. 🤯
- [WhatsApp Bot #1](https://github.com/pascalroget/whatsgpt) (multi-user support)
- [WhatsApp Bot #2](https://github.com/amosayomide05/chatgpt-whatsapp-bot)
- [WhatsApp Bot #3](https://github.com/navopw/whatsapp-chatgpt)
- [Matrix Bot](https://github.com/jakecoppinger/matrix-chatgpt-bot)
- [WhatsApp Bot #4](https://github.com/noelzappy/chatgpt-whatsapp) (schedule periodic messages)
- [Matrix Bot](https://github.com/matrixgpt/matrix-chatgpt-bot)
- [Rental Cover Letter Generator](https://sharehouse.app/ai)
- [Assistant CLI](https://github.com/diciaup/assistant-cli)
- [Teams Bot](https://github.com/formulahendry/chatgpt-teams-bot)
......@@ -351,6 +371,8 @@ All of these awesome projects are built using the `chatgpt` package. 🤯
- [Continuous Conversation](https://github.com/DanielTerletzkiy/chat-gtp-assistant)
- [Figma plugin](https://github.com/frederickk/chatgpt-figma-plugin)
- [NestJS server](https://github.com/RusDyn/chatgpt_nestjs_server)
- [NestJS ChatGPT Starter Boilerplate](https://github.com/mitkodkn/nestjs-chatgpt-starter)
- [Wordsmith: Add-in for Microsoft Word](https://github.com/xtremehpx/Wordsmith)
If you create a cool integration, feel free to open a PR and add it to the list.
......
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