chore: remove need for beta header when using prompt caching or PDF support
This commit is contained in:
@@ -694,22 +694,7 @@ foreach (var content in response.Value.Content)
|
|||||||
|
|
||||||
### Prompt Caching
|
### 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).
|
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).
|
||||||
|
|
||||||
> [!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);
|
|
||||||
```
|
|
||||||
|
|
||||||
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`.
|
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
|
### 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).
|
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).
|
||||||
|
|
||||||
> [!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);
|
|
||||||
```
|
|
||||||
|
|
||||||
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.
|
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);
|
var response = await client.CreateMessageAsync(request);
|
||||||
|
|
||||||
if (response.IsSuccess is false)
|
if (response.IsSuccess is false)
|
||||||
|
|||||||
@@ -100,10 +100,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task CreateMessageAsync_WhenSystemMessagesContainCacheControl_ItShouldUseCache()
|
public async Task CreateMessageAsync_WhenSystemMessagesContainCacheControl_ItShouldUseCache()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient();
|
var client = CreateClient(new HttpClient());
|
||||||
httpClient.DefaultRequestHeaders.Add("anthropic-beta", "prompt-caching-2024-07-31");
|
|
||||||
|
|
||||||
var client = CreateClient(httpClient);
|
|
||||||
|
|
||||||
var storyPath = GetTestFilePath("story.txt");
|
var storyPath = GetTestFilePath("story.txt");
|
||||||
var storyText = await File.ReadAllTextAsync(storyPath);
|
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.IsSuccess.Should().BeTrue();
|
||||||
resultOne.Value.Should().BeOfType<MessageResponse>();
|
resultOne.Value.Should().BeOfType<MessageResponse>();
|
||||||
@@ -142,10 +139,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task CreateMessageAsync_WhenMessagesContainCacheControl_ItShouldUseCache()
|
public async Task CreateMessageAsync_WhenMessagesContainCacheControl_ItShouldUseCache()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient();
|
var client = CreateClient(new HttpClient());
|
||||||
httpClient.DefaultRequestHeaders.Add("anthropic-beta", "prompt-caching-2024-07-31");
|
|
||||||
|
|
||||||
var client = CreateClient(httpClient);
|
|
||||||
|
|
||||||
var storyPath = GetTestFilePath("story.txt");
|
var storyPath = GetTestFilePath("story.txt");
|
||||||
var storyText = await File.ReadAllTextAsync(storyPath);
|
var storyText = await File.ReadAllTextAsync(storyPath);
|
||||||
@@ -181,10 +175,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task CreateMessageAsync_WhenToolsContainCacheControl_ItShouldUseCache()
|
public async Task CreateMessageAsync_WhenToolsContainCacheControl_ItShouldUseCache()
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient();
|
var client = CreateClient(new HttpClient());
|
||||||
httpClient.DefaultRequestHeaders.Add("anthropic-beta", "prompt-caching-2024-07-31");
|
|
||||||
|
|
||||||
var client = CreateClient(httpClient);
|
|
||||||
|
|
||||||
var func = (string ticker) => ticker;
|
var func = (string ticker) => ticker;
|
||||||
|
|
||||||
@@ -238,9 +229,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
var httpClient = new HttpClient();
|
var client = CreateClient(new HttpClient());
|
||||||
httpClient.DefaultRequestHeaders.Add("anthropic-beta", "pdfs-2024-09-25");
|
|
||||||
var client = CreateClient(httpClient);
|
|
||||||
|
|
||||||
var result = await client.CreateMessageAsync(request);
|
var result = await client.CreateMessageAsync(request);
|
||||||
|
|
||||||
@@ -268,9 +257,7 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf
|
|||||||
var bytes = await File.ReadAllBytesAsync(pdfPath);
|
var bytes = await File.ReadAllBytesAsync(pdfPath);
|
||||||
var base64Data = Convert.ToBase64String(bytes);
|
var base64Data = Convert.ToBase64String(bytes);
|
||||||
|
|
||||||
var httpClient = new HttpClient();
|
var client = CreateClient(new HttpClient());
|
||||||
httpClient.DefaultRequestHeaders.Add("anthropic-beta", "pdfs-2024-09-25, prompt-caching-2024-07-31");
|
|
||||||
var client = CreateClient(httpClient);
|
|
||||||
|
|
||||||
var request = new MessageRequest(
|
var request = new MessageRequest(
|
||||||
model: AnthropicModels.Claude35Sonnet,
|
model: AnthropicModels.Claude35Sonnet,
|
||||||
|
|||||||
Reference in New Issue
Block a user