feat: initial pass at citations in request and response
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
namespace AnthropicClient.Models;
|
||||
|
||||
public static class CitationType
|
||||
{
|
||||
public const string CharacterLocation = "char_location";
|
||||
public const string PageLocation = "page_location";
|
||||
public const string ContentBlockLocation = "content_block_location";
|
||||
}
|
||||
@@ -14,6 +14,12 @@ public class DocumentContent : Content
|
||||
/// </summary>
|
||||
public DocumentSource Source { get; init; } = new();
|
||||
|
||||
public string Title { get; init; } = string.Empty;
|
||||
|
||||
public string Context { get; init; } = string.Empty;
|
||||
|
||||
public CitationOption Citations { get; init; } = new CitationOption();
|
||||
|
||||
[JsonConstructor]
|
||||
internal DocumentContent()
|
||||
{
|
||||
@@ -53,4 +59,24 @@ public class DocumentContent : Content
|
||||
|
||||
Source = new(mediaType, data);
|
||||
}
|
||||
|
||||
public DocumentContent(DocumentSource source) : base(ContentType.Document)
|
||||
{
|
||||
ArgumentValidator.ThrowIfNull(source, nameof(source));
|
||||
|
||||
Source = source;
|
||||
}
|
||||
|
||||
public DocumentContent(DocumentSource source, CacheControl cacheControl) : base(ContentType.Document, cacheControl)
|
||||
{
|
||||
ArgumentValidator.ThrowIfNull(source, nameof(source));
|
||||
|
||||
Source = source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class CitationOption
|
||||
{
|
||||
public bool Enabled { get; init; }
|
||||
}
|
||||
@@ -14,6 +14,8 @@ public class TextContent : Content
|
||||
/// </summary>
|
||||
public string Text { get; init; } = string.Empty;
|
||||
|
||||
public Citation[] Citations { get; init; } = [];
|
||||
|
||||
[JsonConstructor]
|
||||
internal TextContent() : base(ContentType.Text)
|
||||
{
|
||||
@@ -50,4 +52,45 @@ public class TextContent : Content
|
||||
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Citation
|
||||
{
|
||||
public string Type { get; init; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("cited_text")]
|
||||
public string CitedText { get; init; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("document_index")]
|
||||
public int DocumentIndex { get; init; }
|
||||
|
||||
[JsonPropertyName("document_title")]
|
||||
public string DocumentTitle { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
public class CharacterLocationCitation : Citation
|
||||
{
|
||||
[JsonPropertyName("start_char_index")]
|
||||
public int StartCharIndex { get; init; }
|
||||
|
||||
[JsonPropertyName("end_char_index")]
|
||||
public int EndCharIndex { get; init; }
|
||||
}
|
||||
|
||||
public class PageLocationCitation : Citation
|
||||
{
|
||||
[JsonPropertyName("start_page_number")]
|
||||
public int StartPageNumber { get; init; }
|
||||
|
||||
[JsonPropertyName("end_page_number")]
|
||||
public int EndPageNumber { get; init; }
|
||||
}
|
||||
|
||||
public class ContentBlockLocationCitation : Citation
|
||||
{
|
||||
[JsonPropertyName("start_block_index")]
|
||||
public int StartBlockIndex { get; init; }
|
||||
|
||||
[JsonPropertyName("end_block_index")]
|
||||
public int EndBlockIndex { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace AnthropicClient.Models;
|
||||
|
||||
public class TextDocumentSource : DocumentSource
|
||||
{
|
||||
public TextDocumentSource(string data) : base("text/plain", data)
|
||||
{
|
||||
Type = "text";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user