feat: add support for citations when streaming

This commit is contained in:
Stevan Freeborn
2025-06-14 22:24:44 -05:00
parent 74ac1ffc06
commit 98da1384c1
5 changed files with 188 additions and 7 deletions
+30 -3
View File
@@ -124,10 +124,37 @@ public class AnthropicApiClient : IAnthropicApiClient
// current content type and delta type
if (currentEvent.Type is EventType.ContentBlockDelta && currentEvent.Data is ContentDeltaEventData contentDeltaData)
{
if (content is TextContent textContent && contentDeltaData.Delta is TextDelta textDelta)
if (content is TextContent textContent)
{
var newText = textContent.Text + textDelta.Text;
content = new TextContent(newText);
if (contentDeltaData.Delta is TextDelta textDelta)
{
var newText = textContent.Text + textDelta.Text;
content = new TextContent(newText)
{
Citations = textContent.Citations,
};
}
if (contentDeltaData.Delta is CitationDelta citationDelta)
{
var citations = new List<Citation>()
{
citationDelta.Citation,
};
if (textContent.Citations is not null)
{
citations.AddRange(textContent.Citations);
}
var newContent = new TextContent(textContent.Text)
{
Citations = [.. citations],
};
content = newContent;
}
}
if (content is ToolUseContent toolUseContent && contentDeltaData.Delta is JsonDelta jsonDelta)