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
8e0f32b4
Commit
8e0f32b4
authored
Dec 15, 2022
by
Travis Fischer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add timeout support to browser sendMessage
parent
0d09ca96
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
13 deletions
+34
-13
src/chatgpt-api-browser.ts
src/chatgpt-api-browser.ts
+34
-13
No files found.
src/chatgpt-api-browser.ts
View file @
8e0f32b4
import
delay
from
'
delay
'
import
delay
from
'
delay
'
import
html2md
from
'
html-to-md
'
import
html2md
from
'
html-to-md
'
import
pTimeout
from
'
p-timeout
'
import
type
{
Browser
,
HTTPRequest
,
HTTPResponse
,
Page
}
from
'
puppeteer
'
import
type
{
Browser
,
HTTPRequest
,
HTTPResponse
,
Page
}
from
'
puppeteer
'
import
{
getBrowser
,
getOpenAIAuth
}
from
'
./openai-auth
'
import
{
getBrowser
,
getOpenAIAuth
}
from
'
./openai-auth
'
...
@@ -275,7 +276,14 @@ export class ChatGPTAPIBrowser {
...
@@ -275,7 +276,14 @@ export class ChatGPTAPIBrowser {
}
}
}
}
async
sendMessage
(
message
:
string
):
Promise
<
string
>
{
async
sendMessage
(
message
:
string
,
opts
:
{
timeoutMs
?:
number
}
=
{}
):
Promise
<
string
>
{
const
{
timeoutMs
}
=
opts
const
inputBox
=
await
this
.
_getInputBox
()
const
inputBox
=
await
this
.
_getInputBox
()
if
(
!
inputBox
)
throw
new
Error
(
'
not signed in
'
)
if
(
!
inputBox
)
throw
new
Error
(
'
not signed in
'
)
...
@@ -294,19 +302,32 @@ export class ChatGPTAPIBrowser {
...
@@ -294,19 +302,32 @@ export class ChatGPTAPIBrowser {
}
}
}
}
do
{
const
responseP
=
new
Promise
<
string
>
(
async
(
resolve
,
reject
)
=>
{
await
delay
(
1000
)
try
{
do
{
// TODO: this logic needs some work because we can have repeat messages...
await
delay
(
1000
)
const
newLastMessage
=
await
this
.
getLastMessage
()
if
(
// TODO: this logic needs some work because we can have repeat messages...
newLastMessage
&&
const
newLastMessage
=
await
this
.
getLastMessage
()
lastMessage
?.
toLowerCase
()
!==
newLastMessage
?.
toLowerCase
()
if
(
)
{
newLastMessage
&&
await
delay
(
5000
)
lastMessage
?.
toLowerCase
()
!==
newLastMessage
?.
toLowerCase
()
return
newLastMessage
)
{
return
resolve
(
newLastMessage
)
}
}
while
(
true
)
}
catch
(
err
)
{
return
reject
(
err
)
}
}
}
while
(
true
)
})
if
(
timeoutMs
)
{
return
pTimeout
(
responseP
,
{
milliseconds
:
timeoutMs
})
}
else
{
return
responseP
}
}
}
async
resetThread
()
{
async
resetThread
()
{
...
...
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