Skip to content

Commit

Permalink
feat: fix capacity error
Browse files Browse the repository at this point in the history
  • Loading branch information
transitive-bullshit committed Dec 15, 2022
1 parent 61e9148 commit 0385b8d
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 164 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"expiry-map": "^2.0.0",
"p-timeout": "^6.0.0",
"puppeteer-extra": "^3.3.4",
"puppeteer-extra-plugin-recaptcha": "^3.6.6",
"puppeteer-extra-plugin-stealth": "^2.11.1",
"remark": "^14.0.2",
"strip-markdown": "^5.0.0",
Expand Down
22 changes: 0 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ export * from './chatgpt-conversation'
export * from './types'
export * from './utils'
export * from './openai-auth'
export * from './openai-auth-2captcha'

130 changes: 0 additions & 130 deletions src/openai-auth-2captcha.ts

This file was deleted.

13 changes: 4 additions & 9 deletions src/openai-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ export async function getOpenAIAuth({

await page.goto('https://chat.openai.com/auth/login')

await checkForChatGPTAtCapacity(page)

// NOTE: this is where you may encounter a CAPTCHA
var capacityLimit = await page.$('[role="alert"]')
if (capacityLimit) {
throw `ChatGPT is at capacity right now`
}
await checkForChatGPTAtCapacity(page)

await page.waitForSelector('#__next .btn-primary', { timeout: timeoutMs })

Expand Down Expand Up @@ -231,15 +226,15 @@ export const defaultChromeExecutablePath = (): string => {
}

async function checkForChatGPTAtCapacity(page: Page) {
let res: ElementHandle<Element> | null
let res: ElementHandle<Node>[]

try {
res = await page.$('[role="alert"]')
res = await page.$x("//div[contains(., 'ChatGPT is at capacity')]")
} catch (err) {
// ignore errors likely due to navigation
}

if (res) {
if (res?.length) {
const error = new types.ChatGPTError(`ChatGPT is at capacity: ${res}`)
error.statusCode = 503
throw error
Expand Down

0 comments on commit 0385b8d

Please sign in to comment.