Skip to content

Commit

Permalink
fixing issue where streaming OpenAI Assistant result images would dis…
Browse files Browse the repository at this point in the history
…play two clone images
  • Loading branch information
OvidijusParsiunas committed Apr 13, 2024
1 parent fae09a3 commit fc81951
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions component/src/services/openAI/openAIAssistantIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,14 @@ export class OpenAIAssistantIO extends DirectServiceIO {
// prettier-ignore
private async parseStreamResult(result: OpenAIAssistantInitReqResult) {
if (result.content && result.content.length > 0 && this.messages) {
const downloadCb = OpenAIAssistantUtils.getFilesAndText.bind(this,
this, {role: 'assistant', content: result.content}, result.content[0]);
this.messageStream?.endStreamAfterFileDownloaded(this.messages, downloadCb);
return {text: ''};
// if file is included and there is an annotation/link in text, process at the end
const textContent = result.content.find((content) => content.text);
if (textContent?.text?.annotations && textContent.text.annotations.length > 0) {
const downloadCb = OpenAIAssistantUtils.getFilesAndText.bind(this,
this, {role: 'assistant', content: result.content}, result.content[0]);
this.messageStream?.endStreamAfterFileDownloaded(this.messages, downloadCb);
return {text: ''};
}
}
if (result.delta?.content) {
if (!this.streamedMessageId) {
Expand All @@ -261,8 +265,12 @@ export class OpenAIAssistantIO extends DirectServiceIO {
this.messageStream?.newMessage();
}
if (result.delta.content.length > 1) {
const messages = await OpenAIAssistantUtils.processStreamMessages(this, result.delta.content);
return {text: messages[0].text, files: messages[1].files};
// if file is included and there is no annotation/link in text, process during the stream
const textContent = result.delta.content.find((content) => content.text);
if (textContent?.text?.annotations && textContent.text.annotations.length === 0) {
const messages = await OpenAIAssistantUtils.processStreamMessages(this, result.delta.content);
return {text: messages[0].text, files: messages[1].files};
}
}
return {text: result.delta.content[0].text?.value};
}
Expand Down

0 comments on commit fc81951

Please sign in to comment.