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
df94c613
Commit
df94c613
authored
Dec 06, 2022
by
simon3000
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optional params for Conversation
parent
9e891f52
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
15 deletions
+24
-15
src/chatgpt-api.ts
src/chatgpt-api.ts
+24
-15
No files found.
src/chatgpt-api.ts
View file @
df94c613
...
@@ -16,16 +16,21 @@ const USER_AGENT =
...
@@ -16,16 +16,21 @@ const USER_AGENT =
* manually pass the conversation ID and parent message ID for each message.
* manually pass the conversation ID and parent message ID for each message.
*/
*/
class
Conversation
{
class
Conversation
{
protected
_
api
:
ChatGPTAPI
api
:
ChatGPTAPI
protected
_
conversationId
:
string
=
undefined
conversationId
:
string
=
undefined
p
rotected
_p
arentMessageId
:
string
=
undefined
parentMessageId
:
string
=
undefined
/**
/**
* Creates a new conversation wrapper around the ChatGPT API.
* Creates a new conversation wrapper around the ChatGPT API.
* @param api - The ChatGPT API instance to use.
* @param api - The ChatGPT API instance to use.
*/
*/
constructor
(
api
:
ChatGPTAPI
)
{
constructor
(
this
.
_api
=
api
api
:
ChatGPTAPI
,
opts
:
{
conversationId
?:
string
;
parentMessageId
?:
string
}
=
{}
)
{
this
.
api
=
api
this
.
conversationId
=
opts
.
conversationId
this
.
parentMessageId
=
opts
.
parentMessageId
}
}
/**
/**
...
@@ -54,23 +59,23 @@ class Conversation {
...
@@ -54,23 +59,23 @@ class Conversation {
}
=
{}
}
=
{}
)
{
)
{
const
{
onProgress
,
onConversationResponse
}
=
opts
const
{
onProgress
,
onConversationResponse
}
=
opts
if
(
!
this
.
_
conversationId
)
{
if
(
!
this
.
conversationId
)
{
return
this
.
_
api
.
sendMessage
(
message
,
{
return
this
.
api
.
sendMessage
(
message
,
{
onProgress
,
onProgress
,
onConversationResponse
:
(
response
)
=>
{
onConversationResponse
:
(
response
)
=>
{
this
.
_
conversationId
=
response
.
conversation_id
this
.
conversationId
=
response
.
conversation_id
this
.
_
parentMessageId
=
response
.
message
.
id
this
.
parentMessageId
=
response
.
message
.
id
onConversationResponse
?.(
response
)
onConversationResponse
?.(
response
)
}
}
})
})
}
}
return
this
.
_
api
.
sendMessage
(
message
,
{
return
this
.
api
.
sendMessage
(
message
,
{
conversationId
:
this
.
_
conversationId
,
conversationId
:
this
.
conversationId
,
parentMessageId
:
this
.
_
parentMessageId
,
parentMessageId
:
this
.
parentMessageId
,
onProgress
,
onProgress
,
onConversationResponse
:
(
response
)
=>
{
onConversationResponse
:
(
response
)
=>
{
this
.
_
parentMessageId
=
response
.
message
.
id
this
.
parentMessageId
=
response
.
message
.
id
onConversationResponse
?.(
response
)
onConversationResponse
?.(
response
)
}
}
})
})
...
@@ -285,9 +290,13 @@ export class ChatGPTAPI {
...
@@ -285,9 +290,13 @@ export class ChatGPTAPI {
/**
/**
* Get a new Conversation instance, which can be used to send multiple messages as part of a single conversation.
* Get a new Conversation instance, which can be used to send multiple messages as part of a single conversation.
*
*
* @param opts.conversationId - Optional Data of the previous message in a conversation
* @param opts.parentMessageId - Optional Data of the previous message in a conversation
* @returns a new Conversation instance
* @returns a new Conversation instance
*/
*/
getConversation
()
{
getConversation
(
return
new
Conversation
(
this
)
opts
:
{
conversationId
?:
string
;
parentMessageId
?:
string
}
=
{}
)
{
return
new
Conversation
(
this
,
opts
)
}
}
}
}
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