feat: initial pass at citations in request and response

This commit is contained in:
Stevan Freeborn
2025-06-10 23:34:33 -05:00
parent 8326e1749d
commit a9d0dfdc76
7 changed files with 146 additions and 0 deletions
@@ -286,6 +286,35 @@ public class AnthropicApiClientTests(ConfigurationFixture configFixture) : EndTo
resultTwo.Value.Usage.CacheReadInputTokens.Should().BeGreaterThan(0);
}
[Fact]
public async Task CreateMessageAsync_WhenCitationsAreEnabled_ItShouldReturnCitationsInResponse()
{
var request = new MessageRequest(
model: AnthropicModels.Claude3Haiku,
messages: [
new(
MessageRole.User,
[
new DocumentContent(
new TextDocumentSource("The grass is green. The sky is blue.")
)
{
Title = "My Document",
Context = "This is a trustworthy document.",
Citations = new() { Enabled = true }
},
new TextContent("What color is the grass and sky?"),
]
)
]
);
var result = await _client.CreateMessageAsync(request);
result.IsSuccess.Should().BeTrue();
result.Value.Content.OfType<TextContent>().SelectMany(c => c.Citations).Should().NotBeEmpty();
}
[Fact]
public async Task CountMessageTokensAsync_WhenCalled_ItShouldReturnResponse()
{