| `opts.sessionToken` | `string` | = **Required** OpenAI session token which can be found in a valid session's cookies (see readme for instructions) |
| `opts.userAgent?` | `string` | **`Default Value`**`'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'`* |
> As of December 11, 2022 ~2pm CST, OpenAI has enabled additional Cloudflare restrictions that are currently preventing us from refreshing access tokens. This is affecting _all_ ChatGPT API wrappers at the moment, including the Python ones. See [this issue](https://github.com/transitive-bullshit/chatgpt-api/issues/96) for an ongoing discussion until I release a viable workaround.
<palign="center">
<imgalt="Example usage"src="/media/demo.gif">
</p>
...
...
@@ -49,7 +52,7 @@ async function example() {
// send a message and wait for the response
constresponse=awaitapi.sendMessage(
'Write a python version of bubble sort. Do not include example usage.'
'Write a python version of bubble sort.'
)
// response is a markdown-formatted string
...
...
@@ -57,7 +60,7 @@ async function example() {
}
```
The default ChatGPT responses are formatted as markdown. If you want to work with plaintext only, you can use:
ChatGPT responses are formatted as markdown by default. If you want to work with plaintext instead, you can use:
```ts
constapi=newChatGPTAPI({
...
...
@@ -85,9 +88,9 @@ const response1 = await conversation.sendMessage('Can you expand on that?')
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.
Sometimes, ChatGPT will hang for an extended period of time before beginning to respond. 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:
To mitigate these issues, you can add a timeout like this:
```ts
// timeout after 2 minutes (which will also abort the underlying HTTP request)
...
...
@@ -96,6 +99,8 @@ const response = await api.sendMessage('this is a timeout test', {
})
```
You can stream responses using the `onProgress` or `onConversationResponse` callbacks. See the [docs](./docs/classes/ChatGPTAPI.md) for more details.
<details>
<summary>Usage in CommonJS (Dynamic import)</summary>
...
...
@@ -169,17 +174,40 @@ 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
If you create a cool integration, feel free to open a PR and add it to the list.
...
...
@@ -191,15 +219,16 @@ This package is ESM-only. It supports:
- 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
- Mainly meant for chrome extensions where your code is protected to a degree
-We recommend against 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 💪
- Huge thanks to [@simon300000](https://github.com/simon300000), [@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)
- The original REST version was inspired by [chat-gpt-google-extension](https://github.com/wong2/chat-gpt-google-extension) by [@wong2](https://github.com/wong2)
-[OpenAI](https://openai.com) for creating [ChatGPT](https://openai.com/blog/chatgpt/) 🔥