Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df0738ac7f | ||
|
|
0dd7829733 | ||
|
|
0b81bfc2f6 | ||
|
|
33191a32cc | ||
|
|
3fe75f511d | ||
|
|
9abad390f1 | ||
|
|
8bbd4bb7c8 | ||
|
|
8e0443a6bb | ||
|
|
9d341011df | ||
|
|
df75cd25e0 | ||
|
|
28b7bf6a89 | ||
|
|
9e367d3542 | ||
|
|
4a7d2c39be | ||
|
|
e08c94ec57 | ||
|
|
5a1bf4ca41 | ||
|
|
de326abe25 | ||
|
|
57f66d3619 | ||
|
|
a23938961f | ||
|
|
4fe8bfaf0e | ||
|
|
944822060c | ||
|
|
31a7097cdc | ||
|
|
8ef9a21a93 | ||
|
|
87ecb6e5ad | ||
|
|
abf4154432 | ||
|
|
9c0a2e37b7 | ||
|
|
f861155551 | ||
|
|
6e0c0654af | ||
|
|
6b6bc1b015 |
Vendored
+1
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"editor.formatOnSave": true,
|
||||
"dotnet.defaultSolution": "AnthropicClient.sln",
|
||||
"cSpell.words": [
|
||||
"Browsable",
|
||||
|
||||
@@ -105,9 +105,105 @@ The primary use case for working with the Anthropic API is to create a message i
|
||||
> [!NOTE]
|
||||
> The following examples assume that you have already created an instance of the `AnthropicApiClient` class named `client`. You can also find these snippets in the examples directory.
|
||||
|
||||
### Count Message Tokens
|
||||
|
||||
The `AnthropicApiClient` exposes a method named `CountMessageTokensAsync` that can be used to count the number of tokens in a message. The method requires a `CountMessageTokensRequest` instance as a parameter.
|
||||
|
||||
```csharp
|
||||
using AnthropicClient;
|
||||
using AnthropicClient.Models;
|
||||
|
||||
var response = await client.CountMessageTokensAsync(new CountMessageTokensRequest(
|
||||
AnthropicModels.Claude3Haiku,
|
||||
[
|
||||
new(
|
||||
MessageRole.User,
|
||||
[new TextContent("Please write a haiku about the ocean.")]
|
||||
)
|
||||
]
|
||||
));
|
||||
|
||||
if (response.IsFailure)
|
||||
{
|
||||
Console.WriteLine("Failed to count message tokens");
|
||||
Console.WriteLine("Error Type: {0}", response.Error.Error.Type);
|
||||
Console.WriteLine("Error Message: {0}", response.Error.Error.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Token Count: {0}", response.Value.InputTokens);
|
||||
```
|
||||
|
||||
### List Models
|
||||
|
||||
The `AnthropicApiClient` exposes a method named `ListModelsAsync` that can be used to list the available models. The method takes an optional `PagingRequest` instance as a parameter.
|
||||
|
||||
```csharp
|
||||
using AnthropicClient;
|
||||
|
||||
var response = await client.ListModelsAsync();
|
||||
|
||||
if (response.IsFailure)
|
||||
{
|
||||
Console.WriteLine("Failed to list models");
|
||||
Console.WriteLine("Error Type: {0}", response.Error.Error.Type);
|
||||
Console.WriteLine("Error Message: {0}", response.Error.Error.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var model in response.Value.Data)
|
||||
{
|
||||
Console.WriteLine("Model Id: {0}", model.Id);
|
||||
Console.WriteLine("Model Name: {0}", model.DisplayName);
|
||||
}
|
||||
```
|
||||
|
||||
Using the `PagingRequest` instance allows you to specify the number of models to return and the page of models to return.
|
||||
|
||||
```csharp
|
||||
using AnthropicClient;
|
||||
using AnthropicClient.Models;
|
||||
|
||||
var response = await client.ListModelsAsync(new PagingRequest(afterId: "claude-3-5-sonnet-20241022", limit: 2));
|
||||
|
||||
if (response.IsFailure)
|
||||
{
|
||||
Console.WriteLine("Failed to list models");
|
||||
Console.WriteLine("Error Type: {0}", response.Error.Error.Type);
|
||||
Console.WriteLine("Error Message: {0}", response.Error.Error.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var model in response.Value.Data)
|
||||
{
|
||||
Console.WriteLine("Model Id: {0}", model.Id);
|
||||
Console.WriteLine("Model Name: {0}", model.DisplayName);
|
||||
}
|
||||
```
|
||||
|
||||
### Get Model
|
||||
|
||||
The `AnthropicApiClient` exposes a method named `GetModelAsync` that can be used to get a model by its id.
|
||||
|
||||
```csharp
|
||||
using AnthropicClient;
|
||||
|
||||
var response = await client.GetModelAsync("claude-3-5-sonnet-20241022");
|
||||
|
||||
if (response.IsFailure)
|
||||
{
|
||||
Console.WriteLine("Failed to get model");
|
||||
Console.WriteLine("Error Type: {0}", response.Error.Error.Type);
|
||||
Console.WriteLine("Error Message: {0}", response.Error.Error.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Model Id: {0}", response.Value.Id);
|
||||
```
|
||||
|
||||
### Create a message
|
||||
|
||||
The `AnthropicApiClient` exposes a single method named `CreateMessageAsync` that can be used to create a message. The method requires a `MessageRequest` or a `StreamMessageRequest` instance as a parameter. The `MessageRequest` class is used to create a message whose response is not streamed and the `StreamMessageRequest` class is used to create a message whose response is streamed. The `MessageRequest` instance's properties can be set to configure how the message is created.
|
||||
The `AnthropicApiClient` exposes a method named `CreateMessageAsync` that can be used to create a message. The method requires a `MessageRequest` or a `StreamMessageRequest` instance as a parameter. The `MessageRequest` class is used to create a message whose response is not streamed and the `StreamMessageRequest` class is used to create a message whose response is streamed. The `MessageRequest` instance's properties can be set to configure how the message is created.
|
||||
|
||||
#### Non-Streaming
|
||||
|
||||
@@ -694,22 +790,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 +931,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 +951,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)
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
|
||||
|
||||
<h1 id="AnthropicClient_AnthropicApiClient" data-uid="AnthropicClient.AnthropicApiClient" class="text-break">
|
||||
Class AnthropicApiClient <a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L32"><i class="bi bi-code-slash"></i></a>
|
||||
Class AnthropicApiClient <a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L39"><i class="bi bi-code-slash"></i></a>
|
||||
</h1>
|
||||
|
||||
<div class="facts text-secondary">
|
||||
@@ -163,7 +163,7 @@ Class AnthropicApiClient <a class="header-action link-secondary" title="View so
|
||||
|
||||
<h3 id="AnthropicClient_AnthropicApiClient__ctor_System_String_System_Net_Http_HttpClient_" data-uid="AnthropicClient.AnthropicApiClient.#ctor(System.String,System.Net.Http.HttpClient)">
|
||||
AnthropicApiClient(string, HttpClient)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L53"><i class="bi bi-code-slash"></i></a>
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L61"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="AnthropicClient.AnthropicApiClient.html">AnthropicApiClient</a> class.</p>
|
||||
@@ -205,11 +205,50 @@ Class AnthropicApiClient <a class="header-action link-secondary" title="View so
|
||||
</h2>
|
||||
|
||||
|
||||
<a id="AnthropicClient_AnthropicApiClient_CountMessageTokensAsync_" data-uid="AnthropicClient.AnthropicApiClient.CountMessageTokensAsync*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_AnthropicApiClient_CountMessageTokensAsync_AnthropicClient_Models_CountMessageTokensRequest_" data-uid="AnthropicClient.AnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest)">
|
||||
CountMessageTokensAsync(CountMessageTokensRequest)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L267"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Counts the tokens in a message asynchronously.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public Task<AnthropicResult<TokenCountResponse>> CountMessageTokensAsync(CountMessageTokensRequest request)</code></pre>
|
||||
</div>
|
||||
|
||||
<h4 class="section">Parameters</h4>
|
||||
<dl class="parameters">
|
||||
<dt><code>request</code> <a class="xref" href="AnthropicClient.Models.CountMessageTokensRequest.html">CountMessageTokensRequest</a></dt>
|
||||
<dd><p>The count message tokens request.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h4 class="section">Returns</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1">Task</a><<a class="xref" href="AnthropicResult-1.html">AnthropicResult</a><<a class="xref" href="AnthropicClient.Models.TokenCountResponse.html">TokenCountResponse</a>>></dt>
|
||||
<dd><p>A task that represents the asynchronous operation. The task result contains the response as an <a class="xref" href="AnthropicResult-1.html">AnthropicResult<T></a> where T is <a class="xref" href="AnthropicClient.Models.TokenCountResponse.html">TokenCountResponse</a>.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a id="AnthropicClient_AnthropicApiClient_CreateMessageAsync_" data-uid="AnthropicClient.AnthropicApiClient.CreateMessageAsync*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_AnthropicApiClient_CreateMessageAsync_AnthropicClient_Models_MessageRequest_" data-uid="AnthropicClient.AnthropicApiClient.CreateMessageAsync(AnthropicClient.Models.MessageRequest)">
|
||||
CreateMessageAsync(MessageRequest)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L72"><i class="bi bi-code-slash"></i></a>
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L80"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Creates a message asynchronously.</p>
|
||||
@@ -248,7 +287,7 @@ Class AnthropicApiClient <a class="header-action link-secondary" title="View so
|
||||
|
||||
<h3 id="AnthropicClient_AnthropicApiClient_CreateMessageAsync_AnthropicClient_Models_StreamMessageRequest_" data-uid="AnthropicClient.AnthropicApiClient.CreateMessageAsync(AnthropicClient.Models.StreamMessageRequest)">
|
||||
CreateMessageAsync(StreamMessageRequest)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L95"><i class="bi bi-code-slash"></i></a>
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L103"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Creates a message asynchronously and streams the response.</p>
|
||||
@@ -287,7 +326,7 @@ Class AnthropicApiClient <a class="header-action link-secondary" title="View so
|
||||
</article>
|
||||
|
||||
<div class="contribution d-print-none">
|
||||
<a href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L32" class="edit-link">Edit this page</a>
|
||||
<a href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L39" class="edit-link">Edit this page</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -121,6 +121,45 @@ Interface IAnthropicApiClient <a class="header-action link-secondary" title="Vi
|
||||
</h2>
|
||||
|
||||
|
||||
<a id="AnthropicClient_IAnthropicApiClient_CountMessageTokensAsync_" data-uid="AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_IAnthropicApiClient_CountMessageTokensAsync_AnthropicClient_Models_CountMessageTokensRequest_" data-uid="AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest)">
|
||||
CountMessageTokensAsync(CountMessageTokensRequest)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/AnthropicApiClient.cs/#L35"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Counts the tokens in a message asynchronously.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">Task<AnthropicResult<TokenCountResponse>> CountMessageTokensAsync(CountMessageTokensRequest request)</code></pre>
|
||||
</div>
|
||||
|
||||
<h4 class="section">Parameters</h4>
|
||||
<dl class="parameters">
|
||||
<dt><code>request</code> <a class="xref" href="AnthropicClient.Models.CountMessageTokensRequest.html">CountMessageTokensRequest</a></dt>
|
||||
<dd><p>The count message tokens request.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h4 class="section">Returns</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1">Task</a><<a class="xref" href="AnthropicResult-1.html">AnthropicResult</a><<a class="xref" href="AnthropicClient.Models.TokenCountResponse.html">TokenCountResponse</a>>></dt>
|
||||
<dd><p>A task that represents the asynchronous operation. The task result contains the response as an <a class="xref" href="AnthropicResult-1.html">AnthropicResult<T></a> where T is <a class="xref" href="AnthropicClient.Models.TokenCountResponse.html">TokenCountResponse</a>.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a id="AnthropicClient_IAnthropicApiClient_CreateMessageAsync_" data-uid="AnthropicClient.IAnthropicApiClient.CreateMessageAsync*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_IAnthropicApiClient_CreateMessageAsync_AnthropicClient_Models_MessageRequest_" data-uid="AnthropicClient.IAnthropicApiClient.CreateMessageAsync(AnthropicClient.Models.MessageRequest)">
|
||||
|
||||
@@ -154,12 +154,74 @@ Class AnthropicModels <a class="header-action link-secondary" title="View sourc
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude35Sonnet" data-uid="AnthropicClient.Models.AnthropicModels.Claude35Sonnet">
|
||||
Claude35Sonnet
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L21"><i class="bi bi-code-slash"></i></a>
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude35Haiku20241022" data-uid="AnthropicClient.Models.AnthropicModels.Claude35Haiku20241022">
|
||||
Claude35Haiku20241022
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L66"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude-3.5 Sonnet model.</p>
|
||||
<div class="markdown level1 summary"><p>The Claude 3.5 Haiku model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public const string Claude35Haiku20241022 = "claude-3-5-haiku-20241022"</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Field Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude35HaikuLatest" data-uid="AnthropicClient.Models.AnthropicModels.Claude35HaikuLatest">
|
||||
Claude35HaikuLatest
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L71"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude 3.5 Haiku model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public const string Claude35HaikuLatest = "claude-3-5-haiku-latest"</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Field Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude35Sonnet" data-uid="AnthropicClient.Models.AnthropicModels.Claude35Sonnet">
|
||||
Claude35Sonnet
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L36"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude 3.5 Sonnet model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
@@ -185,12 +247,105 @@ Class AnthropicModels <a class="header-action link-secondary" title="View sourc
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude3Haiku" data-uid="AnthropicClient.Models.AnthropicModels.Claude3Haiku">
|
||||
Claude3Haiku
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L26"><i class="bi bi-code-slash"></i></a>
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude35Sonnet20240620" data-uid="AnthropicClient.Models.AnthropicModels.Claude35Sonnet20240620">
|
||||
Claude35Sonnet20240620
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L41"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude-3 Haiku model.</p>
|
||||
<div class="markdown level1 summary"><p>The Claude 3.5 Sonnet model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public const string Claude35Sonnet20240620 = "claude-3-5-sonnet-20240620"</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Field Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude35Sonnet20241022" data-uid="AnthropicClient.Models.AnthropicModels.Claude35Sonnet20241022">
|
||||
Claude35Sonnet20241022
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L46"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude 3.5 Sonnet model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public const string Claude35Sonnet20241022 = "claude-3-5-sonnet-20241022"</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Field Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude35SonnetLatest" data-uid="AnthropicClient.Models.AnthropicModels.Claude35SonnetLatest">
|
||||
Claude35SonnetLatest
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L51"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude 3.5 Sonnet model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public const string Claude35SonnetLatest = "claude-3-5-sonnet-latest"</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Field Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude3Haiku" data-uid="AnthropicClient.Models.AnthropicModels.Claude3Haiku">
|
||||
Claude3Haiku
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L56"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude 3 Haiku model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
@@ -216,12 +371,43 @@ Class AnthropicModels <a class="header-action link-secondary" title="View sourc
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude3Haiku20240307" data-uid="AnthropicClient.Models.AnthropicModels.Claude3Haiku20240307">
|
||||
Claude3Haiku20240307
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L61"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude 3 Haiku model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public const string Claude3Haiku20240307 = "claude-3-haiku-20240307"</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Field Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude3Opus" data-uid="AnthropicClient.Models.AnthropicModels.Claude3Opus">
|
||||
Claude3Opus
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L11"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude-3 Opus model.</p>
|
||||
<div class="markdown level1 summary"><p>The Claude 3 Opus model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
@@ -247,12 +433,74 @@ Class AnthropicModels <a class="header-action link-secondary" title="View sourc
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude3Sonnet" data-uid="AnthropicClient.Models.AnthropicModels.Claude3Sonnet">
|
||||
Claude3Sonnet
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude3Opus20241022" data-uid="AnthropicClient.Models.AnthropicModels.Claude3Opus20241022">
|
||||
Claude3Opus20241022
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L16"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude-3 Sonnet model.</p>
|
||||
<div class="markdown level1 summary"><p>The Claude 3 Opus model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public const string Claude3Opus20241022 = "claude-3-opus-20240229"</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Field Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude3OpusLatest" data-uid="AnthropicClient.Models.AnthropicModels.Claude3OpusLatest">
|
||||
Claude3OpusLatest
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L21"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude 3 Opus model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public const string Claude3OpusLatest = "claude-3-opus-latest"</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Field Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude3Sonnet" data-uid="AnthropicClient.Models.AnthropicModels.Claude3Sonnet">
|
||||
Claude3Sonnet
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L26"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude 3 Sonnet model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
@@ -278,6 +526,37 @@ Class AnthropicModels <a class="header-action link-secondary" title="View sourc
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_AnthropicModels_Claude3Sonnet20240229" data-uid="AnthropicClient.Models.AnthropicModels.Claude3Sonnet20240229">
|
||||
Claude3Sonnet20240229
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/AnthropicModels.cs/#L31"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The Claude 3 Sonnet model.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public const string Claude3Sonnet20240229 = "claude-3-sonnet-20240229"</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Field Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
<div class="contribution d-print-none">
|
||||
|
||||
@@ -164,7 +164,7 @@ Class BaseMessageRequest <a class="header-action link-secondary" title="View so
|
||||
|
||||
<h3 id="AnthropicClient_Models_BaseMessageRequest__ctor_System_String_System_Collections_Generic_List_AnthropicClient_Models_Message__System_Int32_System_String_System_Collections_Generic_Dictionary_System_String_System_Object__System_Decimal_System_Nullable_System_Int32__System_Nullable_System_Decimal__AnthropicClient_Models_ToolChoice_System_Collections_Generic_List_AnthropicClient_Models_Tool__System_Boolean_System_Collections_Generic_List_System_String__System_Collections_Generic_List_AnthropicClient_Models_TextContent__" data-uid="AnthropicClient.Models.BaseMessageRequest.#ctor(System.String,System.Collections.Generic.List{AnthropicClient.Models.Message},System.Int32,System.String,System.Collections.Generic.Dictionary{System.String,System.Object},System.Decimal,System.Nullable{System.Int32},System.Nullable{System.Decimal},AnthropicClient.Models.ToolChoice,System.Collections.Generic.List{AnthropicClient.Models.Tool},System.Boolean,System.Collections.Generic.List{System.String},System.Collections.Generic.List{AnthropicClient.Models.TextContent})">
|
||||
BaseMessageRequest(string, List<Message>, int, string?, Dictionary<string, object>?, decimal, int?, decimal?, ToolChoice?, List<Tool>?, bool, List<string>?, List<TextContent>?)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/BaseMessageRequest.cs/#L135"><i class="bi bi-code-slash"></i></a>
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/BaseMessageRequest.cs/#L134"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="AnthropicClient.Models.BaseMessageRequest.html">BaseMessageRequest</a> class.</p>
|
||||
@@ -228,9 +228,6 @@ Class BaseMessageRequest <a class="header-action link-secondary" title="View so
|
||||
|
||||
<h4 class="section">Exceptions</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentexception">ArgumentException</a></dt>
|
||||
<dd><p>Thrown when the model ID is invalid.</p>
|
||||
</dd>
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentnullexception">ArgumentNullException</a></dt>
|
||||
<dd><p>Thrown when the model or messages is null.</p>
|
||||
</dd>
|
||||
|
||||
@@ -120,6 +120,7 @@ Class Content <a class="header-action link-secondary" title="View source" href=
|
||||
<dl class="typelist derived">
|
||||
<dt>Derived</dt>
|
||||
<dd>
|
||||
<div><a class="xref" href="AnthropicClient.Models.DocumentContent.html">DocumentContent</a></div>
|
||||
<div><a class="xref" href="AnthropicClient.Models.ImageContent.html">ImageContent</a></div>
|
||||
<div><a class="xref" href="AnthropicClient.Models.TextContent.html">TextContent</a></div>
|
||||
<div><a class="xref" href="AnthropicClient.Models.ToolResultContent.html">ToolResultContent</a></div>
|
||||
|
||||
@@ -154,6 +154,37 @@ Class ContentType <a class="header-action link-secondary" title="View source" h
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_ContentType_Document" data-uid="AnthropicClient.Models.ContentType.Document">
|
||||
Document
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/ContentType.cs/#L31"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Represents the document content type.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public const string Document = "document"</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Field Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="AnthropicClient_Models_ContentType_Image" data-uid="AnthropicClient.Models.ContentType.Image">
|
||||
Image
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/ContentType.cs/#L16"><i class="bi bi-code-slash"></i></a>
|
||||
|
||||
@@ -0,0 +1,401 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Class CountMessageTokensRequest | AnthropicClient </title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="title" content="Class CountMessageTokensRequest | AnthropicClient ">
|
||||
|
||||
<meta name="description" content="Represents a request to count the number of tokens in a message.">
|
||||
<link rel="icon" href="../favicon.ico">
|
||||
<link rel="stylesheet" href="../public/docfx.min.css">
|
||||
<link rel="stylesheet" href="../public/main.css">
|
||||
<meta name="docfx:navrel" content="../toc.html">
|
||||
<meta name="docfx:tocrel" content="toc.html">
|
||||
|
||||
<meta name="docfx:rel" content="../">
|
||||
|
||||
|
||||
<meta name="docfx:docurl" content="https://github.com/StevanFreeborn/anthropic-client/new/main/apiSpec/new?filename=AnthropicClient_Models_CountMessageTokensRequest.md&value=---%0Auid%3A%20AnthropicClient.Models.CountMessageTokensRequest%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">
|
||||
<meta name="loc:inThisArticle" content="In this article">
|
||||
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
||||
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
||||
<meta name="loc:tocFilter" content="Filter by title">
|
||||
<meta name="loc:nextArticle" content="Next">
|
||||
<meta name="loc:prevArticle" content="Previous">
|
||||
<meta name="loc:themeLight" content="Light">
|
||||
<meta name="loc:themeDark" content="Dark">
|
||||
<meta name="loc:themeAuto" content="Auto">
|
||||
<meta name="loc:changeTheme" content="Change theme">
|
||||
<meta name="loc:copy" content="Copy">
|
||||
<meta name="loc:downloadPdf" content="Download PDF">
|
||||
|
||||
<script type="module" src="./../public/docfx.min.js"></script>
|
||||
|
||||
<script>
|
||||
const theme = localStorage.getItem('theme') || 'auto'
|
||||
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
|
||||
<header class="bg-body border-bottom">
|
||||
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
||||
<div class="container-xxl flex-nowrap">
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
<img id="logo" class="svg" src="../logo.svg" alt="AnthropicClient">
|
||||
AnthropicClient
|
||||
</a>
|
||||
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<i class="bi bi-three-dots"></i>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navpanel">
|
||||
<div id="navbar">
|
||||
<form class="search" role="search" id="search">
|
||||
<i class="bi bi-search"></i>
|
||||
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main class="container-xxl">
|
||||
<div class="toc-offcanvas">
|
||||
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
||||
<div class="offcanvas-header">
|
||||
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="offcanvas-body">
|
||||
<nav class="toc" id="toc"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="actionbar">
|
||||
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
||||
<i class="bi bi-list"></i>
|
||||
</button>
|
||||
|
||||
<nav id="breadcrumb"></nav>
|
||||
</div>
|
||||
|
||||
<article data-uid="AnthropicClient.Models.CountMessageTokensRequest">
|
||||
|
||||
|
||||
|
||||
<h1 id="AnthropicClient_Models_CountMessageTokensRequest" data-uid="AnthropicClient.Models.CountMessageTokensRequest" class="text-break">
|
||||
Class CountMessageTokensRequest <a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/CountMessageTokensRequest.cs/#L10"><i class="bi bi-code-slash"></i></a>
|
||||
</h1>
|
||||
|
||||
<div class="facts text-secondary">
|
||||
<dl><dt>Namespace</dt><dd><a class="xref" href="AnthropicClient.html">AnthropicClient</a>.<a class="xref" href="AnthropicClient.Models.html">Models</a></dd></dl>
|
||||
<dl><dt>Assembly</dt><dd>AnthropicClient.dll</dd></dl>
|
||||
</div>
|
||||
|
||||
<div class="markdown summary"><p>Represents a request to count the number of tokens in a message.</p>
|
||||
</div>
|
||||
<div class="markdown conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public class CountMessageTokensRequest</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="typelist inheritance">
|
||||
<dt>Inheritance</dt>
|
||||
<dd>
|
||||
<div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
|
||||
<div><span class="xref">CountMessageTokensRequest</span></div>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
<dl class="typelist inheritedMembers">
|
||||
<dt>Inherited Members</dt>
|
||||
<dd>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 class="section" id="constructors">Constructors
|
||||
</h2>
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_CountMessageTokensRequest__ctor_" data-uid="AnthropicClient.Models.CountMessageTokensRequest.#ctor*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_CountMessageTokensRequest__ctor_System_String_System_Collections_Generic_List_AnthropicClient_Models_Message__AnthropicClient_Models_ToolChoice_System_Collections_Generic_List_AnthropicClient_Models_Tool__System_Collections_Generic_List_AnthropicClient_Models_TextContent__" data-uid="AnthropicClient.Models.CountMessageTokensRequest.#ctor(System.String,System.Collections.Generic.List{AnthropicClient.Models.Message},AnthropicClient.Models.ToolChoice,System.Collections.Generic.List{AnthropicClient.Models.Tool},System.Collections.Generic.List{AnthropicClient.Models.TextContent})">
|
||||
CountMessageTokensRequest(string, List<Message>, ToolChoice?, List<Tool>?, List<TextContent>?)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/CountMessageTokensRequest.cs/#L50"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="AnthropicClient.Models.CountMessageTokensRequest.html">CountMessageTokensRequest</a> class.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public CountMessageTokensRequest(string model, List<Message> messages, ToolChoice? toolChoice = null, List<Tool>? tools = null, List<TextContent>? systemPrompt = null)</code></pre>
|
||||
</div>
|
||||
|
||||
<h4 class="section">Parameters</h4>
|
||||
<dl class="parameters">
|
||||
<dt><code>model</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd><p>The model ID to use for the request.</p>
|
||||
</dd>
|
||||
<dt><code>messages</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a><<a class="xref" href="AnthropicClient.Models.Message.html">Message</a>></dt>
|
||||
<dd><p>The messages to count the number of tokens in.</p>
|
||||
</dd>
|
||||
<dt><code>toolChoice</code> <a class="xref" href="AnthropicClient.Models.ToolChoice.html">ToolChoice</a></dt>
|
||||
<dd><p>The tool choice mode to use for the request.</p>
|
||||
</dd>
|
||||
<dt><code>tools</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a><<a class="xref" href="AnthropicClient.Models.Tool.html">Tool</a>></dt>
|
||||
<dd><p>The tools to use for the request.</p>
|
||||
</dd>
|
||||
<dt><code>systemPrompt</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a><<a class="xref" href="AnthropicClient.Models.TextContent.html">TextContent</a>></dt>
|
||||
<dd><p>The system prompt to use for the request.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Exceptions</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentnullexception">ArgumentNullException</a></dt>
|
||||
<dd><p>Thrown when <code class="paramref">model</code> or <code class="paramref">messages</code> is null.</p>
|
||||
</dd>
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentexception">ArgumentException</a></dt>
|
||||
<dd><p>Thrown when <code class="paramref">messages</code> is empty.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
<h2 class="section" id="properties">Properties
|
||||
</h2>
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_CountMessageTokensRequest_Messages_" data-uid="AnthropicClient.Models.CountMessageTokensRequest.Messages*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_CountMessageTokensRequest_Messages" data-uid="AnthropicClient.Models.CountMessageTokensRequest.Messages">
|
||||
Messages
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/CountMessageTokensRequest.cs/#L20"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Gets the messages to count the number of tokens in.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public List<Message> Messages { get; init; }</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Property Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a><<a class="xref" href="AnthropicClient.Models.Message.html">Message</a>></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_CountMessageTokensRequest_Model_" data-uid="AnthropicClient.Models.CountMessageTokensRequest.Model*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_CountMessageTokensRequest_Model" data-uid="AnthropicClient.Models.CountMessageTokensRequest.Model">
|
||||
Model
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/CountMessageTokensRequest.cs/#L15"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Gets the model ID to be used for the request.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public string Model { get; init; }</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Property Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_CountMessageTokensRequest_SystemPrompt_" data-uid="AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_CountMessageTokensRequest_SystemPrompt" data-uid="AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt">
|
||||
SystemPrompt
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/CountMessageTokensRequest.cs/#L36"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Gets the system prompt to use for the request.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">[JsonPropertyName("system")]
|
||||
public List<TextContent>? SystemPrompt { get; init; }</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Property Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a><<a class="xref" href="AnthropicClient.Models.TextContent.html">TextContent</a>></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_CountMessageTokensRequest_ToolChoice_" data-uid="AnthropicClient.Models.CountMessageTokensRequest.ToolChoice*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_CountMessageTokensRequest_ToolChoice" data-uid="AnthropicClient.Models.CountMessageTokensRequest.ToolChoice">
|
||||
ToolChoice
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/CountMessageTokensRequest.cs/#L25"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Gets the tool choice mode to use for the request.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">[JsonPropertyName("tool_choice")]
|
||||
public ToolChoice? ToolChoice { get; init; }</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Property Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="AnthropicClient.Models.ToolChoice.html">ToolChoice</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_CountMessageTokensRequest_Tools_" data-uid="AnthropicClient.Models.CountMessageTokensRequest.Tools*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_CountMessageTokensRequest_Tools" data-uid="AnthropicClient.Models.CountMessageTokensRequest.Tools">
|
||||
Tools
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/CountMessageTokensRequest.cs/#L31"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Gets the tools to use for the request.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public List<Tool>? Tools { get; init; }</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Property Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a><<a class="xref" href="AnthropicClient.Models.Tool.html">Tool</a>></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
<div class="contribution d-print-none">
|
||||
<a href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/CountMessageTokensRequest.cs/#L10" class="edit-link">Edit this page</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="affix">
|
||||
<nav id="affix"></nav>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<div class="container-xxl search-results" id="search-results"></div>
|
||||
|
||||
<footer class="border-top text-secondary">
|
||||
<div class="container-xxl">
|
||||
<div class="flex-fill">
|
||||
<span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,311 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Class DocumentContent | AnthropicClient </title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="title" content="Class DocumentContent | AnthropicClient ">
|
||||
|
||||
<meta name="description" content="Represents content from a document that is part of a message.">
|
||||
<link rel="icon" href="../favicon.ico">
|
||||
<link rel="stylesheet" href="../public/docfx.min.css">
|
||||
<link rel="stylesheet" href="../public/main.css">
|
||||
<meta name="docfx:navrel" content="../toc.html">
|
||||
<meta name="docfx:tocrel" content="toc.html">
|
||||
|
||||
<meta name="docfx:rel" content="../">
|
||||
|
||||
|
||||
<meta name="docfx:docurl" content="https://github.com/StevanFreeborn/anthropic-client/new/main/apiSpec/new?filename=AnthropicClient_Models_DocumentContent.md&value=---%0Auid%3A%20AnthropicClient.Models.DocumentContent%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">
|
||||
<meta name="loc:inThisArticle" content="In this article">
|
||||
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
||||
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
||||
<meta name="loc:tocFilter" content="Filter by title">
|
||||
<meta name="loc:nextArticle" content="Next">
|
||||
<meta name="loc:prevArticle" content="Previous">
|
||||
<meta name="loc:themeLight" content="Light">
|
||||
<meta name="loc:themeDark" content="Dark">
|
||||
<meta name="loc:themeAuto" content="Auto">
|
||||
<meta name="loc:changeTheme" content="Change theme">
|
||||
<meta name="loc:copy" content="Copy">
|
||||
<meta name="loc:downloadPdf" content="Download PDF">
|
||||
|
||||
<script type="module" src="./../public/docfx.min.js"></script>
|
||||
|
||||
<script>
|
||||
const theme = localStorage.getItem('theme') || 'auto'
|
||||
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
|
||||
<header class="bg-body border-bottom">
|
||||
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
||||
<div class="container-xxl flex-nowrap">
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
<img id="logo" class="svg" src="../logo.svg" alt="AnthropicClient">
|
||||
AnthropicClient
|
||||
</a>
|
||||
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<i class="bi bi-three-dots"></i>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navpanel">
|
||||
<div id="navbar">
|
||||
<form class="search" role="search" id="search">
|
||||
<i class="bi bi-search"></i>
|
||||
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main class="container-xxl">
|
||||
<div class="toc-offcanvas">
|
||||
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
||||
<div class="offcanvas-header">
|
||||
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="offcanvas-body">
|
||||
<nav class="toc" id="toc"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="actionbar">
|
||||
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
||||
<i class="bi bi-list"></i>
|
||||
</button>
|
||||
|
||||
<nav id="breadcrumb"></nav>
|
||||
</div>
|
||||
|
||||
<article data-uid="AnthropicClient.Models.DocumentContent">
|
||||
|
||||
|
||||
|
||||
<h1 id="AnthropicClient_Models_DocumentContent" data-uid="AnthropicClient.Models.DocumentContent" class="text-break">
|
||||
Class DocumentContent <a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentContent.cs/#L10"><i class="bi bi-code-slash"></i></a>
|
||||
</h1>
|
||||
|
||||
<div class="facts text-secondary">
|
||||
<dl><dt>Namespace</dt><dd><a class="xref" href="AnthropicClient.html">AnthropicClient</a>.<a class="xref" href="AnthropicClient.Models.html">Models</a></dd></dl>
|
||||
<dl><dt>Assembly</dt><dd>AnthropicClient.dll</dd></dl>
|
||||
</div>
|
||||
|
||||
<div class="markdown summary"><p>Represents content from a document that is part of a message.</p>
|
||||
</div>
|
||||
<div class="markdown conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public class DocumentContent : Content</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="typelist inheritance">
|
||||
<dt>Inheritance</dt>
|
||||
<dd>
|
||||
<div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
|
||||
<div><a class="xref" href="AnthropicClient.Models.Content.html">Content</a></div>
|
||||
<div><span class="xref">DocumentContent</span></div>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
<dl class="typelist inheritedMembers">
|
||||
<dt>Inherited Members</dt>
|
||||
<dd>
|
||||
<div>
|
||||
<a class="xref" href="AnthropicClient.Models.Content.html#AnthropicClient_Models_Content_Type">Content.Type</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="AnthropicClient.Models.Content.html#AnthropicClient_Models_Content_CacheControl">Content.CacheControl</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 class="section" id="constructors">Constructors
|
||||
</h2>
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_DocumentContent__ctor_" data-uid="AnthropicClient.Models.DocumentContent.#ctor*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_DocumentContent__ctor_System_String_System_String_" data-uid="AnthropicClient.Models.DocumentContent.#ctor(System.String,System.String)">
|
||||
DocumentContent(string, string)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentContent.cs/#L35"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="AnthropicClient.Models.DocumentContent.html">DocumentContent</a> class.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public DocumentContent(string mediaType, string data)</code></pre>
|
||||
</div>
|
||||
|
||||
<h4 class="section">Parameters</h4>
|
||||
<dl class="parameters">
|
||||
<dt><code>mediaType</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd><p>The media type of the document.</p>
|
||||
</dd>
|
||||
<dt><code>data</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd><p>The data of the document.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Exceptions</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentnullexception">ArgumentNullException</a></dt>
|
||||
<dd><p>Thrown when the media type or data is null.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_DocumentContent__ctor_" data-uid="AnthropicClient.Models.DocumentContent.#ctor*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_DocumentContent__ctor_System_String_System_String_AnthropicClient_Models_CacheControl_" data-uid="AnthropicClient.Models.DocumentContent.#ctor(System.String,System.String,AnthropicClient.Models.CacheControl)">
|
||||
DocumentContent(string, string, CacheControl)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentContent.cs/#L50"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="AnthropicClient.Models.DocumentContent.html">DocumentContent</a> class.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public DocumentContent(string mediaType, string data, CacheControl cacheControl)</code></pre>
|
||||
</div>
|
||||
|
||||
<h4 class="section">Parameters</h4>
|
||||
<dl class="parameters">
|
||||
<dt><code>mediaType</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd><p>The media type of the document.</p>
|
||||
</dd>
|
||||
<dt><code>data</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd><p>The data of the document.</p>
|
||||
</dd>
|
||||
<dt><code>cacheControl</code> <a class="xref" href="AnthropicClient.Models.CacheControl.html">CacheControl</a></dt>
|
||||
<dd><p>The cache control to be used for the content.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Exceptions</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentnullexception">ArgumentNullException</a></dt>
|
||||
<dd><p>Thrown when the media type, data, or cache control is null.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
<h2 class="section" id="properties">Properties
|
||||
</h2>
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_DocumentContent_Source_" data-uid="AnthropicClient.Models.DocumentContent.Source*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_DocumentContent_Source" data-uid="AnthropicClient.Models.DocumentContent.Source">
|
||||
Source
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentContent.cs/#L15"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Gets the source of the document.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public DocumentSource Source { get; init; }</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Property Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="AnthropicClient.Models.DocumentSource.html">DocumentSource</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
<div class="contribution d-print-none">
|
||||
<a href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentContent.cs/#L10" class="edit-link">Edit this page</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="affix">
|
||||
<nav id="affix"></nav>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<div class="container-xxl search-results" id="search-results"></div>
|
||||
|
||||
<footer class="border-top text-secondary">
|
||||
<div class="container-xxl">
|
||||
<div class="flex-fill">
|
||||
<span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,327 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Class DocumentSource | AnthropicClient </title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="title" content="Class DocumentSource | AnthropicClient ">
|
||||
|
||||
<meta name="description" content="Represents a document source.">
|
||||
<link rel="icon" href="../favicon.ico">
|
||||
<link rel="stylesheet" href="../public/docfx.min.css">
|
||||
<link rel="stylesheet" href="../public/main.css">
|
||||
<meta name="docfx:navrel" content="../toc.html">
|
||||
<meta name="docfx:tocrel" content="toc.html">
|
||||
|
||||
<meta name="docfx:rel" content="../">
|
||||
|
||||
|
||||
<meta name="docfx:docurl" content="https://github.com/StevanFreeborn/anthropic-client/new/main/apiSpec/new?filename=AnthropicClient_Models_DocumentSource.md&value=---%0Auid%3A%20AnthropicClient.Models.DocumentSource%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">
|
||||
<meta name="loc:inThisArticle" content="In this article">
|
||||
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
||||
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
||||
<meta name="loc:tocFilter" content="Filter by title">
|
||||
<meta name="loc:nextArticle" content="Next">
|
||||
<meta name="loc:prevArticle" content="Previous">
|
||||
<meta name="loc:themeLight" content="Light">
|
||||
<meta name="loc:themeDark" content="Dark">
|
||||
<meta name="loc:themeAuto" content="Auto">
|
||||
<meta name="loc:changeTheme" content="Change theme">
|
||||
<meta name="loc:copy" content="Copy">
|
||||
<meta name="loc:downloadPdf" content="Download PDF">
|
||||
|
||||
<script type="module" src="./../public/docfx.min.js"></script>
|
||||
|
||||
<script>
|
||||
const theme = localStorage.getItem('theme') || 'auto'
|
||||
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
|
||||
<header class="bg-body border-bottom">
|
||||
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
||||
<div class="container-xxl flex-nowrap">
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
<img id="logo" class="svg" src="../logo.svg" alt="AnthropicClient">
|
||||
AnthropicClient
|
||||
</a>
|
||||
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<i class="bi bi-three-dots"></i>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navpanel">
|
||||
<div id="navbar">
|
||||
<form class="search" role="search" id="search">
|
||||
<i class="bi bi-search"></i>
|
||||
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main class="container-xxl">
|
||||
<div class="toc-offcanvas">
|
||||
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
||||
<div class="offcanvas-header">
|
||||
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="offcanvas-body">
|
||||
<nav class="toc" id="toc"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="actionbar">
|
||||
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
||||
<i class="bi bi-list"></i>
|
||||
</button>
|
||||
|
||||
<nav id="breadcrumb"></nav>
|
||||
</div>
|
||||
|
||||
<article data-uid="AnthropicClient.Models.DocumentSource">
|
||||
|
||||
|
||||
|
||||
<h1 id="AnthropicClient_Models_DocumentSource" data-uid="AnthropicClient.Models.DocumentSource" class="text-break">
|
||||
Class DocumentSource <a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentSource.cs/#L10"><i class="bi bi-code-slash"></i></a>
|
||||
</h1>
|
||||
|
||||
<div class="facts text-secondary">
|
||||
<dl><dt>Namespace</dt><dd><a class="xref" href="AnthropicClient.html">AnthropicClient</a>.<a class="xref" href="AnthropicClient.Models.html">Models</a></dd></dl>
|
||||
<dl><dt>Assembly</dt><dd>AnthropicClient.dll</dd></dl>
|
||||
</div>
|
||||
|
||||
<div class="markdown summary"><p>Represents a document source.</p>
|
||||
</div>
|
||||
<div class="markdown conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public class DocumentSource</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="typelist inheritance">
|
||||
<dt>Inheritance</dt>
|
||||
<dd>
|
||||
<div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
|
||||
<div><span class="xref">DocumentSource</span></div>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
<dl class="typelist inheritedMembers">
|
||||
<dt>Inherited Members</dt>
|
||||
<dd>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 class="section" id="constructors">Constructors
|
||||
</h2>
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_DocumentSource__ctor_" data-uid="AnthropicClient.Models.DocumentSource.#ctor*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_DocumentSource__ctor_System_String_System_String_" data-uid="AnthropicClient.Models.DocumentSource.#ctor(System.String,System.String)">
|
||||
DocumentSource(string, string)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentSource.cs/#L41"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="AnthropicClient.Models.DocumentSource.html">DocumentSource</a> class.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public DocumentSource(string mediaType, string data)</code></pre>
|
||||
</div>
|
||||
|
||||
<h4 class="section">Parameters</h4>
|
||||
<dl class="parameters">
|
||||
<dt><code>mediaType</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd><p>The media type of the document.</p>
|
||||
</dd>
|
||||
<dt><code>data</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd><p>The data of the document.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Exceptions</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentexception">ArgumentException</a></dt>
|
||||
<dd><p>Thrown when the media type is invalid.</p>
|
||||
</dd>
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentnullexception">ArgumentNullException</a></dt>
|
||||
<dd><p>Thrown when the media type or data is null.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
<h2 class="section" id="properties">Properties
|
||||
</h2>
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_DocumentSource_Data_" data-uid="AnthropicClient.Models.DocumentSource.Data*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_DocumentSource_Data" data-uid="AnthropicClient.Models.DocumentSource.Data">
|
||||
Data
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentSource.cs/#L21"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Gets the data of the document.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public string Data { get; init; }</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Property Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_DocumentSource_MediaType_" data-uid="AnthropicClient.Models.DocumentSource.MediaType*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_DocumentSource_MediaType" data-uid="AnthropicClient.Models.DocumentSource.MediaType">
|
||||
MediaType
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentSource.cs/#L15"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Gets the media type of the document.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">[JsonPropertyName("media_type")]
|
||||
public string MediaType { get; init; }</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Property Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_DocumentSource_Type_" data-uid="AnthropicClient.Models.DocumentSource.Type*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_DocumentSource_Type" data-uid="AnthropicClient.Models.DocumentSource.Type">
|
||||
Type
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentSource.cs/#L26"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Gets the type of encoding of the document data.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public string Type { get; init; }</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Property Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
<div class="contribution d-print-none">
|
||||
<a href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/DocumentSource.cs/#L10" class="edit-link">Edit this page</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="affix">
|
||||
<nav id="affix"></nav>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<div class="container-xxl search-results" id="search-results"></div>
|
||||
|
||||
<footer class="border-top text-secondary">
|
||||
<div class="container-xxl">
|
||||
<div class="flex-fill">
|
||||
<span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -200,7 +200,7 @@ Class MessageRequest <a class="header-action link-secondary" title="View source
|
||||
|
||||
<h3 id="AnthropicClient_Models_MessageRequest__ctor_System_String_System_Collections_Generic_List_AnthropicClient_Models_Message__System_Int32_System_String_System_Collections_Generic_Dictionary_System_String_System_Object__System_Decimal_System_Nullable_System_Int32__System_Nullable_System_Decimal__AnthropicClient_Models_ToolChoice_System_Collections_Generic_List_AnthropicClient_Models_Tool__System_Collections_Generic_List_System_String__System_Collections_Generic_List_AnthropicClient_Models_TextContent__" data-uid="AnthropicClient.Models.MessageRequest.#ctor(System.String,System.Collections.Generic.List{AnthropicClient.Models.Message},System.Int32,System.String,System.Collections.Generic.Dictionary{System.String,System.Object},System.Decimal,System.Nullable{System.Int32},System.Nullable{System.Decimal},AnthropicClient.Models.ToolChoice,System.Collections.Generic.List{AnthropicClient.Models.Tool},System.Collections.Generic.List{System.String},System.Collections.Generic.List{AnthropicClient.Models.TextContent})">
|
||||
MessageRequest(string, List<Message>, int, string?, Dictionary<string, object>?, decimal, int?, decimal?, ToolChoice?, List<Tool>?, List<string>?, List<TextContent>?)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/MessageRequest.cs/#L34"><i class="bi bi-code-slash"></i></a>
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/MessageRequest.cs/#L33"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="AnthropicClient.Models.MessageRequest.html">MessageRequest</a> class.</p>
|
||||
@@ -261,9 +261,6 @@ Class MessageRequest <a class="header-action link-secondary" title="View source
|
||||
|
||||
<h4 class="section">Exceptions</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentexception">ArgumentException</a></dt>
|
||||
<dd><p>Thrown when the model ID is invalid.</p>
|
||||
</dd>
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentnullexception">ArgumentNullException</a></dt>
|
||||
<dd><p>Thrown when the model or messages is null.</p>
|
||||
</dd>
|
||||
|
||||
@@ -200,7 +200,7 @@ Class StreamMessageRequest <a class="header-action link-secondary" title="View
|
||||
|
||||
<h3 id="AnthropicClient_Models_StreamMessageRequest__ctor_System_String_System_Collections_Generic_List_AnthropicClient_Models_Message__System_Int32_System_String_System_Collections_Generic_Dictionary_System_String_System_Object__System_Decimal_System_Nullable_System_Int32__System_Nullable_System_Decimal__AnthropicClient_Models_ToolChoice_System_Collections_Generic_List_AnthropicClient_Models_Tool__System_Collections_Generic_List_System_String__System_Collections_Generic_List_AnthropicClient_Models_TextContent__" data-uid="AnthropicClient.Models.StreamMessageRequest.#ctor(System.String,System.Collections.Generic.List{AnthropicClient.Models.Message},System.Int32,System.String,System.Collections.Generic.Dictionary{System.String,System.Object},System.Decimal,System.Nullable{System.Int32},System.Nullable{System.Decimal},AnthropicClient.Models.ToolChoice,System.Collections.Generic.List{AnthropicClient.Models.Tool},System.Collections.Generic.List{System.String},System.Collections.Generic.List{AnthropicClient.Models.TextContent})">
|
||||
StreamMessageRequest(string, List<Message>, int, string?, Dictionary<string, object>?, decimal, int?, decimal?, ToolChoice?, List<Tool>?, List<string>?, List<TextContent>?)
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/StreamMessageRequest.cs/#L34"><i class="bi bi-code-slash"></i></a>
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/StreamMessageRequest.cs/#L33"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="AnthropicClient.Models.StreamMessageRequest.html">StreamMessageRequest</a> class.</p>
|
||||
@@ -261,9 +261,6 @@ Class StreamMessageRequest <a class="header-action link-secondary" title="View
|
||||
|
||||
<h4 class="section">Exceptions</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentexception">ArgumentException</a></dt>
|
||||
<dd><p>Thrown when the model ID is invalid.</p>
|
||||
</dd>
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentnullexception">ArgumentNullException</a></dt>
|
||||
<dd><p>Thrown when the model or messages is null.</p>
|
||||
</dd>
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Class TokenCountResponse | AnthropicClient </title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="title" content="Class TokenCountResponse | AnthropicClient ">
|
||||
|
||||
<meta name="description" content="Represents a response to a token count request.">
|
||||
<link rel="icon" href="../favicon.ico">
|
||||
<link rel="stylesheet" href="../public/docfx.min.css">
|
||||
<link rel="stylesheet" href="../public/main.css">
|
||||
<meta name="docfx:navrel" content="../toc.html">
|
||||
<meta name="docfx:tocrel" content="toc.html">
|
||||
|
||||
<meta name="docfx:rel" content="../">
|
||||
|
||||
|
||||
<meta name="docfx:docurl" content="https://github.com/StevanFreeborn/anthropic-client/new/main/apiSpec/new?filename=AnthropicClient_Models_TokenCountResponse.md&value=---%0Auid%3A%20AnthropicClient.Models.TokenCountResponse%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">
|
||||
<meta name="loc:inThisArticle" content="In this article">
|
||||
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
||||
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
||||
<meta name="loc:tocFilter" content="Filter by title">
|
||||
<meta name="loc:nextArticle" content="Next">
|
||||
<meta name="loc:prevArticle" content="Previous">
|
||||
<meta name="loc:themeLight" content="Light">
|
||||
<meta name="loc:themeDark" content="Dark">
|
||||
<meta name="loc:themeAuto" content="Auto">
|
||||
<meta name="loc:changeTheme" content="Change theme">
|
||||
<meta name="loc:copy" content="Copy">
|
||||
<meta name="loc:downloadPdf" content="Download PDF">
|
||||
|
||||
<script type="module" src="./../public/docfx.min.js"></script>
|
||||
|
||||
<script>
|
||||
const theme = localStorage.getItem('theme') || 'auto'
|
||||
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
|
||||
<header class="bg-body border-bottom">
|
||||
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
||||
<div class="container-xxl flex-nowrap">
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
<img id="logo" class="svg" src="../logo.svg" alt="AnthropicClient">
|
||||
AnthropicClient
|
||||
</a>
|
||||
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<i class="bi bi-three-dots"></i>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navpanel">
|
||||
<div id="navbar">
|
||||
<form class="search" role="search" id="search">
|
||||
<i class="bi bi-search"></i>
|
||||
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main class="container-xxl">
|
||||
<div class="toc-offcanvas">
|
||||
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
||||
<div class="offcanvas-header">
|
||||
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="offcanvas-body">
|
||||
<nav class="toc" id="toc"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="actionbar">
|
||||
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
||||
<i class="bi bi-list"></i>
|
||||
</button>
|
||||
|
||||
<nav id="breadcrumb"></nav>
|
||||
</div>
|
||||
|
||||
<article data-uid="AnthropicClient.Models.TokenCountResponse">
|
||||
|
||||
|
||||
|
||||
<h1 id="AnthropicClient_Models_TokenCountResponse" data-uid="AnthropicClient.Models.TokenCountResponse" class="text-break">
|
||||
Class TokenCountResponse <a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/TokenCountResponse.cs/#L8"><i class="bi bi-code-slash"></i></a>
|
||||
</h1>
|
||||
|
||||
<div class="facts text-secondary">
|
||||
<dl><dt>Namespace</dt><dd><a class="xref" href="AnthropicClient.html">AnthropicClient</a>.<a class="xref" href="AnthropicClient.Models.html">Models</a></dd></dl>
|
||||
<dl><dt>Assembly</dt><dd>AnthropicClient.dll</dd></dl>
|
||||
</div>
|
||||
|
||||
<div class="markdown summary"><p>Represents a response to a token count request.</p>
|
||||
</div>
|
||||
<div class="markdown conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public class TokenCountResponse</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="typelist inheritance">
|
||||
<dt>Inheritance</dt>
|
||||
<dd>
|
||||
<div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
|
||||
<div><span class="xref">TokenCountResponse</span></div>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
<dl class="typelist inheritedMembers">
|
||||
<dt>Inherited Members</dt>
|
||||
<dd>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 class="section" id="properties">Properties
|
||||
</h2>
|
||||
|
||||
|
||||
<a id="AnthropicClient_Models_TokenCountResponse_InputTokens_" data-uid="AnthropicClient.Models.TokenCountResponse.InputTokens*"></a>
|
||||
|
||||
<h3 id="AnthropicClient_Models_TokenCountResponse_InputTokens" data-uid="AnthropicClient.Models.TokenCountResponse.InputTokens">
|
||||
InputTokens
|
||||
<a class="header-action link-secondary" title="View source" href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/TokenCountResponse.cs/#L13"><i class="bi bi-code-slash"></i></a>
|
||||
</h3>
|
||||
|
||||
<div class="markdown level1 summary"><p>The number of input tokens counted.</p>
|
||||
</div>
|
||||
<div class="markdown level1 conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">[JsonPropertyName("input_tokens")]
|
||||
public int InputTokens { get; init; }</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="section">Property Value</h4>
|
||||
<dl class="parameters">
|
||||
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
<div class="contribution d-print-none">
|
||||
<a href="https://github.com/StevanFreeborn/anthropic-client/blob/main/src/AnthropicClient/Models/TokenCountResponse.cs/#L8" class="edit-link">Edit this page</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="affix">
|
||||
<nav id="affix"></nav>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<div class="container-xxl search-results" id="search-results"></div>
|
||||
|
||||
<footer class="border-top text-secondary">
|
||||
<div class="container-xxl">
|
||||
<div class="flex-fill">
|
||||
<span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -187,6 +187,21 @@ Classes
|
||||
<dl class="jumplist">
|
||||
<dt><a class="xref" href="AnthropicClient.Models.ContentType.html">ContentType</a></dt>
|
||||
<dd><p>Represents the content type.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="jumplist">
|
||||
<dt><a class="xref" href="AnthropicClient.Models.CountMessageTokensRequest.html">CountMessageTokensRequest</a></dt>
|
||||
<dd><p>Represents a request to count the number of tokens in a message.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="jumplist">
|
||||
<dt><a class="xref" href="AnthropicClient.Models.DocumentContent.html">DocumentContent</a></dt>
|
||||
<dd><p>Represents content from a document that is part of a message.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="jumplist">
|
||||
<dt><a class="xref" href="AnthropicClient.Models.DocumentSource.html">DocumentSource</a></dt>
|
||||
<dd><p>Represents a document source.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="jumplist">
|
||||
@@ -357,6 +372,11 @@ Classes
|
||||
<dl class="jumplist">
|
||||
<dt><a class="xref" href="AnthropicClient.Models.TextDelta.html">TextDelta</a></dt>
|
||||
<dd><p>Represents a text delta.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="jumplist">
|
||||
<dt><a class="xref" href="AnthropicClient.Models.TokenCountResponse.html">TokenCountResponse</a></dt>
|
||||
<dd><p>Represents a response to a token count request.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="jumplist">
|
||||
|
||||
@@ -87,6 +87,15 @@
|
||||
<li>
|
||||
<a href="AnthropicClient.Models.ContentType.html" name="" title="ContentType">ContentType</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="AnthropicClient.Models.CountMessageTokensRequest.html" name="" title="CountMessageTokensRequest">CountMessageTokensRequest</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="AnthropicClient.Models.DocumentContent.html" name="" title="DocumentContent">DocumentContent</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="AnthropicClient.Models.DocumentSource.html" name="" title="DocumentSource">DocumentSource</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="AnthropicClient.Models.EphemeralCacheControl.html" name="" title="EphemeralCacheControl">EphemeralCacheControl</a>
|
||||
</li>
|
||||
@@ -192,6 +201,9 @@
|
||||
<li>
|
||||
<a href="AnthropicClient.Models.TextDelta.html" name="" title="TextDelta">TextDelta</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="AnthropicClient.Models.TokenCountResponse.html" name="" title="TokenCountResponse">TokenCountResponse</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="AnthropicClient.Models.Tool.html" name="" title="Tool">Tool</a>
|
||||
</li>
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+63
-15
@@ -146,8 +146,33 @@ var client = new AnthropicApiClient(apiKey, new HttpClient());
|
||||
<h5>Note</h5>
|
||||
<p>The following examples assume that you have already created an instance of the <code>AnthropicApiClient</code> class named <code>client</code>. You can also find these snippets in the examples directory.</p>
|
||||
</div>
|
||||
<h3 id="count-message-tokens">Count Message Tokens</h3>
|
||||
<p>The <code>AnthropicApiClient</code> exposes a method named <code>CountMessageTokensAsync</code> that can be used to count the number of tokens in a message. The method requires a <code>CountMessageTokensRequest</code> instance as a parameter.</p>
|
||||
<pre><code class="lang-csharp">using AnthropicClient;
|
||||
using AnthropicClient.Models;
|
||||
|
||||
var response = await client.CountMessageTokensAsync(new CountMessageTokensRequest(
|
||||
AnthropicModels.Claude3Haiku,
|
||||
[
|
||||
new(
|
||||
MessageRole.User,
|
||||
[new TextContent("Please write a haiku about the ocean.")]
|
||||
)
|
||||
]
|
||||
));
|
||||
|
||||
if (response.IsFailure)
|
||||
{
|
||||
Console.WriteLine("Failed to count message tokens");
|
||||
Console.WriteLine("Error Type: {0}", response.Error.Error.Type);
|
||||
Console.WriteLine("Error Message: {0}", response.Error.Error.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Token Count: {0}", response.Value.InputTokens);
|
||||
</code></pre>
|
||||
<h3 id="create-a-message">Create a message</h3>
|
||||
<p>The <code>AnthropicApiClient</code> exposes a single method named <code>CreateMessageAsync</code> that can be used to create a message. The method requires a <code>MessageRequest</code> or a <code>StreamMessageRequest</code> instance as a parameter. The <code>MessageRequest</code> class is used to create a message whose response is not streamed and the <code>StreamMessageRequest</code> class is used to create a message whose response is streamed. The <code>MessageRequest</code> instance's properties can be set to configure how the message is created.</p>
|
||||
<p>The <code>AnthropicApiClient</code> exposes a method named <code>CreateMessageAsync</code> that can be used to create a message. The method requires a <code>MessageRequest</code> or a <code>StreamMessageRequest</code> instance as a parameter. The <code>MessageRequest</code> class is used to create a message whose response is not streamed and the <code>StreamMessageRequest</code> class is used to create a message whose response is streamed. The <code>MessageRequest</code> instance's properties can be set to configure how the message is created.</p>
|
||||
<h4 id="non-streaming">Non-Streaming</h4>
|
||||
<pre><code class="lang-csharp">using AnthropicClient;
|
||||
using AnthropicClient.Models;
|
||||
@@ -674,20 +699,7 @@ foreach (var content in response.Value.Content)
|
||||
}
|
||||
</code></pre>
|
||||
<h3 id="prompt-caching">Prompt Caching</h3>
|
||||
<p>Anthropic has recently introduced a feature called <a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching">Prompt Caching</a> 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 <a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching">Anthropic's API Documentation</a>.</p>
|
||||
<div class="NOTE">
|
||||
<h5>Note</h5>
|
||||
<p>This feature is in beta and requires you to set an <code>anthropic-beta</code> header on your requests to use it.
|
||||
The value of the header should be <code>prompt-caching-2024-07-31</code>.</p>
|
||||
</div>
|
||||
<p>When using this library you can opt-in to prompt caching by adding the required header to the <code>HttpClient</code> instance you provide to the <code>AnthropicApiClient</code> constructor.</p>
|
||||
<pre><code class="lang-csharp">using AnthropicClient;
|
||||
|
||||
var httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Add("anthropic-beta", "prompt-caching-2024-07-31");
|
||||
|
||||
var client = new AnthropicApiClient(apiKey, httpClient);
|
||||
</code></pre>
|
||||
<p>Anthropic provides a feature called <a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching">Prompt Caching</a> 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 <a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching">Anthropic's API Documentation</a>.</p>
|
||||
<p>Prompt caching can be used to cache all parts of the prompt including system messages, user messages, and tools. You should refer to the <a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching">Anthropic API Documentation</a> 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 - <code>EphemeralCacheControl</code>.</p>
|
||||
<h4 id="caching-system-messages">Caching System Messages</h4>
|
||||
<p>System messages can be cached by providing a <code>List<TextContent></code> as the <code>systemMessages</code> parameter in the <code>MessageRequest</code> or <code>StreamMessageRequest</code> constructor and having one or more of the <code>TextContent</code> instances have the <code>CacheControl</code> property set.</p>
|
||||
@@ -812,6 +824,42 @@ foreach (var content in response.Value.Content)
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h3 id="pdf-support">PDF Support</h3>
|
||||
<p>Anthropic provides a feature called <a href="https://docs.anthropic.com/en/docs/build-with-claude/pdf-support">PDF Support</a> that allows Claude to support PDF input and understand both text and visual content within documents. This feature is covered in depth in <a href="https://docs.anthropic.com/en/docs/build-with-claude/pdf-support">Anthropic's API Documentation</a>.</p>
|
||||
<p>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.</p>
|
||||
<h4 id="pdf-document">PDF Document</h4>
|
||||
<p>You can provide a PDF document by providing its base64 encoded content as a <code>DocumentContent</code> instance in the list of messages in the <code>MessageRequest</code> or <code>StreamMessageRequest</code> constructor.</p>
|
||||
<pre><code class="lang-csharp">using AnthropicClient;
|
||||
using AnthropicClient.Models;
|
||||
|
||||
var request = new MessageRequest(
|
||||
model: AnthropicModels.Claude35Sonnet,
|
||||
messages: [
|
||||
new(MessageRole.User, [new TextContent("What is the title of this paper?")]),
|
||||
new(MessageRole.User, [new DocumentContent("application/pdf", base64Data)])
|
||||
]
|
||||
);
|
||||
|
||||
var response = await client.CreateMessageAsync(request);
|
||||
|
||||
if (response.IsSuccess is false)
|
||||
{
|
||||
Console.WriteLine("Failed to create message");
|
||||
Console.WriteLine("Error Type: {0}", response.Error.Error.Type);
|
||||
Console.WriteLine("Error Message: {0}", response.Error.Error.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var content in response.Value.Content)
|
||||
{
|
||||
switch (content)
|
||||
{
|
||||
case TextContent textContent:
|
||||
Console.WriteLine(textContent.Text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
+30
-10
File diff suppressed because one or more lines are too long
+46
-6
@@ -220,6 +220,36 @@
|
||||
},
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "ManagedReference",
|
||||
"source_relative_path": "api/AnthropicClient.Models.CountMessageTokensRequest.yml",
|
||||
"output": {
|
||||
".html": {
|
||||
"relative_path": "api/AnthropicClient.Models.CountMessageTokensRequest.html"
|
||||
}
|
||||
},
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "ManagedReference",
|
||||
"source_relative_path": "api/AnthropicClient.Models.DocumentContent.yml",
|
||||
"output": {
|
||||
".html": {
|
||||
"relative_path": "api/AnthropicClient.Models.DocumentContent.html"
|
||||
}
|
||||
},
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "ManagedReference",
|
||||
"source_relative_path": "api/AnthropicClient.Models.DocumentSource.yml",
|
||||
"output": {
|
||||
".html": {
|
||||
"relative_path": "api/AnthropicClient.Models.DocumentSource.html"
|
||||
}
|
||||
},
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "ManagedReference",
|
||||
"source_relative_path": "api/AnthropicClient.Models.EphemeralCacheControl.yml",
|
||||
@@ -570,6 +600,16 @@
|
||||
},
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "ManagedReference",
|
||||
"source_relative_path": "api/AnthropicClient.Models.TokenCountResponse.yml",
|
||||
"output": {
|
||||
".html": {
|
||||
"relative_path": "api/AnthropicClient.Models.TokenCountResponse.html"
|
||||
}
|
||||
},
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "ManagedReference",
|
||||
"source_relative_path": "api/AnthropicClient.Models.Tool.yml",
|
||||
@@ -674,11 +714,11 @@
|
||||
"type": "Toc",
|
||||
"source_relative_path": "api/toc.yml",
|
||||
"output": {
|
||||
".json": {
|
||||
"relative_path": "api/toc.json"
|
||||
},
|
||||
".html": {
|
||||
"relative_path": "api/toc.html"
|
||||
},
|
||||
".json": {
|
||||
"relative_path": "api/toc.json"
|
||||
}
|
||||
},
|
||||
"version": ""
|
||||
@@ -697,11 +737,11 @@
|
||||
"type": "Toc",
|
||||
"source_relative_path": "toc.yml",
|
||||
"output": {
|
||||
".json": {
|
||||
"relative_path": "toc.json"
|
||||
},
|
||||
".html": {
|
||||
"relative_path": "toc.html"
|
||||
},
|
||||
".json": {
|
||||
"relative_path": "toc.json"
|
||||
}
|
||||
},
|
||||
"version": ""
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Vendored
+20
-20
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -32,6 +32,19 @@ references:
|
||||
fullName.vb: AnthropicClient.AnthropicApiClient.New
|
||||
nameWithType: AnthropicApiClient.AnthropicApiClient
|
||||
nameWithType.vb: AnthropicApiClient.New
|
||||
- uid: AnthropicClient.AnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest)
|
||||
name: CountMessageTokensAsync(CountMessageTokensRequest)
|
||||
href: api/AnthropicClient.AnthropicApiClient.html#AnthropicClient_AnthropicApiClient_CountMessageTokensAsync_AnthropicClient_Models_CountMessageTokensRequest_
|
||||
commentId: M:AnthropicClient.AnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest)
|
||||
fullName: AnthropicClient.AnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest)
|
||||
nameWithType: AnthropicApiClient.CountMessageTokensAsync(CountMessageTokensRequest)
|
||||
- uid: AnthropicClient.AnthropicApiClient.CountMessageTokensAsync*
|
||||
name: CountMessageTokensAsync
|
||||
href: api/AnthropicClient.AnthropicApiClient.html#AnthropicClient_AnthropicApiClient_CountMessageTokensAsync_
|
||||
commentId: Overload:AnthropicClient.AnthropicApiClient.CountMessageTokensAsync
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.AnthropicApiClient.CountMessageTokensAsync
|
||||
nameWithType: AnthropicApiClient.CountMessageTokensAsync
|
||||
- uid: AnthropicClient.AnthropicApiClient.CreateMessageAsync(AnthropicClient.Models.MessageRequest)
|
||||
name: CreateMessageAsync(MessageRequest)
|
||||
href: api/AnthropicClient.AnthropicApiClient.html#AnthropicClient_AnthropicApiClient_CreateMessageAsync_AnthropicClient_Models_MessageRequest_
|
||||
@@ -57,6 +70,19 @@ references:
|
||||
commentId: T:AnthropicClient.IAnthropicApiClient
|
||||
fullName: AnthropicClient.IAnthropicApiClient
|
||||
nameWithType: IAnthropicApiClient
|
||||
- uid: AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest)
|
||||
name: CountMessageTokensAsync(CountMessageTokensRequest)
|
||||
href: api/AnthropicClient.IAnthropicApiClient.html#AnthropicClient_IAnthropicApiClient_CountMessageTokensAsync_AnthropicClient_Models_CountMessageTokensRequest_
|
||||
commentId: M:AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest)
|
||||
fullName: AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest)
|
||||
nameWithType: IAnthropicApiClient.CountMessageTokensAsync(CountMessageTokensRequest)
|
||||
- uid: AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync*
|
||||
name: CountMessageTokensAsync
|
||||
href: api/AnthropicClient.IAnthropicApiClient.html#AnthropicClient_IAnthropicApiClient_CountMessageTokensAsync_
|
||||
commentId: Overload:AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync
|
||||
nameWithType: IAnthropicApiClient.CountMessageTokensAsync
|
||||
- uid: AnthropicClient.IAnthropicApiClient.CreateMessageAsync(AnthropicClient.Models.MessageRequest)
|
||||
name: CreateMessageAsync(MessageRequest)
|
||||
href: api/AnthropicClient.IAnthropicApiClient.html#AnthropicClient_IAnthropicApiClient_CreateMessageAsync_AnthropicClient_Models_MessageRequest_
|
||||
@@ -351,30 +377,84 @@ references:
|
||||
commentId: T:AnthropicClient.Models.AnthropicModels
|
||||
fullName: AnthropicClient.Models.AnthropicModels
|
||||
nameWithType: AnthropicModels
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude35Haiku20241022
|
||||
name: Claude35Haiku20241022
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude35Haiku20241022
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude35Haiku20241022
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude35Haiku20241022
|
||||
nameWithType: AnthropicModels.Claude35Haiku20241022
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude35HaikuLatest
|
||||
name: Claude35HaikuLatest
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude35HaikuLatest
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude35HaikuLatest
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude35HaikuLatest
|
||||
nameWithType: AnthropicModels.Claude35HaikuLatest
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude35Sonnet
|
||||
name: Claude35Sonnet
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude35Sonnet
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude35Sonnet
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude35Sonnet
|
||||
nameWithType: AnthropicModels.Claude35Sonnet
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude35Sonnet20240620
|
||||
name: Claude35Sonnet20240620
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude35Sonnet20240620
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude35Sonnet20240620
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude35Sonnet20240620
|
||||
nameWithType: AnthropicModels.Claude35Sonnet20240620
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude35Sonnet20241022
|
||||
name: Claude35Sonnet20241022
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude35Sonnet20241022
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude35Sonnet20241022
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude35Sonnet20241022
|
||||
nameWithType: AnthropicModels.Claude35Sonnet20241022
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude35SonnetLatest
|
||||
name: Claude35SonnetLatest
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude35SonnetLatest
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude35SonnetLatest
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude35SonnetLatest
|
||||
nameWithType: AnthropicModels.Claude35SonnetLatest
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude3Haiku
|
||||
name: Claude3Haiku
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude3Haiku
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude3Haiku
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude3Haiku
|
||||
nameWithType: AnthropicModels.Claude3Haiku
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude3Haiku20240307
|
||||
name: Claude3Haiku20240307
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude3Haiku20240307
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude3Haiku20240307
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude3Haiku20240307
|
||||
nameWithType: AnthropicModels.Claude3Haiku20240307
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude3Opus
|
||||
name: Claude3Opus
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude3Opus
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude3Opus
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude3Opus
|
||||
nameWithType: AnthropicModels.Claude3Opus
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude3Opus20241022
|
||||
name: Claude3Opus20241022
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude3Opus20241022
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude3Opus20241022
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude3Opus20241022
|
||||
nameWithType: AnthropicModels.Claude3Opus20241022
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude3OpusLatest
|
||||
name: Claude3OpusLatest
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude3OpusLatest
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude3OpusLatest
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude3OpusLatest
|
||||
nameWithType: AnthropicModels.Claude3OpusLatest
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude3Sonnet
|
||||
name: Claude3Sonnet
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude3Sonnet
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude3Sonnet
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude3Sonnet
|
||||
nameWithType: AnthropicModels.Claude3Sonnet
|
||||
- uid: AnthropicClient.Models.AnthropicModels.Claude3Sonnet20240229
|
||||
name: Claude3Sonnet20240229
|
||||
href: api/AnthropicClient.Models.AnthropicModels.html#AnthropicClient_Models_AnthropicModels_Claude3Sonnet20240229
|
||||
commentId: F:AnthropicClient.Models.AnthropicModels.Claude3Sonnet20240229
|
||||
fullName: AnthropicClient.Models.AnthropicModels.Claude3Sonnet20240229
|
||||
nameWithType: AnthropicModels.Claude3Sonnet20240229
|
||||
- uid: AnthropicClient.Models.AnyToolChoice
|
||||
name: AnyToolChoice
|
||||
href: api/AnthropicClient.Models.AnyToolChoice.html
|
||||
@@ -994,6 +1074,12 @@ references:
|
||||
commentId: T:AnthropicClient.Models.ContentType
|
||||
fullName: AnthropicClient.Models.ContentType
|
||||
nameWithType: ContentType
|
||||
- uid: AnthropicClient.Models.ContentType.Document
|
||||
name: Document
|
||||
href: api/AnthropicClient.Models.ContentType.html#AnthropicClient_Models_ContentType_Document
|
||||
commentId: F:AnthropicClient.Models.ContentType.Document
|
||||
fullName: AnthropicClient.Models.ContentType.Document
|
||||
nameWithType: ContentType.Document
|
||||
- uid: AnthropicClient.Models.ContentType.Image
|
||||
name: Image
|
||||
href: api/AnthropicClient.Models.ContentType.html#AnthropicClient_Models_ContentType_Image
|
||||
@@ -1018,6 +1104,207 @@ references:
|
||||
commentId: F:AnthropicClient.Models.ContentType.ToolUse
|
||||
fullName: AnthropicClient.Models.ContentType.ToolUse
|
||||
nameWithType: ContentType.ToolUse
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest
|
||||
name: CountMessageTokensRequest
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html
|
||||
commentId: T:AnthropicClient.Models.CountMessageTokensRequest
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest
|
||||
nameWithType: CountMessageTokensRequest
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.#ctor(System.String,System.Collections.Generic.List{AnthropicClient.Models.Message},AnthropicClient.Models.ToolChoice,System.Collections.Generic.List{AnthropicClient.Models.Tool},System.Collections.Generic.List{AnthropicClient.Models.TextContent})
|
||||
name: CountMessageTokensRequest(string, List<Message>, ToolChoice?, List<Tool>?, List<TextContent>?)
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest__ctor_System_String_System_Collections_Generic_List_AnthropicClient_Models_Message__AnthropicClient_Models_ToolChoice_System_Collections_Generic_List_AnthropicClient_Models_Tool__System_Collections_Generic_List_AnthropicClient_Models_TextContent__
|
||||
commentId: M:AnthropicClient.Models.CountMessageTokensRequest.#ctor(System.String,System.Collections.Generic.List{AnthropicClient.Models.Message},AnthropicClient.Models.ToolChoice,System.Collections.Generic.List{AnthropicClient.Models.Tool},System.Collections.Generic.List{AnthropicClient.Models.TextContent})
|
||||
name.vb: New(String, List(Of Message), ToolChoice, List(Of Tool), List(Of TextContent))
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.CountMessageTokensRequest(string, System.Collections.Generic.List<AnthropicClient.Models.Message>, AnthropicClient.Models.ToolChoice?, System.Collections.Generic.List<AnthropicClient.Models.Tool>?, System.Collections.Generic.List<AnthropicClient.Models.TextContent>?)
|
||||
fullName.vb: AnthropicClient.Models.CountMessageTokensRequest.New(String, System.Collections.Generic.List(Of AnthropicClient.Models.Message), AnthropicClient.Models.ToolChoice, System.Collections.Generic.List(Of AnthropicClient.Models.Tool), System.Collections.Generic.List(Of AnthropicClient.Models.TextContent))
|
||||
nameWithType: CountMessageTokensRequest.CountMessageTokensRequest(string, List<Message>, ToolChoice?, List<Tool>?, List<TextContent>?)
|
||||
nameWithType.vb: CountMessageTokensRequest.New(String, List(Of Message), ToolChoice, List(Of Tool), List(Of TextContent))
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.#ctor*
|
||||
name: CountMessageTokensRequest
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest__ctor_
|
||||
commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.#ctor
|
||||
isSpec: "True"
|
||||
name.vb: New
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.CountMessageTokensRequest
|
||||
fullName.vb: AnthropicClient.Models.CountMessageTokensRequest.New
|
||||
nameWithType: CountMessageTokensRequest.CountMessageTokensRequest
|
||||
nameWithType.vb: CountMessageTokensRequest.New
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.Messages
|
||||
name: Messages
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Messages
|
||||
commentId: P:AnthropicClient.Models.CountMessageTokensRequest.Messages
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.Messages
|
||||
nameWithType: CountMessageTokensRequest.Messages
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.Messages*
|
||||
name: Messages
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Messages_
|
||||
commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.Messages
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.Messages
|
||||
nameWithType: CountMessageTokensRequest.Messages
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.Model
|
||||
name: Model
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Model
|
||||
commentId: P:AnthropicClient.Models.CountMessageTokensRequest.Model
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.Model
|
||||
nameWithType: CountMessageTokensRequest.Model
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.Model*
|
||||
name: Model
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Model_
|
||||
commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.Model
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.Model
|
||||
nameWithType: CountMessageTokensRequest.Model
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt
|
||||
name: SystemPrompt
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_SystemPrompt
|
||||
commentId: P:AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt
|
||||
nameWithType: CountMessageTokensRequest.SystemPrompt
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt*
|
||||
name: SystemPrompt
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_SystemPrompt_
|
||||
commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt
|
||||
nameWithType: CountMessageTokensRequest.SystemPrompt
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.ToolChoice
|
||||
name: ToolChoice
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_ToolChoice
|
||||
commentId: P:AnthropicClient.Models.CountMessageTokensRequest.ToolChoice
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.ToolChoice
|
||||
nameWithType: CountMessageTokensRequest.ToolChoice
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.ToolChoice*
|
||||
name: ToolChoice
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_ToolChoice_
|
||||
commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.ToolChoice
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.ToolChoice
|
||||
nameWithType: CountMessageTokensRequest.ToolChoice
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.Tools
|
||||
name: Tools
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Tools
|
||||
commentId: P:AnthropicClient.Models.CountMessageTokensRequest.Tools
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.Tools
|
||||
nameWithType: CountMessageTokensRequest.Tools
|
||||
- uid: AnthropicClient.Models.CountMessageTokensRequest.Tools*
|
||||
name: Tools
|
||||
href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Tools_
|
||||
commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.Tools
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.CountMessageTokensRequest.Tools
|
||||
nameWithType: CountMessageTokensRequest.Tools
|
||||
- uid: AnthropicClient.Models.DocumentContent
|
||||
name: DocumentContent
|
||||
href: api/AnthropicClient.Models.DocumentContent.html
|
||||
commentId: T:AnthropicClient.Models.DocumentContent
|
||||
fullName: AnthropicClient.Models.DocumentContent
|
||||
nameWithType: DocumentContent
|
||||
- uid: AnthropicClient.Models.DocumentContent.#ctor(System.String,System.String)
|
||||
name: DocumentContent(string, string)
|
||||
href: api/AnthropicClient.Models.DocumentContent.html#AnthropicClient_Models_DocumentContent__ctor_System_String_System_String_
|
||||
commentId: M:AnthropicClient.Models.DocumentContent.#ctor(System.String,System.String)
|
||||
name.vb: New(String, String)
|
||||
fullName: AnthropicClient.Models.DocumentContent.DocumentContent(string, string)
|
||||
fullName.vb: AnthropicClient.Models.DocumentContent.New(String, String)
|
||||
nameWithType: DocumentContent.DocumentContent(string, string)
|
||||
nameWithType.vb: DocumentContent.New(String, String)
|
||||
- uid: AnthropicClient.Models.DocumentContent.#ctor(System.String,System.String,AnthropicClient.Models.CacheControl)
|
||||
name: DocumentContent(string, string, CacheControl)
|
||||
href: api/AnthropicClient.Models.DocumentContent.html#AnthropicClient_Models_DocumentContent__ctor_System_String_System_String_AnthropicClient_Models_CacheControl_
|
||||
commentId: M:AnthropicClient.Models.DocumentContent.#ctor(System.String,System.String,AnthropicClient.Models.CacheControl)
|
||||
name.vb: New(String, String, CacheControl)
|
||||
fullName: AnthropicClient.Models.DocumentContent.DocumentContent(string, string, AnthropicClient.Models.CacheControl)
|
||||
fullName.vb: AnthropicClient.Models.DocumentContent.New(String, String, AnthropicClient.Models.CacheControl)
|
||||
nameWithType: DocumentContent.DocumentContent(string, string, CacheControl)
|
||||
nameWithType.vb: DocumentContent.New(String, String, CacheControl)
|
||||
- uid: AnthropicClient.Models.DocumentContent.#ctor*
|
||||
name: DocumentContent
|
||||
href: api/AnthropicClient.Models.DocumentContent.html#AnthropicClient_Models_DocumentContent__ctor_
|
||||
commentId: Overload:AnthropicClient.Models.DocumentContent.#ctor
|
||||
isSpec: "True"
|
||||
name.vb: New
|
||||
fullName: AnthropicClient.Models.DocumentContent.DocumentContent
|
||||
fullName.vb: AnthropicClient.Models.DocumentContent.New
|
||||
nameWithType: DocumentContent.DocumentContent
|
||||
nameWithType.vb: DocumentContent.New
|
||||
- uid: AnthropicClient.Models.DocumentContent.Source
|
||||
name: Source
|
||||
href: api/AnthropicClient.Models.DocumentContent.html#AnthropicClient_Models_DocumentContent_Source
|
||||
commentId: P:AnthropicClient.Models.DocumentContent.Source
|
||||
fullName: AnthropicClient.Models.DocumentContent.Source
|
||||
nameWithType: DocumentContent.Source
|
||||
- uid: AnthropicClient.Models.DocumentContent.Source*
|
||||
name: Source
|
||||
href: api/AnthropicClient.Models.DocumentContent.html#AnthropicClient_Models_DocumentContent_Source_
|
||||
commentId: Overload:AnthropicClient.Models.DocumentContent.Source
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.DocumentContent.Source
|
||||
nameWithType: DocumentContent.Source
|
||||
- uid: AnthropicClient.Models.DocumentSource
|
||||
name: DocumentSource
|
||||
href: api/AnthropicClient.Models.DocumentSource.html
|
||||
commentId: T:AnthropicClient.Models.DocumentSource
|
||||
fullName: AnthropicClient.Models.DocumentSource
|
||||
nameWithType: DocumentSource
|
||||
- uid: AnthropicClient.Models.DocumentSource.#ctor(System.String,System.String)
|
||||
name: DocumentSource(string, string)
|
||||
href: api/AnthropicClient.Models.DocumentSource.html#AnthropicClient_Models_DocumentSource__ctor_System_String_System_String_
|
||||
commentId: M:AnthropicClient.Models.DocumentSource.#ctor(System.String,System.String)
|
||||
name.vb: New(String, String)
|
||||
fullName: AnthropicClient.Models.DocumentSource.DocumentSource(string, string)
|
||||
fullName.vb: AnthropicClient.Models.DocumentSource.New(String, String)
|
||||
nameWithType: DocumentSource.DocumentSource(string, string)
|
||||
nameWithType.vb: DocumentSource.New(String, String)
|
||||
- uid: AnthropicClient.Models.DocumentSource.#ctor*
|
||||
name: DocumentSource
|
||||
href: api/AnthropicClient.Models.DocumentSource.html#AnthropicClient_Models_DocumentSource__ctor_
|
||||
commentId: Overload:AnthropicClient.Models.DocumentSource.#ctor
|
||||
isSpec: "True"
|
||||
name.vb: New
|
||||
fullName: AnthropicClient.Models.DocumentSource.DocumentSource
|
||||
fullName.vb: AnthropicClient.Models.DocumentSource.New
|
||||
nameWithType: DocumentSource.DocumentSource
|
||||
nameWithType.vb: DocumentSource.New
|
||||
- uid: AnthropicClient.Models.DocumentSource.Data
|
||||
name: Data
|
||||
href: api/AnthropicClient.Models.DocumentSource.html#AnthropicClient_Models_DocumentSource_Data
|
||||
commentId: P:AnthropicClient.Models.DocumentSource.Data
|
||||
fullName: AnthropicClient.Models.DocumentSource.Data
|
||||
nameWithType: DocumentSource.Data
|
||||
- uid: AnthropicClient.Models.DocumentSource.Data*
|
||||
name: Data
|
||||
href: api/AnthropicClient.Models.DocumentSource.html#AnthropicClient_Models_DocumentSource_Data_
|
||||
commentId: Overload:AnthropicClient.Models.DocumentSource.Data
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.DocumentSource.Data
|
||||
nameWithType: DocumentSource.Data
|
||||
- uid: AnthropicClient.Models.DocumentSource.MediaType
|
||||
name: MediaType
|
||||
href: api/AnthropicClient.Models.DocumentSource.html#AnthropicClient_Models_DocumentSource_MediaType
|
||||
commentId: P:AnthropicClient.Models.DocumentSource.MediaType
|
||||
fullName: AnthropicClient.Models.DocumentSource.MediaType
|
||||
nameWithType: DocumentSource.MediaType
|
||||
- uid: AnthropicClient.Models.DocumentSource.MediaType*
|
||||
name: MediaType
|
||||
href: api/AnthropicClient.Models.DocumentSource.html#AnthropicClient_Models_DocumentSource_MediaType_
|
||||
commentId: Overload:AnthropicClient.Models.DocumentSource.MediaType
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.DocumentSource.MediaType
|
||||
nameWithType: DocumentSource.MediaType
|
||||
- uid: AnthropicClient.Models.DocumentSource.Type
|
||||
name: Type
|
||||
href: api/AnthropicClient.Models.DocumentSource.html#AnthropicClient_Models_DocumentSource_Type
|
||||
commentId: P:AnthropicClient.Models.DocumentSource.Type
|
||||
fullName: AnthropicClient.Models.DocumentSource.Type
|
||||
nameWithType: DocumentSource.Type
|
||||
- uid: AnthropicClient.Models.DocumentSource.Type*
|
||||
name: Type
|
||||
href: api/AnthropicClient.Models.DocumentSource.html#AnthropicClient_Models_DocumentSource_Type_
|
||||
commentId: Overload:AnthropicClient.Models.DocumentSource.Type
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.DocumentSource.Type
|
||||
nameWithType: DocumentSource.Type
|
||||
- uid: AnthropicClient.Models.EphemeralCacheControl
|
||||
name: EphemeralCacheControl
|
||||
href: api/AnthropicClient.Models.EphemeralCacheControl.html
|
||||
@@ -2519,6 +2806,25 @@ references:
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.TextDelta.Text
|
||||
nameWithType: TextDelta.Text
|
||||
- uid: AnthropicClient.Models.TokenCountResponse
|
||||
name: TokenCountResponse
|
||||
href: api/AnthropicClient.Models.TokenCountResponse.html
|
||||
commentId: T:AnthropicClient.Models.TokenCountResponse
|
||||
fullName: AnthropicClient.Models.TokenCountResponse
|
||||
nameWithType: TokenCountResponse
|
||||
- uid: AnthropicClient.Models.TokenCountResponse.InputTokens
|
||||
name: InputTokens
|
||||
href: api/AnthropicClient.Models.TokenCountResponse.html#AnthropicClient_Models_TokenCountResponse_InputTokens
|
||||
commentId: P:AnthropicClient.Models.TokenCountResponse.InputTokens
|
||||
fullName: AnthropicClient.Models.TokenCountResponse.InputTokens
|
||||
nameWithType: TokenCountResponse.InputTokens
|
||||
- uid: AnthropicClient.Models.TokenCountResponse.InputTokens*
|
||||
name: InputTokens
|
||||
href: api/AnthropicClient.Models.TokenCountResponse.html#AnthropicClient_Models_TokenCountResponse_InputTokens_
|
||||
commentId: Overload:AnthropicClient.Models.TokenCountResponse.InputTokens
|
||||
isSpec: "True"
|
||||
fullName: AnthropicClient.Models.TokenCountResponse.InputTokens
|
||||
nameWithType: TokenCountResponse.InputTokens
|
||||
- uid: AnthropicClient.Models.Tool
|
||||
name: Tool
|
||||
href: api/AnthropicClient.Models.Tool.html
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using AnthropicClient.Json;
|
||||
using AnthropicClient.Models;
|
||||
@@ -26,6 +27,35 @@ public interface IAnthropicApiClient
|
||||
/// <param name="request">The message request to create.</param>
|
||||
/// <returns>An asynchronous enumerable that yields the response event by event.</returns>
|
||||
IAsyncEnumerable<AnthropicEvent> CreateMessageAsync(StreamMessageRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Counts the tokens in a message asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="request">The count message tokens request.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains the response as an <see cref="AnthropicResult{T}"/> where T is <see cref="TokenCountResponse"/>.</returns>
|
||||
Task<AnthropicResult<TokenCountResponse>> CountMessageTokensAsync(CountMessageTokensRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Lists the models asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="request">The paging request to use for listing the models.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains the response as an <see cref="AnthropicResult{T}"/> where T is <see cref="Page{T}"/> where T is <see cref="AnthropicModel"/>.</returns>
|
||||
Task<AnthropicResult<Page<AnthropicModel>>> ListModelsAsync(PagingRequest? request = null);
|
||||
|
||||
/// <summary>
|
||||
/// Lists the models asynchronously
|
||||
/// </summary>
|
||||
/// <param name="limit">The maximum number of models to return in each page.</param>
|
||||
/// <returns>An asynchronous enumerable that yields the response as an <see cref="AnthropicResult{T}"/> where T is <see cref="Page{T}"/> where T is <see cref="AnthropicModel"/>.</returns>
|
||||
///
|
||||
IAsyncEnumerable<AnthropicResult<Page<AnthropicModel>>> ListAllModelsAsync(int limit = 20);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a model by its ID asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="modelId">The ID of the model to get.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains the response as an <see cref="AnthropicResult{T}"/> where T is <see cref="AnthropicModel"/>.</returns>
|
||||
Task<AnthropicResult<AnthropicModel>> GetModelAsync(string modelId);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IAnthropicApiClient"/>
|
||||
@@ -34,6 +64,8 @@ public class AnthropicApiClient : IAnthropicApiClient
|
||||
private const string BaseUrl = "https://api.anthropic.com/v1/";
|
||||
private const string ApiKeyHeader = "x-api-key";
|
||||
private const string MessagesEndpoint = "messages";
|
||||
private const string CountTokensEndpoint = "messages/count_tokens";
|
||||
private const string ModelsEndpoint = "models";
|
||||
private const string JsonContentType = "application/json";
|
||||
private const string EventPrefix = "event:";
|
||||
private const string DataPrefix = "data:";
|
||||
@@ -71,7 +103,7 @@ public class AnthropicApiClient : IAnthropicApiClient
|
||||
/// <inheritdoc/>
|
||||
public async Task<AnthropicResult<MessageResponse>> CreateMessageAsync(MessageRequest request)
|
||||
{
|
||||
var response = await SendRequestAsync(request);
|
||||
var response = await SendRequestAsync(MessagesEndpoint, request);
|
||||
var anthropicHeaders = new AnthropicHeaders(response.Headers);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
@@ -94,7 +126,7 @@ public class AnthropicApiClient : IAnthropicApiClient
|
||||
/// <inheritdoc/>
|
||||
public async IAsyncEnumerable<AnthropicEvent> CreateMessageAsync(StreamMessageRequest request)
|
||||
{
|
||||
var response = await SendRequestAsync(request);
|
||||
var response = await SendRequestAsync(MessagesEndpoint, request);
|
||||
|
||||
if (response.IsSuccessStatusCode is false)
|
||||
{
|
||||
@@ -255,6 +287,96 @@ public class AnthropicApiClient : IAnthropicApiClient
|
||||
} while (true);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<AnthropicResult<TokenCountResponse>> CountMessageTokensAsync(CountMessageTokensRequest request)
|
||||
{
|
||||
var response = await SendRequestAsync(CountTokensEndpoint, request);
|
||||
var anthropicHeaders = new AnthropicHeaders(response.Headers);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (response.IsSuccessStatusCode is false)
|
||||
{
|
||||
var error = Deserialize<AnthropicError>(responseContent) ?? new AnthropicError();
|
||||
return AnthropicResult<TokenCountResponse>.Failure(error, anthropicHeaders);
|
||||
}
|
||||
|
||||
var msgResponse = Deserialize<TokenCountResponse>(responseContent) ?? new TokenCountResponse();
|
||||
return AnthropicResult<TokenCountResponse>.Success(msgResponse, anthropicHeaders);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<AnthropicResult<Page<AnthropicModel>>> ListModelsAsync(PagingRequest? request = null)
|
||||
{
|
||||
var pagingRequest = request ?? new PagingRequest();
|
||||
var endpoint = $"{ModelsEndpoint}?{pagingRequest.ToQueryParameters()}";
|
||||
var response = await SendRequestAsync(endpoint);
|
||||
var anthropicHeaders = new AnthropicHeaders(response.Headers);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (response.IsSuccessStatusCode is false)
|
||||
{
|
||||
var error = Deserialize<AnthropicError>(responseContent) ?? new AnthropicError();
|
||||
return AnthropicResult<Page<AnthropicModel>>.Failure(error, anthropicHeaders);
|
||||
}
|
||||
|
||||
var page = Deserialize<Page<AnthropicModel>>(responseContent) ?? new Page<AnthropicModel>();
|
||||
return AnthropicResult<Page<AnthropicModel>>.Success(page, anthropicHeaders);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async IAsyncEnumerable<AnthropicResult<Page<AnthropicModel>>> ListAllModelsAsync(int limit = 20)
|
||||
{
|
||||
var pagingRequest = new PagingRequest(limit: limit);
|
||||
string Endpoint() => $"{ModelsEndpoint}?{pagingRequest.ToQueryParameters()}";
|
||||
bool hasMore;
|
||||
|
||||
do
|
||||
{
|
||||
var response = await SendRequestAsync(Endpoint());
|
||||
var anthropicHeaders = new AnthropicHeaders(response.Headers);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (response.IsSuccessStatusCode is false)
|
||||
{
|
||||
var error = Deserialize<AnthropicError>(responseContent) ?? new AnthropicError();
|
||||
yield return AnthropicResult<Page<AnthropicModel>>.Failure(error, anthropicHeaders);
|
||||
yield break;
|
||||
}
|
||||
|
||||
var page = Deserialize<Page<AnthropicModel>>(responseContent) ?? new Page<AnthropicModel>();
|
||||
|
||||
if (page.HasMore && page.LastId is not null)
|
||||
{
|
||||
hasMore = true;
|
||||
pagingRequest = new PagingRequest(limit: limit, afterId: page.LastId);
|
||||
}
|
||||
else
|
||||
{
|
||||
hasMore = false;
|
||||
}
|
||||
|
||||
yield return AnthropicResult<Page<AnthropicModel>>.Success(page, anthropicHeaders);
|
||||
} while (hasMore);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<AnthropicResult<AnthropicModel>> GetModelAsync(string modelId)
|
||||
{
|
||||
var endpoint = $"{ModelsEndpoint}/{modelId}";
|
||||
var response = await SendRequestAsync(endpoint);
|
||||
var anthropicHeaders = new AnthropicHeaders(response.Headers);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (response.IsSuccessStatusCode is false)
|
||||
{
|
||||
var error = Deserialize<AnthropicError>(responseContent) ?? new AnthropicError();
|
||||
return AnthropicResult<AnthropicModel>.Failure(error, anthropicHeaders);
|
||||
}
|
||||
|
||||
var model = Deserialize<AnthropicModel>(responseContent) ?? new AnthropicModel();
|
||||
return AnthropicResult<AnthropicModel>.Success(model, anthropicHeaders);
|
||||
}
|
||||
|
||||
private ToolCall? GetToolCall(MessageResponse response, List<Tool> tools)
|
||||
{
|
||||
var toolUse = response.Content.OfType<ToolUseContent>().FirstOrDefault();
|
||||
@@ -274,11 +396,16 @@ public class AnthropicApiClient : IAnthropicApiClient
|
||||
return new ToolCall(tool, toolUse);
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage> SendRequestAsync(BaseMessageRequest request)
|
||||
private async Task<HttpResponseMessage> SendRequestAsync(string endpoint)
|
||||
{
|
||||
return await _httpClient.GetAsync(endpoint);
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage> SendRequestAsync<T>(string endpoint, T request)
|
||||
{
|
||||
var requestJson = Serialize(request);
|
||||
var requestContent = new StringContent(requestJson, Encoding.UTF8, JsonContentType);
|
||||
return await _httpClient.PostAsync(MessagesEndpoint, requestContent);
|
||||
return await _httpClient.PostAsync(endpoint, requestContent);
|
||||
}
|
||||
|
||||
private string Serialize<T>(T obj) => JsonSerializer.Serialize(obj, JsonSerializationOptions.DefaultOptions);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<PackageId>AnthropicClient</PackageId>
|
||||
<Version>0.2.0</Version>
|
||||
<Version>0.5.0</Version>
|
||||
<Authors>Stevan Freeborn</Authors>
|
||||
<Description>Anthropic Client Library</Description>
|
||||
<PackageProjectUrl>https://anthropicclient.stevanfreeborn.com/</PackageProjectUrl>
|
||||
|
||||
@@ -2,6 +2,38 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [versionize](https://github.com/versionize/versionize) for commit guidelines.
|
||||
|
||||
<a name="0.5.0"></a>
|
||||
## [0.5.0](https://www.github.com/StevanFreeborn/anthropic-client/releases/tag/v0.5.0) (2025-01-06)
|
||||
|
||||
### Features
|
||||
|
||||
* add classes to model response to get model list endpoint ([28b7bf6](https://www.github.com/StevanFreeborn/anthropic-client/commit/28b7bf6a897cf3b2e2aad7df767b0f4428bec7a4))
|
||||
* add model to represent paged request ([df75cd2](https://www.github.com/StevanFreeborn/anthropic-client/commit/df75cd25e0a1beb55be97d5fcb8a718806793f51))
|
||||
* implement GetModelAsync method ([8bbd4bb](https://www.github.com/StevanFreeborn/anthropic-client/commit/8bbd4bb7c8c3f4e6fdd6d85d68d728794b85831f))
|
||||
* implement ListAllModelsAsync and ListModelsAsync ([8e0443a](https://www.github.com/StevanFreeborn/anthropic-client/commit/8e0443a6bb4736207d5ddf173f8ec966d03cec46))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* only allow afterId or beforeId to be set. not both at same time. ([3fe75f5](https://www.github.com/StevanFreeborn/anthropic-client/commit/3fe75f511d6c6adae7971b6402353c7408b6d513))
|
||||
|
||||
<a name="0.4.0"></a>
|
||||
## [0.4.0](https://www.github.com/StevanFreeborn/anthropic-client/releases/tag/v0.4.0) (2025-01-03)
|
||||
|
||||
### Features
|
||||
|
||||
* add support for count tokens endpoint ([9448220](https://www.github.com/StevanFreeborn/anthropic-client/commit/944822060cd297c5720d8a1dc366f08ca0ec79ec))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove model id validation ([31a7097](https://www.github.com/StevanFreeborn/anthropic-client/commit/31a7097cdc9f9f60a7b6576b8bcee7a49a00552c))
|
||||
|
||||
<a name="0.3.0"></a>
|
||||
## [0.3.0](https://www.github.com/StevanFreeborn/anthropic-client/releases/tag/v0.3.0) (2025-01-02)
|
||||
|
||||
### Features
|
||||
|
||||
* add missing model identifiers ([6e0c065](https://www.github.com/StevanFreeborn/anthropic-client/commit/6e0c0654af6a7daebac541995e4f082bae4a052e))
|
||||
|
||||
<a name="0.2.0"></a>
|
||||
## [0.2.0](https://www.github.com/StevanFreeborn/anthropic-client/releases/tag/v0.2.0) (2024-11-21)
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AnthropicClient.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an Anthropic model.
|
||||
/// </summary>
|
||||
public class AnthropicModel
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of the model.
|
||||
/// </summary>
|
||||
public string Type { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The id of the model.
|
||||
/// </summary>
|
||||
public string Id { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The display name of the model.
|
||||
/// </summary>
|
||||
[JsonPropertyName("display_name")]
|
||||
public string DisplayName { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The created date of the model.
|
||||
/// </summary>
|
||||
[JsonPropertyName("created_at")]
|
||||
public DateTimeOffset CreatedAt { get; init; }
|
||||
}
|
||||
@@ -6,24 +6,67 @@ namespace AnthropicClient.Models;
|
||||
public static class AnthropicModels
|
||||
{
|
||||
/// <summary>
|
||||
/// The Claude-3 Opus model.
|
||||
/// The Claude 3 Opus model.
|
||||
/// </summary>
|
||||
public const string Claude3Opus = "claude-3-opus-20240229";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude-3 Sonnet model.
|
||||
/// The Claude 3 Opus model.
|
||||
/// </summary>
|
||||
public const string Claude3Opus20241022 = "claude-3-opus-20240229";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude 3 Opus model.
|
||||
/// </summary>
|
||||
public const string Claude3OpusLatest = "claude-3-opus-latest";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude 3 Sonnet model.
|
||||
/// </summary>
|
||||
public const string Claude3Sonnet = "claude-3-sonnet-20240229";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude-3.5 Sonnet model.
|
||||
/// The Claude 3 Sonnet model.
|
||||
/// </summary>
|
||||
public const string Claude3Sonnet20240229 = "claude-3-sonnet-20240229";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude 3.5 Sonnet model.
|
||||
/// </summary>
|
||||
public const string Claude35Sonnet = "claude-3-5-sonnet-20240620";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude-3 Haiku model.
|
||||
/// The Claude 3.5 Sonnet model.
|
||||
/// </summary>
|
||||
public const string Claude35Sonnet20240620 = "claude-3-5-sonnet-20240620";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude 3.5 Sonnet model.
|
||||
/// </summary>
|
||||
public const string Claude35Sonnet20241022 = "claude-3-5-sonnet-20241022";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude 3.5 Sonnet model.
|
||||
/// </summary>
|
||||
public const string Claude35SonnetLatest = "claude-3-5-sonnet-latest";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude 3 Haiku model.
|
||||
/// </summary>
|
||||
public const string Claude3Haiku = "claude-3-haiku-20240307";
|
||||
|
||||
internal static bool IsValidModel(string modelId) => modelId is Claude3Opus or Claude3Sonnet or Claude35Sonnet or Claude3Haiku;
|
||||
/// <summary>
|
||||
/// The Claude 3 Haiku model.
|
||||
/// </summary>
|
||||
public const string Claude3Haiku20240307 = "claude-3-haiku-20240307";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude 3.5 Haiku model.
|
||||
/// </summary>
|
||||
public const string Claude35Haiku20241022 = "claude-3-5-haiku-20241022";
|
||||
|
||||
/// <summary>
|
||||
/// The Claude 3.5 Haiku model.
|
||||
/// </summary>
|
||||
public const string Claude35HaikuLatest = "claude-3-5-haiku-latest";
|
||||
}
|
||||
@@ -126,7 +126,6 @@ public abstract class BaseMessageRequest
|
||||
/// <param name="stream">A value indicating whether the message should be streamed.</param>
|
||||
/// <param name="stopSequences">The prompt stop sequences.</param>
|
||||
/// <param name="systemMessages">The system messages to use for the request.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when the model ID is invalid.</exception>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the model or messages is null.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown when the messages contain no messages.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown when the max tokens is less than one.</exception>
|
||||
@@ -151,11 +150,6 @@ public abstract class BaseMessageRequest
|
||||
ArgumentValidator.ThrowIfNull(model, nameof(model));
|
||||
ArgumentValidator.ThrowIfNull(messages, nameof(messages));
|
||||
|
||||
if (AnthropicModels.IsValidModel(model) is false)
|
||||
{
|
||||
throw new ArgumentException($"Invalid model ID: {model}");
|
||||
}
|
||||
|
||||
if (messages.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Messages must contain at least one message");
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using AnthropicClient.Utils;
|
||||
|
||||
namespace AnthropicClient.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to count the number of tokens in a message.
|
||||
/// </summary>
|
||||
public class CountMessageTokensRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the model ID to be used for the request.
|
||||
/// </summary>
|
||||
public string Model { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the messages to count the number of tokens in.
|
||||
/// </summary>
|
||||
public List<Message> Messages { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tool choice mode to use for the request.
|
||||
/// </summary>
|
||||
[JsonPropertyName("tool_choice")]
|
||||
public ToolChoice? ToolChoice { get; init; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tools to use for the request.
|
||||
/// </summary>
|
||||
public List<Tool>? Tools { get; init; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the system prompt to use for the request.
|
||||
/// </summary>
|
||||
[JsonPropertyName("system")]
|
||||
public List<TextContent>? SystemPrompt { get; init; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CountMessageTokensRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="model">The model ID to use for the request.</param>
|
||||
/// <param name="messages">The messages to count the number of tokens in.</param>
|
||||
/// <param name="toolChoice">The tool choice mode to use for the request.</param>
|
||||
/// <param name="tools">The tools to use for the request.</param>
|
||||
/// <param name="systemPrompt">The system prompt to use for the request.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> or <paramref name="messages"/> is null.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown when <paramref name="messages"/> is empty.</exception>
|
||||
/// <returns>A new instance of the <see cref="CountMessageTokensRequest"/> class.</returns>
|
||||
public CountMessageTokensRequest(
|
||||
string model,
|
||||
List<Message> messages,
|
||||
ToolChoice? toolChoice = null,
|
||||
List<Tool>? tools = null,
|
||||
List<TextContent>? systemPrompt = null
|
||||
)
|
||||
{
|
||||
ArgumentValidator.ThrowIfNull(model, nameof(model));
|
||||
ArgumentValidator.ThrowIfNull(messages, nameof(messages));
|
||||
|
||||
if (messages.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Messages must contain at least one message");
|
||||
}
|
||||
|
||||
Model = model;
|
||||
Messages = messages;
|
||||
ToolChoice = toolChoice;
|
||||
Tools = tools;
|
||||
SystemPrompt = systemPrompt;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ public class MessageRequest : BaseMessageRequest
|
||||
/// <param name="tools">The tools to use for the request.</param>
|
||||
/// <param name="stopSequences">The prompt stop sequences.</param>
|
||||
/// <param name="systemMessages">The system messages to include with the request.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when the model ID is invalid.</exception>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the model or messages is null.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown when the messages contain no messages.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown when the max tokens is less than one.</exception>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AnthropicClient.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a page.
|
||||
/// </summary>
|
||||
public class Page
|
||||
{
|
||||
/// <summary>
|
||||
/// The id of the first item in the page.
|
||||
/// </summary>
|
||||
[JsonPropertyName("first_id")]
|
||||
public string? FirstId { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The id of the last item in the page.
|
||||
/// </summary>
|
||||
[JsonPropertyName("last_id")]
|
||||
public string? LastId { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether there is more data to be retrieved.
|
||||
/// </summary>
|
||||
[JsonPropertyName("has_more")]
|
||||
public bool HasMore { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a page with data.
|
||||
/// </summary>
|
||||
public class Page<T> : Page
|
||||
{
|
||||
/// <summary>
|
||||
/// The data in the page.
|
||||
/// </summary>
|
||||
public T[] Data { get; init; } = [];
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AnthropicClient.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to page through a collection of items.
|
||||
/// </summary>
|
||||
public class PagingRequest
|
||||
{
|
||||
private const int LimitMinimum = 1;
|
||||
private const int LimitMaximum = 1000;
|
||||
private const int DefaultLimit = 20;
|
||||
|
||||
/// <summary>
|
||||
/// The ID of the item before which to start the page.
|
||||
/// </summary>
|
||||
[JsonPropertyName("before_id")]
|
||||
public string BeforeId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The ID of the item after which to start the page.
|
||||
/// </summary>
|
||||
[JsonPropertyName("after_id")]
|
||||
public string AfterId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of items to return in the page.
|
||||
/// </summary>
|
||||
public int Limit { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PagingRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="beforeId">The ID of the item before which to start the page.</param>
|
||||
/// <param name="afterId">The ID of the item after which to start the page.</param>
|
||||
/// <param name="limit">The maximum number of items to return in the page.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when both <paramref name="beforeId"/> and <paramref name="afterId"/> are specified.</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="limit"/> is less than 1 or greater than 1000.</exception>
|
||||
/// <returns>A new instance of the <see cref="PagingRequest"/> class.</returns>
|
||||
public PagingRequest(
|
||||
string beforeId = "",
|
||||
string afterId = "",
|
||||
int limit = DefaultLimit
|
||||
)
|
||||
{
|
||||
if (limit is < LimitMinimum or > LimitMaximum)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(limit), $"{nameof(limit)} must be between {LimitMinimum} and {LimitMaximum}.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(beforeId) is false && string.IsNullOrEmpty(afterId) is false)
|
||||
{
|
||||
throw new ArgumentException($"Only one of {nameof(beforeId)} or {nameof(afterId)} can be set.");
|
||||
}
|
||||
|
||||
BeforeId = beforeId;
|
||||
AfterId = afterId;
|
||||
Limit = limit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the <see cref="PagingRequest"/> to a query string.
|
||||
/// </summary>
|
||||
/// <returns>The query string representation of the <see cref="PagingRequest"/>.</returns>
|
||||
public string ToQueryParameters()
|
||||
{
|
||||
var parameters = new List<string>();
|
||||
|
||||
if (string.IsNullOrEmpty(BeforeId) is false)
|
||||
{
|
||||
parameters.Add($"before_id={BeforeId}");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(AfterId) is false)
|
||||
{
|
||||
parameters.Add($"after_id={AfterId}");
|
||||
}
|
||||
|
||||
parameters.Add($"limit={Limit}");
|
||||
|
||||
return string.Join("&", parameters);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ public class StreamMessageRequest : BaseMessageRequest
|
||||
/// <param name="tools">The tools to use for the request.</param>
|
||||
/// <param name="stopSequences">The prompt stop sequences.</param>
|
||||
/// <param name="systemMessages">The system messages to include with the request.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when the model ID is invalid.</exception>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the model or messages is null.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown when the messages contain no messages.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown when the max tokens is less than one.</exception>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AnthropicClient.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a response to a token count request.
|
||||
/// </summary>
|
||||
public class TokenCountResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// The number of input tokens counted.
|
||||
/// </summary>
|
||||
[JsonPropertyName("input_tokens")]
|
||||
public int InputTokens { get; init; }
|
||||
}
|
||||
@@ -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<MessageResponse>();
|
||||
@@ -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,
|
||||
@@ -299,4 +286,59 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf
|
||||
resultTwo.Value.Content.Should().NotBeNullOrEmpty();
|
||||
resultTwo.Value.Usage.CacheReadInputTokens.Should().BeGreaterThan(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CountMessageTokensAsync_WhenCalled_ItShouldReturnResponse()
|
||||
{
|
||||
var request = new CountMessageTokensRequest(
|
||||
model: AnthropicModels.Claude3Haiku,
|
||||
messages: [
|
||||
new(MessageRole.User, [new TextContent("Hello!")])
|
||||
]
|
||||
);
|
||||
|
||||
var result = await _client.CountMessageTokensAsync(request);
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().BeOfType<TokenCountResponse>();
|
||||
result.Value.InputTokens.Should().BeGreaterThan(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListModelsAsync_WhenCalled_ItShouldReturnResponse()
|
||||
{
|
||||
var result = await _client.ListModelsAsync();
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().BeOfType<Page<AnthropicModel>>();
|
||||
result.Value.Data.Should().HaveCountGreaterThan(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListModelsAsync_WhenCalledWithPagination_ItShouldReturnResponse()
|
||||
{
|
||||
var result = await _client.ListModelsAsync(new PagingRequest(limit: 1));
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().BeOfType<Page<AnthropicModel>>();
|
||||
result.Value.Data.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListAllModelsAsync_WhenCalled_ItShouldReturnResponse()
|
||||
{
|
||||
var responses = await _client.ListAllModelsAsync(limit: 1).ToListAsync();
|
||||
|
||||
responses.Should().HaveCountGreaterThan(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetModelAsync_WhenCalled_ItShouldReturnResponse()
|
||||
{
|
||||
var result = await _client.GetModelAsync(AnthropicModels.Claude3Haiku);
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().BeOfType<AnthropicModel>();
|
||||
result.Value.Id.Should().Be(AnthropicModels.Claude3Haiku);
|
||||
}
|
||||
}
|
||||
@@ -418,4 +418,564 @@ public class AnthropicApiClientTests : IntegrationTest
|
||||
textContent.As<TextContent>().Text.Should().Be("It is a PDF");
|
||||
textContent.As<TextContent>().Type.Should().Be("text");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CountMessageTokensAsync_WhenCalled_ItShouldReturnCountTokensResponse()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenCountMessageTokensRequest()
|
||||
.Respond(
|
||||
HttpStatusCode.OK,
|
||||
"application/json",
|
||||
@"{
|
||||
""input_tokens"": 10
|
||||
}"
|
||||
);
|
||||
|
||||
var request = new CountMessageTokensRequest(
|
||||
model: AnthropicModels.Claude35Sonnet,
|
||||
messages: [
|
||||
new(MessageRole.User, [new TextContent("Hello!")]),
|
||||
]
|
||||
);
|
||||
|
||||
var result = await Client.CountMessageTokensAsync(request);
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().BeOfType<TokenCountResponse>();
|
||||
result.Value.InputTokens.Should().Be(10);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CountMessageTokensAsync_WhenCalledAndErrorReturned_ItShouldHandleError()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenCountMessageTokensRequest()
|
||||
.Respond(
|
||||
HttpStatusCode.BadRequest,
|
||||
"application/json",
|
||||
@"{
|
||||
""type"": ""error"",
|
||||
""error"": {
|
||||
""type"": ""invalid_request_error"",
|
||||
""message"": ""messages: roles must alternate between user and assistant, but found multiple user roles in a row""
|
||||
}
|
||||
}"
|
||||
);
|
||||
|
||||
var request = new CountMessageTokensRequest(
|
||||
model: AnthropicModels.Claude35Sonnet,
|
||||
messages: [
|
||||
new(MessageRole.User, [new TextContent("Hello!")]),
|
||||
new(MessageRole.User, [new TextContent("Hello!")])
|
||||
]
|
||||
);
|
||||
|
||||
var result = await Client.CountMessageTokensAsync(request);
|
||||
|
||||
result.IsSuccess.Should().BeFalse();
|
||||
result.Error.Should().BeOfType<AnthropicError>();
|
||||
result.Error.Error.Should().BeOfType<InvalidRequestError>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CountMessageTokensAsync_WhenCalledRequestFailsAndCanNotDeserializeError_ItShouldReturnUnknownError()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenCountMessageTokensRequest()
|
||||
.Respond(
|
||||
HttpStatusCode.BadRequest,
|
||||
"application/json",
|
||||
@"{}"
|
||||
);
|
||||
|
||||
var request = new CountMessageTokensRequest(
|
||||
model: AnthropicModels.Claude35Sonnet,
|
||||
messages: [
|
||||
new(MessageRole.User, [new TextContent("Hello!")]),
|
||||
new(MessageRole.User, [new TextContent("Hello!")])
|
||||
]
|
||||
);
|
||||
|
||||
var result = await Client.CountMessageTokensAsync(request);
|
||||
|
||||
result.IsSuccess.Should().BeFalse();
|
||||
result.Error.Should().BeOfType<AnthropicError>();
|
||||
result.Error.Error.Should().BeOfType<ApiError>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListModelsAsync_WhenCalledWithPagingRequestUsingDefaultValues_ItShouldReturnListOfModels()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.Respond(
|
||||
HttpStatusCode.OK,
|
||||
"application/json",
|
||||
@"{
|
||||
""data"": [
|
||||
{
|
||||
""type"": ""model"",
|
||||
""id"": ""claude-3-5-sonnet-20241022"",
|
||||
""display_name"": ""Claude 3.5 Sonnet (New)"",
|
||||
""created_at"": ""2024-10-22T00:00:00Z""
|
||||
}
|
||||
],
|
||||
""has_more"": true,
|
||||
""first_id"": ""first_id"",
|
||||
""last_id"": ""last_id""
|
||||
}"
|
||||
);
|
||||
|
||||
var result = await Client.ListModelsAsync();
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().BeOfType<Page<AnthropicModel>>();
|
||||
result.Value.HasMore.Should().BeTrue();
|
||||
result.Value.FirstId.Should().Be("first_id");
|
||||
result.Value.LastId.Should().Be("last_id");
|
||||
result.Value.Data.Should().BeEquivalentTo(new AnthropicModel[]
|
||||
{
|
||||
new()
|
||||
{
|
||||
Type = "model",
|
||||
Id = "claude-3-5-sonnet-20241022",
|
||||
DisplayName = "Claude 3.5 Sonnet (New)",
|
||||
CreatedAt = DateTimeOffset.Parse("2024-10-22T00:00:00Z")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListModelsAsync_WhenCalledWithPagingRequestUsingCustomValues_ItShouldReturnListOfModels()
|
||||
{
|
||||
var pagingRequest = new PagingRequest(afterId: "next_id", limit: 10);
|
||||
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.WithQueryString(new Dictionary<string, string>
|
||||
{
|
||||
{ "after_id", pagingRequest.AfterId },
|
||||
{ "limit", pagingRequest.Limit.ToString() },
|
||||
})
|
||||
.Respond(
|
||||
HttpStatusCode.OK,
|
||||
"application/json",
|
||||
@"{
|
||||
""data"": [
|
||||
{
|
||||
""type"": ""model"",
|
||||
""id"": ""claude-3-5-sonnet-20241022"",
|
||||
""display_name"": ""Claude 3.5 Sonnet (New)"",
|
||||
""created_at"": ""2024-10-22T00:00:00Z""
|
||||
}
|
||||
],
|
||||
""has_more"": true,
|
||||
""first_id"": ""first_id"",
|
||||
""last_id"": ""last_id""
|
||||
}"
|
||||
);
|
||||
|
||||
var result = await Client.ListModelsAsync(pagingRequest);
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().BeOfType<Page<AnthropicModel>>();
|
||||
result.Value.HasMore.Should().BeTrue();
|
||||
result.Value.FirstId.Should().Be("first_id");
|
||||
result.Value.LastId.Should().Be("last_id");
|
||||
result.Value.Data.Should().BeEquivalentTo(new AnthropicModel[]
|
||||
{
|
||||
new()
|
||||
{
|
||||
Type = "model",
|
||||
Id = "claude-3-5-sonnet-20241022",
|
||||
DisplayName = "Claude 3.5 Sonnet (New)",
|
||||
CreatedAt = DateTimeOffset.Parse("2024-10-22T00:00:00Z")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListModelsAsync_WhenCalledAndNoModelsReturned_ItShouldReturnEmptyList()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.Respond(
|
||||
HttpStatusCode.OK,
|
||||
"application/json",
|
||||
@"{
|
||||
""data"": [],
|
||||
""has_more"": false,
|
||||
""first_id"": null,
|
||||
""last_id"": null
|
||||
}"
|
||||
);
|
||||
|
||||
var result = await Client.ListModelsAsync();
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().BeOfType<Page<AnthropicModel>>();
|
||||
result.Value.HasMore.Should().BeFalse();
|
||||
result.Value.FirstId.Should().BeNull();
|
||||
result.Value.LastId.Should().BeNull();
|
||||
result.Value.Data.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListModelsAsync_WhenCalledAndErrorReturned_ItShouldHandleError()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.Respond(
|
||||
HttpStatusCode.BadRequest,
|
||||
"application/json",
|
||||
@"{
|
||||
""type"": ""error"",
|
||||
""error"": {
|
||||
""type"": ""invalid_request_error"",
|
||||
""message"": ""messages: roles must alternate between user and assistant, but found multiple user roles in a row""
|
||||
}
|
||||
}"
|
||||
);
|
||||
|
||||
var result = await Client.ListModelsAsync();
|
||||
|
||||
result.IsSuccess.Should().BeFalse();
|
||||
result.Error.Should().BeOfType<AnthropicError>();
|
||||
result.Error.Error.Should().BeOfType<InvalidRequestError>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListModelsAsync_WhenCalledRequestFailsAndCanNotDeserializeError_ItShouldReturnUnknownError()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.Respond(
|
||||
HttpStatusCode.BadRequest,
|
||||
"application/json",
|
||||
@"{}"
|
||||
);
|
||||
|
||||
var result = await Client.ListModelsAsync();
|
||||
|
||||
result.IsSuccess.Should().BeFalse();
|
||||
result.Error.Should().BeOfType<AnthropicError>();
|
||||
result.Error.Error.Should().BeOfType<ApiError>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListAllModelsAsync_WhenCalled_ItShouldReturnAllModels()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.WithExactQueryString(new Dictionary<string, string>()
|
||||
{
|
||||
{ "limit", "20" },
|
||||
})
|
||||
.Respond(
|
||||
HttpStatusCode.OK,
|
||||
"application/json",
|
||||
@"{
|
||||
""data"": [
|
||||
{
|
||||
""type"": ""model"",
|
||||
""id"": ""claude-3-5-sonnet-20241022"",
|
||||
""display_name"": ""Claude 3.5 Sonnet (New)"",
|
||||
""created_at"": ""2024-10-22T00:00:00Z""
|
||||
}
|
||||
],
|
||||
""has_more"": true,
|
||||
""first_id"": ""1"",
|
||||
""last_id"": ""1""
|
||||
}"
|
||||
);
|
||||
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.WithExactQueryString(new Dictionary<string, string>()
|
||||
{
|
||||
{ "after_id", "1" },
|
||||
{ "limit", "20" },
|
||||
})
|
||||
.Respond(
|
||||
HttpStatusCode.OK,
|
||||
"application/json",
|
||||
@"{
|
||||
""data"": [
|
||||
{
|
||||
""type"": ""model"",
|
||||
""id"": ""claude-3-5-sonnet-20241023"",
|
||||
""display_name"": ""Claude 3.5 Sonnet (New)"",
|
||||
""created_at"": ""2024-10-23T00:00:00Z""
|
||||
}
|
||||
],
|
||||
""has_more"": false,
|
||||
""first_id"": ""2"",
|
||||
""last_id"": ""2""
|
||||
}"
|
||||
);
|
||||
|
||||
var pageResponses = Client.ListAllModelsAsync();
|
||||
var collectedPages = new List<Page<AnthropicModel>>();
|
||||
|
||||
await foreach (var response in pageResponses)
|
||||
{
|
||||
response.IsSuccess.Should().BeTrue();
|
||||
response.Value.Should().BeOfType<Page<AnthropicModel>>();
|
||||
collectedPages.Add(response.Value);
|
||||
}
|
||||
|
||||
collectedPages.Should().HaveCount(2);
|
||||
collectedPages.Should().BeEquivalentTo(new Page<AnthropicModel>[]
|
||||
{
|
||||
new()
|
||||
{
|
||||
HasMore = true,
|
||||
FirstId = "1",
|
||||
LastId = "1",
|
||||
Data = [
|
||||
new()
|
||||
{
|
||||
Type = "model",
|
||||
Id = "claude-3-5-sonnet-20241022",
|
||||
DisplayName = "Claude 3.5 Sonnet (New)",
|
||||
CreatedAt = DateTimeOffset.Parse("2024-10-22T00:00:00Z")
|
||||
}
|
||||
]
|
||||
},
|
||||
new()
|
||||
{
|
||||
HasMore = false,
|
||||
FirstId = "2",
|
||||
LastId = "2",
|
||||
Data = [
|
||||
new()
|
||||
{
|
||||
Type = "model",
|
||||
Id = "claude-3-5-sonnet-20241023",
|
||||
DisplayName = "Claude 3.5 Sonnet (New)",
|
||||
CreatedAt = DateTimeOffset.Parse("2024-10-23T00:00:00Z")
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListAllModelsAsync_WhenCalledAndErrorReturned_ItShouldHandleError()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.Respond(
|
||||
HttpStatusCode.BadRequest,
|
||||
"application/json",
|
||||
@"{
|
||||
""type"": ""error"",
|
||||
""error"": {
|
||||
""type"": ""invalid_request_error"",
|
||||
""message"": ""messages: roles must alternate between user and assistant, but found multiple user roles in a row""
|
||||
}
|
||||
}"
|
||||
);
|
||||
|
||||
var responses = Client.ListAllModelsAsync();
|
||||
var count = 0;
|
||||
|
||||
await foreach (var page in responses)
|
||||
{
|
||||
count++;
|
||||
page.IsSuccess.Should().BeFalse();
|
||||
page.Error.Should().BeOfType<AnthropicError>();
|
||||
page.Error.Error.Should().BeOfType<InvalidRequestError>();
|
||||
}
|
||||
|
||||
count.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListAllModelsAsync_WhenCalledRequestFailsAndCanNotDeserializeError_ItShouldReturnUnknownError()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.Respond(
|
||||
HttpStatusCode.BadRequest,
|
||||
"application/json",
|
||||
@"{}"
|
||||
);
|
||||
|
||||
var responses = Client.ListAllModelsAsync();
|
||||
var count = 0;
|
||||
|
||||
await foreach (var page in responses)
|
||||
{
|
||||
count++;
|
||||
page.IsSuccess.Should().BeFalse();
|
||||
page.Error.Should().BeOfType<AnthropicError>();
|
||||
page.Error.Error.Should().BeOfType<ApiError>();
|
||||
}
|
||||
|
||||
count.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListAllModelsAsync_WhenFirstPageSucceedsAndSecondPageFails_ItShouldReturnFirstPageAndError()
|
||||
{
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.WithExactQueryString(new Dictionary<string, string>
|
||||
{
|
||||
{ "limit", "20" },
|
||||
})
|
||||
.Respond(
|
||||
HttpStatusCode.OK,
|
||||
"application/json",
|
||||
@"{
|
||||
""data"": [
|
||||
{
|
||||
""type"": ""model"",
|
||||
""id"": ""claude-3-5-sonnet-20241022"",
|
||||
""display_name"": ""Claude 3.5 Sonnet (New)"",
|
||||
""created_at"": ""2024-10-22T00:00:00Z""
|
||||
}
|
||||
],
|
||||
""has_more"": true,
|
||||
""first_id"": ""1"",
|
||||
""last_id"": ""1""
|
||||
}"
|
||||
);
|
||||
|
||||
_mockHttpMessageHandler
|
||||
.WhenListModelsRequest()
|
||||
.WithExactQueryString(new Dictionary<string, string>
|
||||
{
|
||||
{ "after_id", "1" },
|
||||
{ "limit", "20" },
|
||||
})
|
||||
.Respond(
|
||||
HttpStatusCode.BadRequest,
|
||||
"application/json",
|
||||
@"{
|
||||
""type"": ""error"",
|
||||
""error"": {
|
||||
""type"": ""invalid_request_error"",
|
||||
""message"": ""messages: roles must alternate between user and assistant, but found multiple user roles in a row""
|
||||
}
|
||||
}"
|
||||
);
|
||||
|
||||
var responses = Client.ListAllModelsAsync();
|
||||
var count = 0;
|
||||
|
||||
await foreach (var page in responses)
|
||||
{
|
||||
count++;
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
page.IsSuccess.Should().BeTrue();
|
||||
page.Value.Should().BeOfType<Page<AnthropicModel>>();
|
||||
}
|
||||
else
|
||||
{
|
||||
page.IsSuccess.Should().BeFalse();
|
||||
page.Error.Should().BeOfType<AnthropicError>();
|
||||
page.Error.Error.Should().BeOfType<InvalidRequestError>();
|
||||
}
|
||||
}
|
||||
|
||||
count.Should().Be(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetModelAsync_WhenCalled_ItShouldReturnModel()
|
||||
{
|
||||
var modelId = "claude-3-5-sonnet-20241022";
|
||||
|
||||
_mockHttpMessageHandler
|
||||
.WhenGetModelRequest(modelId)
|
||||
.Respond(
|
||||
HttpStatusCode.OK,
|
||||
"application/json",
|
||||
@"{
|
||||
""type"": ""model"",
|
||||
""id"": ""claude-3-5-sonnet-20241022"",
|
||||
""display_name"": ""Claude 3.5 Sonnet (New)"",
|
||||
""created_at"": ""2024-10-22T00:00:00Z""
|
||||
}"
|
||||
);
|
||||
|
||||
var result = await Client.GetModelAsync(modelId);
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().BeOfType<AnthropicModel>();
|
||||
result.Value.Type.Should().Be("model");
|
||||
result.Value.Id.Should().Be("claude-3-5-sonnet-20241022");
|
||||
result.Value.DisplayName.Should().Be("Claude 3.5 Sonnet (New)");
|
||||
result.Value.CreatedAt.Should().Be(DateTimeOffset.Parse("2024-10-22T00:00:00Z"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetModelAsync_WhenCalledAndErrorReturned_ItShouldHandleError()
|
||||
{
|
||||
var modelId = "claude-3-5-sonnet-20241022";
|
||||
|
||||
_mockHttpMessageHandler
|
||||
.WhenGetModelRequest(modelId)
|
||||
.Respond(
|
||||
HttpStatusCode.BadRequest,
|
||||
"application/json",
|
||||
@"{
|
||||
""type"": ""error"",
|
||||
""error"": {
|
||||
""type"": ""invalid_request_error"",
|
||||
""message"": ""messages: roles must alternate between user and assistant, but found multiple user roles in a row""
|
||||
}
|
||||
}"
|
||||
);
|
||||
|
||||
var result = await Client.GetModelAsync(modelId);
|
||||
|
||||
result.IsSuccess.Should().BeFalse();
|
||||
result.Error.Should().BeOfType<AnthropicError>();
|
||||
result.Error.Error.Should().BeOfType<InvalidRequestError>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetModelAsync_WhenCalledRequestFailsAndCanNotDeserializeError_ItShouldReturnUnknownError()
|
||||
{
|
||||
var modelId = "claude-3-5-sonnet-20241022";
|
||||
|
||||
_mockHttpMessageHandler
|
||||
.WhenGetModelRequest(modelId)
|
||||
.Respond(
|
||||
HttpStatusCode.BadRequest,
|
||||
"application/json",
|
||||
@"{}"
|
||||
);
|
||||
|
||||
var result = await Client.GetModelAsync(modelId);
|
||||
|
||||
result.IsSuccess.Should().BeFalse();
|
||||
result.Error.Should().BeOfType<AnthropicError>();
|
||||
result.Error.Error.Should().BeOfType<ApiError>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetModelAsync_WhenCalledAndCanNotDeserializeModel_ItShouldReturnEmptyModel()
|
||||
{
|
||||
var modelId = "claude-3-5-sonnet-20241022";
|
||||
|
||||
_mockHttpMessageHandler
|
||||
.WhenGetModelRequest(modelId)
|
||||
.Respond(
|
||||
HttpStatusCode.OK,
|
||||
"application/json",
|
||||
@"{}"
|
||||
);
|
||||
|
||||
var result = await Client.GetModelAsync(modelId);
|
||||
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().BeOfType<AnthropicModel>();
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,19 @@ public class IntegrationTest
|
||||
|
||||
public static class MockHttpMessageHandlerExtensions
|
||||
{
|
||||
private static MockedRequest SetupBaseRequest(this MockHttpMessageHandler mockHttpMessageHandler)
|
||||
private const string BaseUrl = "https://api.anthropic.com/v1";
|
||||
private static readonly string MessagesEndpoint = $"{BaseUrl}/messages";
|
||||
private static readonly string CountTokensEndpoint = $"{BaseUrl}/messages/count_tokens";
|
||||
private static readonly string ModelsEndpoint = $"{BaseUrl}/models";
|
||||
|
||||
private static MockedRequest SetupBaseRequest(
|
||||
this MockHttpMessageHandler mockHttpMessageHandler,
|
||||
HttpMethod method,
|
||||
string url
|
||||
)
|
||||
{
|
||||
return mockHttpMessageHandler
|
||||
.When(HttpMethod.Post, "https://api.anthropic.com/v1/messages")
|
||||
.When(method, url)
|
||||
.WithHeaders(new Dictionary<string, string>
|
||||
{
|
||||
{ "anthropic-version", "2023-06-01" },
|
||||
@@ -27,14 +36,32 @@ public static class MockHttpMessageHandlerExtensions
|
||||
public static MockedRequest WhenCreateMessageRequest(this MockHttpMessageHandler mockHttpMessageHandler)
|
||||
{
|
||||
return mockHttpMessageHandler
|
||||
.SetupBaseRequest()
|
||||
.SetupBaseRequest(HttpMethod.Post, MessagesEndpoint)
|
||||
.WithJsonContent<MessageRequest>(r => r.Stream == false, JsonSerializationOptions.DefaultOptions);
|
||||
}
|
||||
|
||||
public static MockedRequest WhenCreateStreamMessageRequest(this MockHttpMessageHandler mockHttpMessageHandler)
|
||||
{
|
||||
return mockHttpMessageHandler
|
||||
.SetupBaseRequest()
|
||||
.SetupBaseRequest(HttpMethod.Post, MessagesEndpoint)
|
||||
.WithJsonContent<StreamMessageRequest>(r => r.Stream == true, JsonSerializationOptions.DefaultOptions);
|
||||
}
|
||||
|
||||
public static MockedRequest WhenCountMessageTokensRequest(this MockHttpMessageHandler mockHttpMessageHandler)
|
||||
{
|
||||
return mockHttpMessageHandler
|
||||
.SetupBaseRequest(HttpMethod.Post, CountTokensEndpoint);
|
||||
}
|
||||
|
||||
public static MockedRequest WhenListModelsRequest(this MockHttpMessageHandler mockHttpMessageHandler)
|
||||
{
|
||||
return mockHttpMessageHandler
|
||||
.SetupBaseRequest(HttpMethod.Get, ModelsEndpoint);
|
||||
}
|
||||
|
||||
public static MockedRequest WhenGetModelRequest(this MockHttpMessageHandler mockHttpMessageHandler, string modelId)
|
||||
{
|
||||
return mockHttpMessageHandler
|
||||
.SetupBaseRequest(HttpMethod.Get, $"{ModelsEndpoint}/{modelId}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class AnthropicModelTests : SerializationTest
|
||||
{
|
||||
private const string SampleJson = @"{
|
||||
""type"": ""model"",
|
||||
""id"": ""claude-3-opus-20240229"",
|
||||
""display_name"": ""Claude 3 Opus"",
|
||||
""created_at"": ""2024-02-29T00:00:00Z""
|
||||
}";
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnAnInstanceWithPropertiesSet()
|
||||
{
|
||||
var model = new AnthropicModel();
|
||||
|
||||
model.Type.Should().BeEmpty();
|
||||
model.Id.Should().BeEmpty();
|
||||
model.DisplayName.Should().BeEmpty();
|
||||
model.CreatedAt.Should().Be(default);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedValues()
|
||||
{
|
||||
var result = Deserialize<AnthropicModel>(SampleJson);
|
||||
|
||||
result.Should().NotBeNull();
|
||||
result!.Type.Should().Be("model");
|
||||
result.Id.Should().Be("claude-3-opus-20240229");
|
||||
result.DisplayName.Should().Be("Claude 3 Opus");
|
||||
result.CreatedAt.Should().Be(new DateTimeOffset(2024, 2, 29, 0, 0, 0, TimeSpan.Zero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenSerialized_ItShouldReturnExpectedShape()
|
||||
{
|
||||
var model = new AnthropicModel
|
||||
{
|
||||
Type = "model",
|
||||
Id = "claude-3-opus-20240229",
|
||||
DisplayName = "Claude 3 Opus",
|
||||
CreatedAt = new DateTimeOffset(2024, 2, 29, 0, 0, 0, TimeSpan.Zero)
|
||||
};
|
||||
|
||||
var result = Serialize(model);
|
||||
|
||||
var expectedJson = @"{
|
||||
""type"": ""model"",
|
||||
""id"": ""claude-3-opus-20240229"",
|
||||
""display_name"": ""Claude 3 Opus"",
|
||||
""created_at"": ""2024-02-29T00:00:00+00:00""
|
||||
}";
|
||||
|
||||
JsonAssert.Equal(expectedJson, result);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,26 @@ public class AnthropicModelsTests
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude3Opus20241022_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
var expected = "claude-3-opus-20240229";
|
||||
|
||||
var actual = AnthropicModels.Claude3Opus20241022;
|
||||
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude3OpusLatest_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
var expected = "claude-3-opus-latest";
|
||||
|
||||
var actual = AnthropicModels.Claude3OpusLatest;
|
||||
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude3Sonnet_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
@@ -22,6 +42,16 @@ public class AnthropicModelsTests
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude3Sonnet20240229_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
var expected = "claude-3-sonnet-20240229";
|
||||
|
||||
var actual = AnthropicModels.Claude3Sonnet20240229;
|
||||
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude35Sonnet_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
@@ -32,6 +62,36 @@ public class AnthropicModelsTests
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude35Sonnet20240620_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
var expected = "claude-3-5-sonnet-20240620";
|
||||
|
||||
var actual = AnthropicModels.Claude35Sonnet20240620;
|
||||
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude35Sonnet20241022_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
var expected = "claude-3-5-sonnet-20241022";
|
||||
|
||||
var actual = AnthropicModels.Claude35Sonnet20241022;
|
||||
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude35SonnetLatest_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
var expected = "claude-3-5-sonnet-latest";
|
||||
|
||||
var actual = AnthropicModels.Claude35SonnetLatest;
|
||||
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude3Haiku_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
@@ -43,24 +103,31 @@ public class AnthropicModelsTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude35Sonnet_WhenCalled_ItShouldExpectedValue()
|
||||
public void Claude3Haiku20240307_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
var expected = "claude-3-5-sonnet-20240620";
|
||||
var expected = "claude-3-haiku-20240307";
|
||||
|
||||
var actual = AnthropicModels.Claude35Sonnet;
|
||||
var actual = AnthropicModels.Claude3Haiku20240307;
|
||||
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("claude-3-opus-20240229", true)]
|
||||
[InlineData("claude-3-sonnet-20240229", true)]
|
||||
[InlineData("claude-3-5-sonnet-20240620", true)]
|
||||
[InlineData("claude-3-haiku-20240307", true)]
|
||||
[InlineData("invalid", false)]
|
||||
public void IsValidModel_WhenCalled_ItShouldReturnExpectedValue(string modelId, bool expected)
|
||||
[Fact]
|
||||
public void Claude35Haiku_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
var actual = AnthropicModels.IsValidModel(modelId);
|
||||
var expected = "claude-3-5-haiku-20241022";
|
||||
|
||||
var actual = AnthropicModels.Claude35Haiku20241022;
|
||||
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Claude35HaikuLatest_WhenCalled_ItShouldReturnExpectedValue()
|
||||
{
|
||||
var expected = "claude-3-5-haiku-latest";
|
||||
|
||||
var actual = AnthropicModels.Claude35HaikuLatest;
|
||||
|
||||
actual.Should().Be(expected);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class CountMessageTokensRequestTests : SerializationTest
|
||||
{
|
||||
private readonly string _testJson = @"{
|
||||
""model"": ""claude-3-sonnet-20240229"",
|
||||
""system"": [{
|
||||
""type"": ""text"",
|
||||
""text"": ""test-system""
|
||||
}],
|
||||
""messages"": [
|
||||
{ ""role"": ""user"", ""content"": [{ ""text"": ""Hello!"", ""type"": ""text"" }] }
|
||||
],
|
||||
""tool_choice"": { ""type"":""auto"" },
|
||||
""tools"": []
|
||||
}";
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldInitializeProperties()
|
||||
{
|
||||
var model = AnthropicModels.Claude3Sonnet;
|
||||
var messages = new List<Message> { new() };
|
||||
var systemPrompt = new List<TextContent>() { new("test-system") };
|
||||
var toolChoice = new AutoToolChoice();
|
||||
var tools = new List<Tool>();
|
||||
|
||||
var request = new CountMessageTokensRequest(
|
||||
model: model,
|
||||
messages: messages,
|
||||
toolChoice: toolChoice,
|
||||
tools: tools,
|
||||
systemPrompt: systemPrompt
|
||||
);
|
||||
|
||||
request.Model.Should().Be(model);
|
||||
request.Messages.Should().BeSameAs(messages);
|
||||
request.ToolChoice.Should().Be(toolChoice);
|
||||
request.Tools.Should().BeSameAs(tools);
|
||||
request.SystemPrompt.Should().BeSameAs(systemPrompt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndModelIsNull_ItShouldThrowArgumentNullException()
|
||||
{
|
||||
var action = () => new CountMessageTokensRequest(
|
||||
model: null!,
|
||||
messages: [new()]
|
||||
);
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndMessagesIsNull_ItShouldThrowArgumentNullException()
|
||||
{
|
||||
var action = () => new CountMessageTokensRequest(
|
||||
model: AnthropicModels.Claude3Sonnet,
|
||||
messages: null!
|
||||
);
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndMessagesIsEmpty_ItShouldThrowArgumentException()
|
||||
{
|
||||
var action = () => new CountMessageTokensRequest(
|
||||
model: AnthropicModels.Claude3Sonnet,
|
||||
messages: []
|
||||
);
|
||||
|
||||
action.Should().Throw<ArgumentException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var messages = new List<Message>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
Role = MessageRole.User,
|
||||
Content = [new TextContent("Hello!")]
|
||||
}
|
||||
};
|
||||
|
||||
var model = AnthropicModels.Claude3Sonnet;
|
||||
var systemPrompt = new List<TextContent>() { new("test-system") };
|
||||
var toolChoice = new AutoToolChoice();
|
||||
var tools = new List<Tool>();
|
||||
|
||||
var request = new CountMessageTokensRequest(
|
||||
model: model,
|
||||
messages: messages,
|
||||
toolChoice: toolChoice,
|
||||
tools: tools,
|
||||
systemPrompt: systemPrompt
|
||||
);
|
||||
|
||||
var actual = Serialize(request);
|
||||
|
||||
JsonAssert.Equal(_testJson, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var request = Deserialize<CountMessageTokensRequest>(_testJson);
|
||||
|
||||
request!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
request.SystemPrompt.Should().BeEquivalentTo(new List<TextContent> { new("test-system") });
|
||||
request.Messages.Should().HaveCount(1);
|
||||
request.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
request.ToolChoice!.Type.Should().Be("auto");
|
||||
request.Tools.Should().HaveCount(0);
|
||||
}
|
||||
}
|
||||
@@ -232,14 +232,14 @@ public class MessageRequestTests : SerializationTest
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndModelIsInvalid_ItShouldThrowArgumentException()
|
||||
public void Constructor_WhenCalledAndModelIsInvalid_ItShouldNotThrowException()
|
||||
{
|
||||
var action = () => new MessageRequest(
|
||||
model: "invalid-model",
|
||||
messages: [new()]
|
||||
);
|
||||
|
||||
action.Should().Throw<ArgumentException>();
|
||||
action.Should().NotThrow();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class PageTests : SerializationTest
|
||||
{
|
||||
private const string BasePageJson = @"{
|
||||
""first_id"": ""msg_123"",
|
||||
""last_id"": ""msg_456"",
|
||||
""has_more"": true
|
||||
}";
|
||||
|
||||
private const string GenericPageJson = @"{
|
||||
""first_id"": ""msg_123"",
|
||||
""last_id"": ""msg_456"",
|
||||
""has_more"": true,
|
||||
""data"": [""item1"", ""item2""]
|
||||
}";
|
||||
|
||||
private const string EmptyPageJson = @"{
|
||||
""first_id"": """",
|
||||
""last_id"": """",
|
||||
""has_more"": false,
|
||||
""data"": []
|
||||
}";
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnAnInstanceWithPropertiesSet()
|
||||
{
|
||||
var page = new Page();
|
||||
|
||||
page.FirstId.Should().BeEmpty();
|
||||
page.LastId.Should().BeEmpty();
|
||||
page.HasMore.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithGeneric_ItShouldReturnAnInstanceWithPropertiesSet()
|
||||
{
|
||||
var page = new Page<string>();
|
||||
|
||||
page.FirstId.Should().BeEmpty();
|
||||
page.LastId.Should().BeEmpty();
|
||||
page.HasMore.Should().BeFalse();
|
||||
page.Data.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenCalled_ItShouldHaveCorrectValues()
|
||||
{
|
||||
var result = Deserialize<Page>(BasePageJson);
|
||||
|
||||
result.Should().NotBeNull();
|
||||
result!.FirstId.Should().Be("msg_123");
|
||||
result.LastId.Should().Be("msg_456");
|
||||
result.HasMore.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenCalled_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var page = new Page
|
||||
{
|
||||
FirstId = "msg_123",
|
||||
LastId = "msg_456",
|
||||
HasMore = true
|
||||
};
|
||||
|
||||
var result = Serialize(page);
|
||||
|
||||
JsonAssert.Equal(BasePageJson, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenCalledWithData_ItShouldHaveCorrectValues()
|
||||
{
|
||||
var result = Deserialize<Page<string>>(GenericPageJson);
|
||||
|
||||
result.Should().NotBeNull();
|
||||
result!.FirstId.Should().Be("msg_123");
|
||||
result.LastId.Should().Be("msg_456");
|
||||
result.HasMore.Should().BeTrue();
|
||||
result.Data.Should().BeEquivalentTo(["item1", "item2"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenCalledWithData_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var page = new Page<string>
|
||||
{
|
||||
FirstId = "msg_123",
|
||||
LastId = "msg_456",
|
||||
HasMore = true,
|
||||
Data = ["item1", "item2"]
|
||||
};
|
||||
|
||||
var result = Serialize(page);
|
||||
|
||||
JsonAssert.Equal(GenericPageJson, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenCalledWithEmptyData_ItShouldHaveCorrectValues()
|
||||
{
|
||||
var result = Deserialize<Page<string>>(EmptyPageJson);
|
||||
|
||||
result.Should().NotBeNull();
|
||||
result!.FirstId.Should().BeEmpty();
|
||||
result.LastId.Should().BeEmpty();
|
||||
result.HasMore.Should().BeFalse();
|
||||
result.Data.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class PagingRequestTests : SerializationTest
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenLimitIsLessThanMinimum_ItShouldThrowArgumentOutOfRangeException()
|
||||
{
|
||||
var act = () => new PagingRequest(limit: 0);
|
||||
|
||||
act.Should().Throw<ArgumentOutOfRangeException>().WithMessage("limit must be between 1 and 1000. (Parameter 'limit')");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenLimitIsGreaterThanMaximum_ItShouldThrowArgumentOutOfRangeException()
|
||||
{
|
||||
var act = () => new PagingRequest(limit: 1001);
|
||||
|
||||
act.Should().Throw<ArgumentOutOfRangeException>().WithMessage("limit must be between 1 and 1000. (Parameter 'limit')");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenBothBeforeIdAndAfterIdAreSet_ItShouldThrowArgumentException()
|
||||
{
|
||||
var act = () => new PagingRequest(beforeId: "before-id", afterId: "after-id");
|
||||
|
||||
act.Should().Throw<ArgumentException>().WithMessage("Only one of beforeId or afterId can be set.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQueryParameters_WhenNoPropertiesSet_ItShouldReturnEmptyString()
|
||||
{
|
||||
var pagingRequest = new PagingRequest();
|
||||
|
||||
var result = pagingRequest.ToQueryParameters();
|
||||
|
||||
result.Should().Be("limit=20");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQueryParameters_WhenBeforeIdIsSet_ItShouldReturnBeforeId()
|
||||
{
|
||||
var pagingRequest = new PagingRequest(beforeId: "before-id");
|
||||
|
||||
var result = pagingRequest.ToQueryParameters();
|
||||
|
||||
result.Should().Be("before_id=before-id&limit=20");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQueryParameters_WhenAfterIdIsSet_ItShouldReturnAfterId()
|
||||
{
|
||||
var pagingRequest = new PagingRequest(afterId: "after-id");
|
||||
|
||||
var result = pagingRequest.ToQueryParameters();
|
||||
|
||||
result.Should().Be("after_id=after-id&limit=20");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQueryParameters_WhenLimitIsSetToNonDefaultValue_ItShouldReturnLimit()
|
||||
{
|
||||
var pagingRequest = new PagingRequest(limit: 10);
|
||||
|
||||
var result = pagingRequest.ToQueryParameters();
|
||||
|
||||
result.Should().Be("limit=10");
|
||||
}
|
||||
}
|
||||
@@ -85,14 +85,14 @@ public class StreamMessageRequestTests : SerializationTest
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndModelIsInvalid_ItShouldThrowArgumentException()
|
||||
public void Constructor_WhenCalledAndModelIsInvalid_ItShouldNotThrowException()
|
||||
{
|
||||
var action = () => new StreamMessageRequest(
|
||||
model: "invalid-model",
|
||||
messages: [new()]
|
||||
);
|
||||
|
||||
action.Should().Throw<ArgumentException>();
|
||||
action.Should().NotThrow();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class TokenCountResponseTests : SerializationTest
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldInitializeProperties()
|
||||
{
|
||||
var expectedTokenCount = 1;
|
||||
|
||||
var response = new TokenCountResponse
|
||||
{
|
||||
InputTokens = expectedTokenCount
|
||||
};
|
||||
|
||||
response.InputTokens.Should().Be(expectedTokenCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenCalled_ItShouldSerializeCorrectly()
|
||||
{
|
||||
var expectedJson = @"{
|
||||
""input_tokens"": 1
|
||||
}";
|
||||
|
||||
var response = new TokenCountResponse
|
||||
{
|
||||
InputTokens = 1
|
||||
};
|
||||
|
||||
var actual = Serialize(response);
|
||||
|
||||
JsonAssert.Equal(expectedJson, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenCalled_ItShouldDeserializeCorrectly()
|
||||
{
|
||||
var json = @"{
|
||||
""input_tokens"": 1
|
||||
}";
|
||||
|
||||
var response = Deserialize<TokenCountResponse>(json);
|
||||
|
||||
response!.InputTokens.Should().Be(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user