Skip to content

Commit 2130f36

Browse files
authored
Address empty text chunck problem (#6723)
1 parent c1dfbf0 commit 2130f36

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantsChatClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
245245

246246
if (fileId is not null)
247247
{
248+
if (textUpdate.Contents.Count == 0)
249+
{
250+
// In case a chunk doesn't have text content, create one with empty text to hold the annotation.
251+
textUpdate.Contents.Add(new TextContent(string.Empty));
252+
}
253+
248254
(((TextContent)textUpdate.Contents[0]).Annotations ??= []).Add(new CitationAnnotation
249255
{
250256
RawRepresentation = tau,

0 commit comments

Comments
 (0)