Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Chatgpt Puppeteer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Chatgpt Puppeteer
Commits
df424df1
Commit
df424df1
authored
Dec 17, 2022
by
Travis Fischer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: retry if at capacity
parent
54f97eb0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
11 deletions
+41
-11
src/openai-auth.ts
src/openai-auth.ts
+41
-11
No files found.
src/openai-auth.ts
View file @
df424df1
...
...
@@ -88,7 +88,7 @@ export async function getOpenAIAuth({
await
page
.
solveRecaptchas
()
}
await
checkForChatGPTAtCapacity
(
page
)
await
checkForChatGPTAtCapacity
(
page
,
{
timeoutMs
}
)
// once we get to this point, the Cloudflare cookies should be available
...
...
@@ -109,7 +109,7 @@ export async function getOpenAIAuth({
page
.
click
(
'
#__next .btn-primary
'
)
])
await
checkForChatGPTAtCapacity
(
page
)
await
checkForChatGPTAtCapacity
(
page
,
{
timeoutMs
}
)
let
submitP
:
()
=>
Promise
<
void
>
...
...
@@ -160,7 +160,7 @@ export async function getOpenAIAuth({
])
}
else
{
await
delay
(
2000
)
await
checkForChatGPTAtCapacity
(
page
)
await
checkForChatGPTAtCapacity
(
page
,
{
timeoutMs
}
)
}
const
pageCookies
=
await
page
.
cookies
()
...
...
@@ -347,17 +347,47 @@ export const defaultChromeExecutablePath = (): string => {
}
}
async
function
checkForChatGPTAtCapacity
(
page
:
Page
)
{
async
function
checkForChatGPTAtCapacity
(
page
:
Page
,
opts
:
{
timeoutMs
?:
number
retries
?:
number
}
=
{}
)
{
const
{
timeoutMs
=
2
*
60
*
1000
,
// 2 minutes
retries
=
10
}
=
opts
// console.log('checkForChatGPTAtCapacity', page.url())
let
res
:
any
[]
let
isAtCapacity
=
false
let
numTries
=
0
try
{
res
=
await
page
.
$x
(
"
//div[contains(., 'ChatGPT is at capacity')]
"
)
}
catch
(
err
)
{
// ignore errors likely due to navigation
}
do
{
try
{
const
res
=
await
page
.
$x
(
"
//div[contains(., 'ChatGPT is at capacity')]
"
)
isAtCapacity
=
!!
res
?.
length
if
(
isAtCapacity
)
{
if
(
++
numTries
>=
retries
)
{
break
}
// try refreshing the page if chatgpt is at capacity
await
page
.
reload
({
waitUntil
:
'
networkidle2
'
,
timeout
:
timeoutMs
})
await
delay
(
2000
)
}
}
catch
(
err
)
{
// ignore errors likely due to navigation
++
numTries
break
}
}
while
(
isAtCapacity
)
if
(
res
?.
length
)
{
if
(
isAtCapacity
)
{
const
error
=
new
types
.
ChatGPTError
(
'
ChatGPT is at capacity
'
)
error
.
statusCode
=
503
throw
error
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment