Skip to content

Commit

Permalink
Handling finish_reason when using SSE
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Sep 24, 2023
1 parent 85b12b6 commit 813825a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/files/system/openai/front.files/chat/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ function aista_submit_form(speech) {
return; // Returning early ...
}

if (obj.finish_reason) {

// We've got a finish reason from OpenAI.
const answer = window.document.getElementsByClassName('ainiro-has-more')[0];
answer.className = answer.className + ' ' + obj.finish_reason;
return;
}

// Appending response to temporary result.
ainiroTempContent += obj.message;

Expand Down
6 changes: 6 additions & 0 deletions backend/files/system/openai/magic.startup/magic.ai.chat.hl
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ select prompt, max(completion) as completion
set-value:x:@.finish_reason
get-value:x:@json2lambda/*/choices/0/*/finish_reason

// Signaling client
unwrap:x:+/*/*
sockets.signal:x:@.session
args
finish_reason:x:@.finish_reason

// Making sure we have a message.
if
and
Expand Down

0 comments on commit 813825a

Please sign in to comment.