Files
anthropic-client/src/AnthropicClient/Models/TextContent.cs
T

53 lines
1.5 KiB
C#
Raw Normal View History

2024-06-27 23:26:53 -05:00
using System.Text.Json.Serialization;
using AnthropicClient.Utils;
namespace AnthropicClient.Models;
/// <summary>
2024-07-03 16:57:27 -05:00
/// Represents text content that is part of a message.
2024-06-27 23:26:53 -05:00
/// </summary>
public class TextContent : Content
{
/// <summary>
/// Gets the text of the content.
/// </summary>
public string Text { get; init; } = string.Empty;
[JsonConstructor]
internal TextContent() : base(ContentType.Text)
{
}
2024-08-17 17:51:32 -05:00
private void Validate(string text)
{
ArgumentValidator.ThrowIfNull(text, nameof(text));
}
2024-06-27 23:26:53 -05:00
/// <summary>
/// Initializes a new instance of the <see cref="TextContent"/> class.
/// </summary>
/// <param name="text">The text of the content.</param>
/// <exception cref="ArgumentNullException">Thrown when the text is null.</exception>
/// <returns>A new instance of the <see cref="TextContent"/> class.</returns>
public TextContent(string text) : base(ContentType.Text)
{
2024-08-17 17:51:32 -05:00
Validate(text);
2024-06-27 23:26:53 -05:00
Text = text;
}
2024-08-15 23:04:45 -05:00
/// <summary>
/// Initializes a new instance of the <see cref="TextContent"/> class.
/// </summary>
/// <param name="text">The text of the content.</param>
/// <param name="cacheControl">The cache control to be used for the content.</param>
/// <returns>A new instance of the <see cref="TextContent"/> class.</returns>
/// <exception cref="ArgumentNullException">Thrown when the text or cache control is null.</exception>
public TextContent(string text, CacheControl cacheControl) : base(ContentType.Text, cacheControl)
{
2024-08-17 17:51:32 -05:00
Validate(text);
2024-08-15 23:04:45 -05:00
Text = text;
}
2024-06-27 23:26:53 -05:00
}