Commit f5c277f1 authored by Travis Fischer's avatar Travis Fischer Committed by GitHub

Merge pull request #148 from transitive-bullshit/feature/browser-improvements

parents 9aeb17e7 83855626
import delay from 'delay'
import dotenv from 'dotenv-safe' import dotenv from 'dotenv-safe'
import { oraPromise } from 'ora' import { oraPromise } from 'ora'
...@@ -16,7 +17,12 @@ async function main() { ...@@ -16,7 +17,12 @@ async function main() {
const email = process.env.OPENAI_EMAIL const email = process.env.OPENAI_EMAIL
const password = process.env.OPENAI_PASSWORD const password = process.env.OPENAI_PASSWORD
const api = new ChatGPTAPIBrowser({ email, password, debug: true }) const api = new ChatGPTAPIBrowser({
email,
password,
debug: false,
minimize: true
})
await api.init() await api.init()
const prompt = const prompt =
......
...@@ -24,7 +24,7 @@ const response = await api.sendMessage('Hello World!') ...@@ -24,7 +24,7 @@ const response = await api.sendMessage('Hello World!')
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). 😂 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). 😂
If you get a "ChatGPT is at capacity" error when logging in, note that this is also happening quite frequently on the official webapp. Their servers are overloaded, and we're all trying our best to offer access to this amazing technology. If you get a "ChatGPT is at capacity" error when logging in, note that this can also happen on the official webapp as well. Their servers get overloaded at times, and we're all trying our best to offer access to this amazing technology.
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) and [Restrictions](#restrictions). 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) and [Restrictions](#restrictions).
...@@ -240,8 +240,6 @@ Pass `sessionToken`, `clearanceToken`, and `userAgent` to the `ChatGPTAPI` const ...@@ -240,8 +240,6 @@ Pass `sessionToken`, `clearanceToken`, and `userAgent` to the `ChatGPTAPI` const
These restrictions are for the `getOpenAIAuth` + `ChatGPTAPI` solution, which uses the unofficial API. The browser-based solution, `ChatGPTAPIBrowser`, doesn't have many of these restrictions, though you'll still have to manually bypass CAPTCHAs by hand. These restrictions are for the `getOpenAIAuth` + `ChatGPTAPI` solution, which uses the unofficial API. The browser-based solution, `ChatGPTAPIBrowser`, doesn't have many of these restrictions, though you'll still have to manually bypass CAPTCHAs by hand.
Note: currently `ChatGPTAPIBrowser` doesn't support continuing arbitrary conversations based on `conversationId`. You can only continue conversations in the current tab or start new conversations using the `resetThread()` function.
**Please read carefully** **Please read carefully**
- You must use `node >= 18` at the moment. I'm using `v19.2.0` in my testing. - You must use `node >= 18` at the moment. I'm using `v19.2.0` in my testing.
......
This diff is collapsed.
...@@ -127,7 +127,7 @@ export async function getOpenAIAuth({ ...@@ -127,7 +127,7 @@ export async function getOpenAIAuth({
} }
await page.click('button[type="submit"]') await page.click('button[type="submit"]')
await page.waitForSelector('#password') await page.waitForSelector('#password', { timeout: timeoutMs })
await page.type('#password', password, { delay: 10 }) await page.type('#password', password, { delay: 10 })
submitP = () => page.click('button[type="submit"]') submitP = () => page.click('button[type="submit"]')
} }
......
...@@ -297,3 +297,19 @@ export class ChatGPTError extends Error { ...@@ -297,3 +297,19 @@ export class ChatGPTError extends Error {
response?: Response response?: Response
originalError?: Error originalError?: Error
} }
export type ChatError = {
error: { message: string; statusCode?: number; statusText?: string }
response: null
conversationId?: string
messageId?: string
conversationResponse?: ConversationResponseEvent
}
export type ChatResponse = {
error: null
response: string
conversationId: string
messageId: string
conversationResponse?: ConversationResponseEvent
}
This diff is collapsed.
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