From 57f66d36195a0b9e3ee31758e2f346d7a5d78614 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:47:35 -0600 Subject: [PATCH] chore: remove need for beta header when using prompt caching or PDF support --- README.md | 39 +------------------ .../EndToEnd/AnthropicApiClientTests.cs | 25 +++--------- 2 files changed, 8 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index a03e6a3..e5a3580 100644 --- a/README.md +++ b/README.md @@ -694,22 +694,7 @@ foreach (var content in response.Value.Content) ### Prompt Caching -Anthropic has recently introduced a feature called [Prompt Caching](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching) that allows you to cache all or part of the prompt you send to the model. This can be used to improve the performance of your application by reducing latency and token usage. This feature is covered in depth in [Anthropic's API Documentation](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching). - -> [!NOTE] -> This feature is in beta and requires you to set an `anthropic-beta` header on your requests to use it. -> The value of the header should be `prompt-caching-2024-07-31`. - -When using this library you can opt-in to prompt caching by adding the required header to the `HttpClient` instance you provide to the `AnthropicApiClient` constructor. - -```csharp -using AnthropicClient; - -var httpClient = new HttpClient(); -httpClient.DefaultRequestHeaders.Add("anthropic-beta", "prompt-caching-2024-07-31"); - -var client = new AnthropicApiClient(apiKey, httpClient); -``` +Anthropic provides a feature called [Prompt Caching](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching) that allows you to cache all or part of the prompt you send to the model. This can be used to improve the performance of your application by reducing latency and token usage. This feature is covered in depth in [Anthropic's API Documentation](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching). Prompt caching can be used to cache all parts of the prompt including system messages, user messages, and tools. You should refer to the [Anthropic API Documentation](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching) for specifics on limitations and requirements for using prompt caching. This library aims to make using prompt caching convenient and give you complete control over what parts of the prompt are cached. Currently there is only one type of cache control available - `EphemeralCacheControl`. @@ -850,22 +835,7 @@ foreach (var content in response.Value.Content) ### PDF Support -Anthropic has recently introduced a feature called [PDF Support](https://docs.anthropic.com/en/docs/build-with-claude/pdf-support) that allows Claude to support PDF input and understand both text and visual content within documents. . This feature is covered in depth in [Anthropic's API Documentation](https://docs.anthropic.com/en/docs/build-with-claude/pdf-support). - -> [!NOTE] -> This feature is in beta and requires you to set an `anthropic-beta` header on your requests to use it. -> The value of the header should be `pdfs-2024-09-25`. - -When using this library you can opt-in to PDF support by adding the required header to the `HttpClient` instance you provide to the `AnthropicApiClient` constructor. - -```csharp -using AnthropicClient; - -var httpClient = new HttpClient(); -httpClient.DefaultRequestHeaders.Add("anthropic-beta", "pdfs-2024-09-25"); - -var client = new AnthropicApiClient(apiKey, httpClient); -``` +Anthropic provides a feature called [PDF Support](https://docs.anthropic.com/en/docs/build-with-claude/pdf-support) that allows Claude to support PDF input and understand both text and visual content within documents. This feature is covered in depth in [Anthropic's API Documentation](https://docs.anthropic.com/en/docs/build-with-claude/pdf-support). PDF support can be used to provide a PDF document as input to the model. This can be used to provide additional context to the model or to ask for additional information from the model. This library aims to make using PDF support convenient by allowing you to provide the PDF document you want Anthropic's models to consider for use when creating a message. @@ -885,11 +855,6 @@ var request = new MessageRequest( ] ); -var httpClient = new HttpClient(); -httpClient.DefaultRequestHeaders.Add("anthropic-beta", "pdfs-2024-09-25"); - -var client = new AnthropicApiClient(apiKey, httpClient); - var response = await client.CreateMessageAsync(request); if (response.IsSuccess is false) diff --git a/tests/AnthropicClient.Tests/EndToEnd/AnthropicApiClientTests.cs b/tests/AnthropicClient.Tests/EndToEnd/AnthropicApiClientTests.cs index 75040e8..50dab64 100644 --- a/tests/AnthropicClient.Tests/EndToEnd/AnthropicApiClientTests.cs +++ b/tests/AnthropicClient.Tests/EndToEnd/AnthropicApiClientTests.cs @@ -100,10 +100,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf [Fact] public async Task CreateMessageAsync_WhenSystemMessagesContainCacheControl_ItShouldUseCache() { - var httpClient = new HttpClient(); - httpClient.DefaultRequestHeaders.Add("anthropic-beta", "prompt-caching-2024-07-31"); - - var client = CreateClient(httpClient); + var client = CreateClient(new HttpClient()); var storyPath = GetTestFilePath("story.txt"); var storyText = await File.ReadAllTextAsync(storyPath); @@ -121,7 +118,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf ] ); - var resultOne = await client.CreateMessageAsync(request); + var resultOne = await _client.CreateMessageAsync(request); resultOne.IsSuccess.Should().BeTrue(); resultOne.Value.Should().BeOfType(); @@ -142,10 +139,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf [Fact] public async Task CreateMessageAsync_WhenMessagesContainCacheControl_ItShouldUseCache() { - var httpClient = new HttpClient(); - httpClient.DefaultRequestHeaders.Add("anthropic-beta", "prompt-caching-2024-07-31"); - - var client = CreateClient(httpClient); + var client = CreateClient(new HttpClient()); var storyPath = GetTestFilePath("story.txt"); var storyText = await File.ReadAllTextAsync(storyPath); @@ -181,10 +175,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf [Fact] public async Task CreateMessageAsync_WhenToolsContainCacheControl_ItShouldUseCache() { - var httpClient = new HttpClient(); - httpClient.DefaultRequestHeaders.Add("anthropic-beta", "prompt-caching-2024-07-31"); - - var client = CreateClient(httpClient); + var client = CreateClient(new HttpClient()); var func = (string ticker) => ticker; @@ -238,9 +229,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf ] ); - var httpClient = new HttpClient(); - httpClient.DefaultRequestHeaders.Add("anthropic-beta", "pdfs-2024-09-25"); - var client = CreateClient(httpClient); + var client = CreateClient(new HttpClient()); var result = await client.CreateMessageAsync(request); @@ -268,9 +257,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf var bytes = await File.ReadAllBytesAsync(pdfPath); var base64Data = Convert.ToBase64String(bytes); - var httpClient = new HttpClient(); - httpClient.DefaultRequestHeaders.Add("anthropic-beta", "pdfs-2024-09-25, prompt-caching-2024-07-31"); - var client = CreateClient(httpClient); + var client = CreateClient(new HttpClient()); var request = new MessageRequest( model: AnthropicModels.Claude35Sonnet,