-
Notifications
You must be signed in to change notification settings - Fork 829
Add TextContent.Annotations #6619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary> | ||
/// Represents an annotation on content. | ||
/// </summary> | ||
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")] | ||
[JsonDerivedType(typeof(CitationAnnotation), typeDiscriminator: "citation")] | ||
public class AIAnnotation | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AIAnnotation"/> class. | ||
/// </summary> | ||
public AIAnnotation() | ||
{ | ||
} | ||
|
||
/// <summary>Gets or sets any target regions for the annotation, pointing to where in the associated <see cref="AIContent"/> this annotation applies.</summary> | ||
/// <remarks> | ||
/// The most common form of <see cref="AnnotatedRegion"/> is <see cref="TextSpanAnnotatedRegion"/>, which provides starting and ending character indices | ||
stephentoub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// for <see cref="TextContent"/>. | ||
/// </remarks> | ||
public IList<AnnotatedRegion>? AnnotatedRegions { get; set; } | ||
|
||
/// <summary>Gets or sets the raw representation of the annotation from an underlying implementation.</summary> | ||
/// <remarks> | ||
/// If an <see cref="AIAnnotation"/> is created to represent some underlying object from another object | ||
/// model, this property can be used to store that original object. This can be useful for debugging or | ||
/// for enabling a consumer to access the underlying object model, if needed. | ||
/// </remarks> | ||
[JsonIgnore] | ||
public object? RawRepresentation { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets additional metadata specific to the provider or source type. | ||
/// </summary> | ||
public AdditionalPropertiesDictionary? AdditionalProperties { get; set; } | ||
} |
Empty file.
Empty file removed
0
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIAnnotationKind.cs
Empty file.
Empty file removed
0
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIAnnotationReference.cs
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AnnotatedRegion.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text.Json.Serialization; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary>Describes the portion of an associated <see cref="AIContent"/> to which an annotation applies.</summary> | ||
/// <remarks> | ||
/// Details about the region is provided by derived types based on how the region is described. For example, starting | ||
/// and ending indices into text content are provided by <see cref="TextSpanAnnotatedRegion"/>. | ||
/// </remarks> | ||
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")] | ||
[JsonDerivedType(typeof(TextSpanAnnotatedRegion), typeDiscriminator: "textSpan")] | ||
public class AnnotatedRegion | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AnnotatedRegion"/> class. | ||
/// </summary> | ||
public AnnotatedRegion() | ||
{ | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/CitationAnnotation.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary> | ||
/// Represents an annotation that links content to source references, | ||
/// such as documents, URLs, files, or tool outputs. | ||
/// </summary> | ||
public class CitationAnnotation : AIAnnotation | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CitationAnnotation"/> class. | ||
/// </summary> | ||
public CitationAnnotation() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the title or name of the source. | ||
/// </summary> | ||
/// <remarks> | ||
/// This could be the title of a document, a title from a web page, a name of a file, or similarly descriptive text. | ||
/// </remarks> | ||
public string? Title { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a URI from which the source material was retrieved. | ||
/// </summary> | ||
public Uri? Url { get; set; } | ||
|
||
/// <summary>Gets or sets a source identifier associated with the annotation.</summary> | ||
/// <remarks> | ||
/// This is a provider-specific identifier that can be used to reference the source material by | ||
/// an ID. This may be a document ID, or a file ID, or some other identifier for the source material | ||
/// that can be used to uniquely identify it with the provider. | ||
/// </remarks> | ||
public string? FileId { get; set; } | ||
|
||
/// <summary>Gets or sets the name of any tool involved in the production of the associated content.</summary> | ||
/// <remarks> | ||
/// This might be a function name, such as one from <see cref="AITool.Name"/>, or the name of a built-in tool | ||
/// from the provider, such as "code_interpreter" or "file_search". | ||
/// </remarks> | ||
public string? ToolName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a snippet or excerpt from the source that was cited. | ||
/// </summary> | ||
public string? Snippet { get; set; } | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/TextSpanAnnotatedRegion.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary>Describes a location in the associated <see cref="AIContent"/> based on starting and ending character indices.</summary> | ||
/// <remarks>This <see cref="AnnotatedRegion"/> typically applies to <see cref="TextContent"/>.</remarks> | ||
[DebuggerDisplay("[{StartIndex}, {EndIndex})")] | ||
public sealed class TextSpanAnnotatedRegion : AnnotatedRegion | ||
stephentoub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TextSpanAnnotatedRegion"/> class. | ||
/// </summary> | ||
public TextSpanAnnotatedRegion() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the start character index (inclusive) of the annotated span in the <see cref="AIContent"/>. | ||
/// </summary> | ||
[JsonPropertyName("start")] | ||
public int? StartIndex { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the end character index (exclusive) of the annotated span in the <see cref="AIContent"/>. | ||
/// </summary> | ||
[JsonPropertyName("end")] | ||
public int? EndIndex { get; set; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.