Skip to content

Commit

Permalink
feat(ChatGPTBrowserClient): add optional onEventMessage parameter to …
Browse files Browse the repository at this point in the history
…postConversation method to handle event messages from the server. (#297)
  • Loading branch information
danny-avila authored Apr 12, 2023
1 parent c55bc25 commit c34ae10
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ChatGPTBrowserClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class ChatGPTBrowserClient {
this.model = this.options.model || 'text-davinci-002-render-sha';
}

async postConversation(conversation, onProgress, abortController = null) {
async postConversation(conversation, onProgress, abortController, onEventMessage = null) {
const {
action = 'next',
conversationId,
Expand Down Expand Up @@ -133,6 +133,11 @@ export default class ChatGPTBrowserClient {
if (debug) {
console.debug(eventMessage);
}

if (onEventMessage) {
onEventMessage(eventMessage);
}

if (!eventMessage.data || eventMessage.event === 'ping') {
return;
}
Expand Down Expand Up @@ -212,6 +217,7 @@ export default class ChatGPTBrowserClient {
},
opts.onProgress || (() => {}),
opts.abortController || new AbortController(),
opts?.onEventMessage,
);

if (this.options.debug) {
Expand Down

0 comments on commit c34ae10

Please sign in to comment.