14 Commits
Author SHA1 Message Date
Stevan Freeborn 87ecb6e5ad chore(release): 0.3.0 [skip ci] 2025-01-02 00:51:59 +00:00
Stevan Freeborn abf4154432 Merge pull request #28 from StevanFreeborn/stevanfreeborn/feat/add-all-UTD-model-identifiers
feat: add model identifiers
2025-01-01 18:51:37 -06:00
Stevan Freeborn 9c0a2e37b7 chore: run dotnet format 2025-01-01 18:49:52 -06:00
Stevan Freeborn f861155551 tests: add tests for new model identifiers 2025-01-01 18:46:49 -06:00
Stevan Freeborn 6e0c0654af feat: add missing model identifiers
- Added additional identifiers for existing Models
  but included the date for consistency while maintaining
  backwards compatibility for those using the existing
  identifiers.
- Added missing identifiers for new versions of the
  Models
- Added identifiers for the models supporting the
  `latest` identifier
- All identifiers sourced from this doc:
  https://docs.anthropic.com/en/docs/about-claude/models
2025-01-01 00:48:25 -06:00
Stevan Freeborn 6b6bc1b015 docs: documentation for v0.2.0 [skip ci] 2024-11-21 20:08:15 +00:00
Stevan Freeborn 69ec59d0ee chore(release): 0.2.0 [skip ci] 2024-11-21 20:07:42 +00:00
Stevan Freeborn 27ad654cd9 Merge pull request #24 from StevanFreeborn/stevanfreeborn/feat/add-pdf-support
feat: add pdf support
2024-11-21 14:07:22 -06:00
Stevan Freeborn dc9755cbb8 chore: run dotnet format 2024-11-21 13:59:45 -06:00
Stevan Freeborn c66dc81df3 tests: add a test for converting DocumentContent 2024-11-21 13:55:56 -06:00
Stevan Freeborn 3de38ee5cf docs: add info about pdf support to README.md 2024-11-21 13:44:21 -06:00
Stevan Freeborn fe984d517d tests: add end to end test using pdf support 2024-11-21 13:43:41 -06:00
Stevan Freeborn f3a7040cb9 feat: add model for DocumentContent and DocumentSource 2024-11-21 13:43:21 -06:00
Stevan Freeborn c4d4d8a15b feat: add content type 2024-11-21 13:42:42 -06:00
26 changed files with 1548 additions and 33 deletions
+63
View File
@@ -847,3 +847,66 @@ 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);
```
PDF support can be used to provide a PDF document as input to the model. This can be used to provide additional context to the model or to ask for additional information from the model. This library aims to make using PDF support convenient by allowing you to provide the PDF document you want Anthropic's models to consider for use when creating a message.
#### PDF Document
You can provide a PDF document by providing its base64 encoded content as a `DocumentContent` instance in the list of messages in the `MessageRequest` or `StreamMessageRequest` constructor.
```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 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)
{
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;
}
}
```
@@ -120,6 +120,7 @@ Class Content <a class="header-action link-secondary" title="View source" href=
<dl class="typelist derived"> <dl class="typelist derived">
<dt>Derived</dt> <dt>Derived</dt>
<dd> <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.ImageContent.html">ImageContent</a></div>
<div><a class="xref" href="AnthropicClient.Models.TextContent.html">TextContent</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> <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 = &quot;document&quot;</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"> <h3 id="AnthropicClient_Models_ContentType_Image" data-uid="AnthropicClient.Models.ContentType.Image">
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> <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,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&amp;value=---%0Auid%3A%20AnthropicClient.Models.DocumentContent%0Asummary%3A%20&#39;*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax&#39;%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 &quot;{query}&quot;">
<meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
<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&amp;value=---%0Auid%3A%20AnthropicClient.Models.DocumentSource%0Asummary%3A%20&#39;*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax&#39;%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 &quot;{query}&quot;">
<meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
<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(&quot;media_type&quot;)]
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>
+10
View File
@@ -187,6 +187,16 @@ Classes
<dl class="jumplist"> <dl class="jumplist">
<dt><a class="xref" href="AnthropicClient.Models.ContentType.html">ContentType</a></dt> <dt><a class="xref" href="AnthropicClient.Models.ContentType.html">ContentType</a></dt>
<dd><p>Represents the content type.</p> <dd><p>Represents the content type.</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> </dd>
</dl> </dl>
<dl class="jumplist"> <dl class="jumplist">
+6
View File
@@ -87,6 +87,12 @@
<li> <li>
<a href="AnthropicClient.Models.ContentType.html" name="" title="ContentType">ContentType</a> <a href="AnthropicClient.Models.ContentType.html" name="" title="ContentType">ContentType</a>
</li> </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> <li>
<a href="AnthropicClient.Models.EphemeralCacheControl.html" name="" title="EphemeralCacheControl">EphemeralCacheControl</a> <a href="AnthropicClient.Models.EphemeralCacheControl.html" name="" title="EphemeralCacheControl">EphemeralCacheControl</a>
</li> </li>
+1 -1
View File
File diff suppressed because one or more lines are too long
+54
View File
@@ -812,6 +812,60 @@ foreach (var content in response.Value.Content)
} }
} }
</code></pre> </code></pre>
<h3 id="pdf-support">PDF Support</h3>
<p>Anthropic has recently introduced 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>
<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>pdfs-2024-09-25</code>.</p>
</div>
<p>When using this library you can opt-in to PDF support 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(&quot;anthropic-beta&quot;, &quot;pdfs-2024-09-25&quot;);
var client = new AnthropicApiClient(apiKey, httpClient);
</code></pre>
<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(&quot;What is the title of this paper?&quot;)]),
new(MessageRole.User, [new DocumentContent(&quot;application/pdf&quot;, base64Data)])
]
);
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add(&quot;anthropic-beta&quot;, &quot;pdfs-2024-09-25&quot;);
var client = new AnthropicApiClient(apiKey, httpClient);
var response = await client.CreateMessageAsync(request);
if (response.IsSuccess is false)
{
Console.WriteLine(&quot;Failed to create message&quot;);
Console.WriteLine(&quot;Error Type: {0}&quot;, response.Error.Error.Type);
Console.WriteLine(&quot;Error Message: {0}&quot;, 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> </article>
+14 -4
View File
File diff suppressed because one or more lines are too long
+20
View File
@@ -220,6 +220,26 @@
}, },
"version": "" "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", "type": "ManagedReference",
"source_relative_path": "api/AnthropicClient.Models.EphemeralCacheControl.yml", "source_relative_path": "api/AnthropicClient.Models.EphemeralCacheControl.yml",
+117
View File
@@ -994,6 +994,12 @@ references:
commentId: T:AnthropicClient.Models.ContentType commentId: T:AnthropicClient.Models.ContentType
fullName: AnthropicClient.Models.ContentType fullName: AnthropicClient.Models.ContentType
nameWithType: 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 - uid: AnthropicClient.Models.ContentType.Image
name: Image name: Image
href: api/AnthropicClient.Models.ContentType.html#AnthropicClient_Models_ContentType_Image href: api/AnthropicClient.Models.ContentType.html#AnthropicClient_Models_ContentType_Image
@@ -1018,6 +1024,117 @@ references:
commentId: F:AnthropicClient.Models.ContentType.ToolUse commentId: F:AnthropicClient.Models.ContentType.ToolUse
fullName: AnthropicClient.Models.ContentType.ToolUse fullName: AnthropicClient.Models.ContentType.ToolUse
nameWithType: ContentType.ToolUse nameWithType: ContentType.ToolUse
- 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 - uid: AnthropicClient.Models.EphemeralCacheControl
name: EphemeralCacheControl name: EphemeralCacheControl
href: api/AnthropicClient.Models.EphemeralCacheControl.html href: api/AnthropicClient.Models.EphemeralCacheControl.html
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<PackageId>AnthropicClient</PackageId> <PackageId>AnthropicClient</PackageId>
<Version>0.1.1</Version> <Version>0.3.0</Version>
<Authors>Stevan Freeborn</Authors> <Authors>Stevan Freeborn</Authors>
<Description>Anthropic Client Library</Description> <Description>Anthropic Client Library</Description>
<PackageProjectUrl>https://anthropicclient.stevanfreeborn.com/</PackageProjectUrl> <PackageProjectUrl>https://anthropicclient.stevanfreeborn.com/</PackageProjectUrl>
+15
View File
@@ -2,6 +2,21 @@
All notable changes to this project will be documented in this file. See [versionize](https://github.com/versionize/versionize) for commit guidelines. 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.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)
### Features
* add content type ([c4d4d8a](https://www.github.com/StevanFreeborn/anthropic-client/commit/c4d4d8a15bb690ae2b766a8f797b9e49f6965e60))
* add model for DocumentContent and DocumentSource ([f3a7040](https://www.github.com/StevanFreeborn/anthropic-client/commit/f3a7040cb929ac55df2b8369a26bb1b1a8e29fc8))
<a name="0.1.1"></a> <a name="0.1.1"></a>
## [0.1.1](https://www.github.com/StevanFreeborn/anthropic-client/releases/tag/v0.1.1) (2024-11-19) ## [0.1.1](https://www.github.com/StevanFreeborn/anthropic-client/releases/tag/v0.1.1) (2024-11-19)
@@ -16,6 +16,7 @@ class ContentConverter : JsonConverter<Content>
{ {
ContentType.Text => JsonSerializer.Deserialize<TextContent>(root.GetRawText(), options)!, ContentType.Text => JsonSerializer.Deserialize<TextContent>(root.GetRawText(), options)!,
ContentType.Image => JsonSerializer.Deserialize<ImageContent>(root.GetRawText(), options)!, ContentType.Image => JsonSerializer.Deserialize<ImageContent>(root.GetRawText(), options)!,
ContentType.Document => JsonSerializer.Deserialize<DocumentContent>(root.GetRawText(), options)!,
ContentType.ToolUse => JsonSerializer.Deserialize<ToolUseContent>(root.GetRawText(), options)!, ContentType.ToolUse => JsonSerializer.Deserialize<ToolUseContent>(root.GetRawText(), options)!,
ContentType.ToolResult => JsonSerializer.Deserialize<ToolResultContent>(root.GetRawText(), options)!, ContentType.ToolResult => JsonSerializer.Deserialize<ToolResultContent>(root.GetRawText(), options)!,
_ => throw new JsonException($"Unknown content type: {type}") _ => throw new JsonException($"Unknown content type: {type}")
+65 -5
View File
@@ -6,24 +6,84 @@ namespace AnthropicClient.Models;
public static class AnthropicModels public static class AnthropicModels
{ {
/// <summary> /// <summary>
/// The Claude-3 Opus model. /// The Claude 3 Opus model.
/// </summary> /// </summary>
public const string Claude3Opus = "claude-3-opus-20240229"; public const string Claude3Opus = "claude-3-opus-20240229";
/// <summary> /// <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> /// </summary>
public const string Claude3Sonnet = "claude-3-sonnet-20240229"; public const string Claude3Sonnet = "claude-3-sonnet-20240229";
/// <summary> /// <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> /// </summary>
public const string Claude35Sonnet = "claude-3-5-sonnet-20240620"; public const string Claude35Sonnet = "claude-3-5-sonnet-20240620";
/// <summary> /// <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> /// </summary>
public const string Claude3Haiku = "claude-3-haiku-20240307"; 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";
internal static bool IsValidModel(string modelId) => modelId is
Claude3Opus or
Claude3Opus20241022 or
Claude3OpusLatest or
Claude3Sonnet or
Claude3Sonnet20240229 or
Claude35Sonnet or
Claude35Sonnet20240620 or
Claude35Sonnet20241022 or
Claude35SonnetLatest or
Claude3Haiku or
Claude3Haiku20240307 or
Claude35Haiku20241022 or
Claude35HaikuLatest;
} }
@@ -24,4 +24,9 @@ public static class ContentType
/// Represents the tool result content type. /// Represents the tool result content type.
/// </summary> /// </summary>
public const string ToolResult = "tool_result"; public const string ToolResult = "tool_result";
/// <summary>
/// Represents the document content type.
/// </summary>
public const string Document = "document";
} }
@@ -0,0 +1,56 @@
using System.Text.Json.Serialization;
using AnthropicClient.Utils;
namespace AnthropicClient.Models;
/// <summary>
/// Represents content from a document that is part of a message.
/// </summary>
public class DocumentContent : Content
{
/// <summary>
/// Gets the source of the document.
/// </summary>
public DocumentSource Source { get; init; } = new();
[JsonConstructor]
internal DocumentContent()
{
}
private void Validate(string mediaType, string data)
{
ArgumentValidator.ThrowIfNull(mediaType, nameof(mediaType));
ArgumentValidator.ThrowIfNull(data, nameof(data));
}
/// <summary>
/// Initializes a new instance of the <see cref="DocumentContent"/> class.
/// </summary>
/// <param name="mediaType">The media type of the document.</param>
/// <param name="data">The data of the document.</param>
/// <exception cref="ArgumentNullException">Thrown when the media type or data is null.</exception>
/// <returns>A new instance of the <see cref="DocumentContent"/> class.</returns>
public DocumentContent(string mediaType, string data) : base(ContentType.Document)
{
Validate(mediaType, data);
Source = new(mediaType, data);
}
/// <summary>
/// Initializes a new instance of the <see cref="DocumentContent"/> class.
/// </summary>
/// <param name="mediaType">The media type of the document.</param>
/// <param name="data">The data of the document.</param>
/// <param name="cacheControl">The cache control to be used for the content.</param>
/// <returns>A new instance of the <see cref="DocumentContent"/> class.</returns>
/// <exception cref="ArgumentNullException">Thrown when the media type, data, or cache control is null.</exception>
public DocumentContent(string mediaType, string data, CacheControl cacheControl) : base(ContentType.Document, cacheControl)
{
Validate(mediaType, data);
Source = new(mediaType, data);
}
}
@@ -0,0 +1,49 @@
using System.Text.Json.Serialization;
using AnthropicClient.Utils;
namespace AnthropicClient.Models;
/// <summary>
/// Represents a document source.
/// </summary>
public class DocumentSource
{
/// <summary>
/// Gets the media type of the document.
/// </summary>
[JsonPropertyName("media_type")]
public string MediaType { get; init; } = string.Empty;
/// <summary>
/// Gets the data of the document.
/// </summary>
public string Data { get; init; } = string.Empty;
/// <summary>
/// Gets the type of encoding of the document data.
/// </summary>
public string Type { get; init; } = "base64";
[JsonConstructor]
internal DocumentSource()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DocumentSource"/> class.
/// </summary>
/// <param name="mediaType">The media type of the document.</param>
/// <param name="data">The data of the document.</param>
/// <exception cref="ArgumentException">Thrown when the media type is invalid.</exception>
/// <exception cref="ArgumentNullException">Thrown when the media type or data is null.</exception>
/// <returns>A new instance of the <see cref="DocumentSource"/> class.</returns>
public DocumentSource(string mediaType, string data)
{
ArgumentValidator.ThrowIfNull(mediaType, nameof(mediaType));
ArgumentValidator.ThrowIfNull(data, nameof(data));
MediaType = mediaType;
Data = data;
}
}
@@ -222,4 +222,81 @@ public class ClientTests(ConfigurationFixture configFixture) : EndToEndTest(conf
resultTwo.Value.Content.Should().NotBeNullOrEmpty(); resultTwo.Value.Content.Should().NotBeNullOrEmpty();
resultTwo.Value.Usage.CacheReadInputTokens.Should().BeGreaterThan(0); resultTwo.Value.Usage.CacheReadInputTokens.Should().BeGreaterThan(0);
} }
[Fact]
public async Task CreateMessageAsync_WhenProvidedWithPDF_ItShouldReturnResponse()
{
var pdfPath = GetTestFilePath("addendum.pdf");
var bytes = await File.ReadAllBytesAsync(pdfPath);
var base64Data = Convert.ToBase64String(bytes);
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 httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("anthropic-beta", "pdfs-2024-09-25");
var client = CreateClient(httpClient);
var result = await client.CreateMessageAsync(request);
result.IsSuccess.Should().BeTrue();
result.Value.Should().BeOfType<MessageResponse>();
result.Value.Content.Should().NotBeNullOrEmpty();
var text = result.Value.Content.Aggregate("", (acc, content) =>
{
if (content is TextContent textContent)
{
acc += textContent.Text;
}
return acc;
});
text.Should().Contain("Model Card Addendum: Claude 3.5 Haiku and Upgraded Claude 3.5 Sonnet");
}
[Fact]
public async Task CreateMessageAsync_WhenProvidedWithPDFWithCacheControl_ItShouldUseCache()
{
var pdfPath = GetTestFilePath("addendum.pdf");
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 request = new MessageRequest(
model: AnthropicModels.Claude35Sonnet,
messages: [
new(MessageRole.User, [
new DocumentContent("application/pdf", base64Data, new EphemeralCacheControl()),
new TextContent("What is the title of this paper?")
]),
]
);
var resultOne = await client.CreateMessageAsync(request);
resultOne.IsSuccess.Should().BeTrue();
resultOne.Value.Should().BeOfType<MessageResponse>();
resultOne.Value.Content.Should().NotBeNullOrEmpty();
resultOne.Value.Usage.Should().Match<Usage>(u => u.CacheCreationInputTokens > 0 || u.CacheReadInputTokens > 0);
request.Messages.Add(new(MessageRole.Assistant, resultOne.Value.Content));
request.Messages.Add(new(MessageRole.User, [new TextContent("What is the main theme of this paper?")]));
var resultTwo = await client.CreateMessageAsync(request);
resultTwo.IsSuccess.Should().BeTrue();
resultTwo.Value.Should().BeOfType<MessageResponse>();
resultTwo.Value.Content.Should().NotBeNullOrEmpty();
resultTwo.Value.Usage.CacheReadInputTokens.Should().BeGreaterThan(0);
}
} }
Binary file not shown.
@@ -359,4 +359,63 @@ public class AnthropicApiClientTests : IntegrationTest
) )
)); ));
} }
[Fact]
public async Task CreateMessageAsync_WhenCalledAndMessageCreatedWithDocumentContent_ItShouldReturnMessage()
{
_mockHttpMessageHandler
.WhenCreateMessageRequest()
.Respond(
HttpStatusCode.OK,
"application/json",
@"{
""content"": [
{
""text"": ""It is a PDF"",
""type"": ""text""
}
],
""id"": ""msg_013Zva2CMHLNnXjNJJKqJ2EF"",
""model"": ""claude-3-5-sonnet-20240620"",
""role"": ""assistant"",
""stop_reason"": ""end_turn"",
""stop_sequence"": null,
""type"": ""message"",
""usage"": {
""input_tokens"": 10,
""output_tokens"": 25
}
}"
);
var request = new MessageRequest(
model: AnthropicModels.Claude35Sonnet,
messages: [
new(MessageRole.User, [new TextContent("What is this?")]),
new(MessageRole.User, [new DocumentContent("application/pdf", "data")])
]
);
var result = await Client.CreateMessageAsync(request);
result.IsSuccess.Should().BeTrue();
result.Value.Should().BeOfType<MessageResponse>();
var message = result.Value;
message.Id.Should().Be("msg_013Zva2CMHLNnXjNJJKqJ2EF");
message.Model.Should().Be("claude-3-5-sonnet-20240620");
message.Role.Should().Be("assistant");
message.StopReason.Should().Be("end_turn");
message.StopSequence.Should().BeNull();
message.Type.Should().Be("message");
message.Usage.InputTokens.Should().Be(10);
message.Usage.OutputTokens.Should().Be(25);
message.Content.Should().HaveCount(1);
message.ToolCall.Should().BeNull();
var textContent = message.Content[0];
textContent.Should().BeOfType<TextContent>();
textContent.As<TextContent>().Text.Should().Be("It is a PDF");
textContent.As<TextContent>().Type.Should().Be("text");
}
} }
@@ -12,6 +12,26 @@ public class AnthropicModelsTests
actual.Should().Be(expected); 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] [Fact]
public void Claude3Sonnet_WhenCalled_ItShouldReturnExpectedValue() public void Claude3Sonnet_WhenCalled_ItShouldReturnExpectedValue()
{ {
@@ -22,6 +42,16 @@ public class AnthropicModelsTests
actual.Should().Be(expected); 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] [Fact]
public void Claude35Sonnet_WhenCalled_ItShouldReturnExpectedValue() public void Claude35Sonnet_WhenCalled_ItShouldReturnExpectedValue()
{ {
@@ -32,6 +62,36 @@ public class AnthropicModelsTests
actual.Should().Be(expected); 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] [Fact]
public void Claude3Haiku_WhenCalled_ItShouldReturnExpectedValue() public void Claude3Haiku_WhenCalled_ItShouldReturnExpectedValue()
{ {
@@ -43,20 +103,45 @@ public class AnthropicModelsTests
} }
[Fact] [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);
}
[Fact]
public void Claude35Haiku_WhenCalled_ItShouldReturnExpectedValue()
{
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); actual.Should().Be(expected);
} }
[Theory] [Theory]
[InlineData("claude-3-opus-20240229", true)] [InlineData("claude-3-opus-20240229", true)]
[InlineData("claude-3-opus-latest", true)]
[InlineData("claude-3-sonnet-20240229", true)] [InlineData("claude-3-sonnet-20240229", true)]
[InlineData("claude-3-5-sonnet-20240620", true)] [InlineData("claude-3-5-sonnet-20240620", true)]
[InlineData("claude-3-5-sonnet-20241022", true)]
[InlineData("claude-3-5-sonnet-latest", true)]
[InlineData("claude-3-haiku-20240307", true)] [InlineData("claude-3-haiku-20240307", true)]
[InlineData("claude-3-5-haiku-20241022", true)]
[InlineData("claude-3-5-haiku-latest", true)]
[InlineData("invalid", false)] [InlineData("invalid", false)]
public void IsValidModel_WhenCalled_ItShouldReturnExpectedValue(string modelId, bool expected) public void IsValidModel_WhenCalled_ItShouldReturnExpectedValue(string modelId, bool expected)
{ {
@@ -5,40 +5,30 @@ public class ContentTypeTests
[Fact] [Fact]
public void Text_WhenCalled_ItShouldReturnText() public void Text_WhenCalled_ItShouldReturnText()
{ {
var expected = "text"; ContentType.Text.Should().Be("text");
var actual = ContentType.Text;
actual.Should().Be(expected);
} }
[Fact] [Fact]
public void Image_WhenCalled_ItShouldReturnImage() public void Image_WhenCalled_ItShouldReturnImage()
{ {
var expected = "image"; ContentType.Image.Should().Be("image");
var actual = ContentType.Image;
actual.Should().Be(expected);
} }
[Fact] [Fact]
public void ToolUse_WhenCalled_ItShouldReturnToolUse() public void ToolUse_WhenCalled_ItShouldReturnToolUse()
{ {
var expected = "tool_use"; ContentType.ToolUse.Should().Be("tool_use");
var actual = ContentType.ToolUse;
actual.Should().Be(expected);
} }
[Fact] [Fact]
public void ToolResult_WhenCalled_ItShouldReturnToolResult() public void ToolResult_WhenCalled_ItShouldReturnToolResult()
{ {
var expected = "tool_result"; ContentType.ToolResult.Should().Be("tool_result");
}
var actual = ContentType.ToolResult; [Fact]
public void Document_WhenCalled_ItShouldReturnDocument()
actual.Should().Be(expected); {
ContentType.Document.Should().Be("document");
} }
} }
@@ -0,0 +1,119 @@
namespace AnthropicClient.Tests.Unit.Models;
public class DocumentContentTests : SerializationTest
{
private readonly string _testJson = @"{
""source"": {
""media_type"": ""application/pdf"",
""data"": ""data"",
""type"": ""base64""
},
""type"": ""document""
}";
private readonly string _testJsonWithCacheControl = @"{
""source"": {
""media_type"": ""application/pdf"",
""data"": ""data"",
""type"": ""base64""
},
""cache_control"": { ""type"": ""ephemeral"" },
""type"": ""document""
}";
[Fact]
public void Constructor_WhenCalled_ItShouldInitializeSource()
{
var expectedMediaType = "application/pdf";
var expectedData = "data";
var result = new DocumentContent(expectedMediaType, expectedData);
result.Source.Should().BeEquivalentTo(new DocumentSource(expectedMediaType, expectedData));
}
[Fact]
public void Constructor_WhenCalledAndMediaTypeIsNull_ItShouldThrowArgumentNullException()
{
var expectedData = "data";
var action = () => new DocumentContent(null!, expectedData);
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledAndDataIsNull_ItShouldThrowArgumentNullException()
{
var expectedMediaType = "application/pdf";
var action = () => new DocumentContent(expectedMediaType, null!);
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledWithCacheControl_ItShouldInitializeSourceAndCacheControl()
{
var expectedMediaType = "application/pdf";
var expectedData = "data";
var cacheControl = new EphemeralCacheControl();
var result = new DocumentContent(expectedMediaType, expectedData, cacheControl);
result.Source.Should().BeEquivalentTo(new DocumentSource(expectedMediaType, expectedData));
result.CacheControl.Should().BeSameAs(cacheControl);
}
[Fact]
public void Constructor_WhenCalledWithCacheControlAndMediaTypeIsNull_ItShouldThrowArgumentNullException()
{
var expectedData = "data";
var cacheControl = new EphemeralCacheControl();
var action = () => new DocumentContent(null!, expectedData, cacheControl);
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledWithCacheControlAndDataIsNull_ItShouldThrowArgumentNullException()
{
var expectedMediaType = "application/pdf";
var cacheControl = new EphemeralCacheControl();
var action = () => new DocumentContent(expectedMediaType, null!, cacheControl);
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
{
var content = new DocumentContent("application/pdf", "data");
var actual = Serialize(content);
JsonAssert.Equal(_testJson, actual);
}
[Fact]
public void JsonSerialization_WhenSerializedWithCacheControl_ItShouldHaveExpectedShape()
{
var content = new DocumentContent("application/pdf", "data", new EphemeralCacheControl());
var actual = Serialize(content);
JsonAssert.Equal(_testJsonWithCacheControl, actual);
}
[Fact]
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape()
{
var expected = new DocumentContent("application/pdf", "data");
var actual = Deserialize<DocumentContent>(_testJson);
actual.Should().BeEquivalentTo(expected);
}
}
@@ -0,0 +1,49 @@
namespace AnthropicClient.Tests.Unit.Models;
public class DocumentSourceTests
{
[Fact]
public void Constructor_WhenCalledWithValidArguments_ItShouldSetProperties()
{
var mediaType = "application/pdf";
var data = "base64data";
var source = new DocumentSource(mediaType, data);
source.MediaType.Should().Be(mediaType);
source.Data.Should().Be(data);
}
[Fact]
public void Constructor_WhenCalledWithNullMediaType_ItShouldThrowArgumentNullException()
{
string? mediaType = null;
var data = "base64data";
var action = () => new DocumentSource(mediaType!, data);
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledWithNullData_ItShouldThrowArgumentNullException()
{
var mediaType = "application/pdf";
string? data = null;
var action = () => new DocumentSource(mediaType, data!);
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalled_ItShouldHaveTypePropertySetToBase64()
{
var mediaType = "application/pdf";
var data = "base64data";
var source = new DocumentSource(mediaType, data);
source.Type.Should().Be("base64");
}
}