@@ -51,9 +58,13 @@ to obtain your `clearanceToken`.
| `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/108.0.0.0 Safari/537.36'`* |
Note that this solution is not lightweight, but it does work a lot more consistently than the REST API-based versions. I'm currently using this solution to power 10 OpenAI accounts concurrently across 10 minimized Chrome windows for my [Twitter bot](https://github.com/transitive-bullshit/chatgpt-twitter-bot). 😂
...
...
@@ -88,15 +89,13 @@ async function example() {
})
constapi=newChatGPTAPI({...openAIAuth})
awaitapi.ensureAuth()
awaitapi.initSession()
// send a message and wait for the response
constresponse=awaitapi.sendMessage(
'Write a python version of bubble sort.'
)
constresult=awaitapi.sendMessage('Write a python version of bubble sort.')
If you want to automatically track the conversation, you can use `ChatGPTAPI.getConversation()`:
If you want to track the conversation, use the `conversationId` and `messageId` in the result object, and pass them to `sendMessage` as `conversationId` and `parentMessageId` respectively.
res=awaitconversation.sendMessage('What were we talking about?',{
conversationId:res.conversationId,
parentMessageId:res.messageId
})
console.log(res.response)
```
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.
...
...
@@ -153,8 +161,6 @@ 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>