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 a message.
|
2024-06-27 23:26:53 -05:00
|
|
|
/// </summary>
|
2024-07-03 16:57:27 -05:00
|
|
|
public class Message
|
2024-06-27 23:26:53 -05:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the role of the message.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Role { get; init; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the contents of the message.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<Content> Content { get; init; } = [];
|
|
|
|
|
|
|
|
|
|
[JsonConstructor]
|
2024-07-03 16:57:27 -05:00
|
|
|
internal Message()
|
2024-06-27 23:26:53 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-07-03 16:57:27 -05:00
|
|
|
/// Initializes a new instance of the <see cref="Message"/> class.
|
2024-06-27 23:26:53 -05:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="role">The role of the message.</param>
|
|
|
|
|
/// <param name="content">The contents of the message.</param>
|
|
|
|
|
/// <exception cref="ArgumentException">Thrown when the role is invalid.</exception>
|
|
|
|
|
/// <exception cref="ArgumentNullException">Thrown when the role or content is null.</exception>
|
2024-07-03 16:57:27 -05:00
|
|
|
/// <returns>A new instance of the <see cref="Message"/> class.</returns>
|
|
|
|
|
public Message(string role, List<Content> content)
|
2024-06-27 23:26:53 -05:00
|
|
|
{
|
|
|
|
|
ArgumentValidator.ThrowIfNull(role, nameof(role));
|
|
|
|
|
ArgumentValidator.ThrowIfNull(content, nameof(content));
|
|
|
|
|
|
|
|
|
|
if (MessageRole.IsValidRole(role) is false)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"Invalid role: {role}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Role = role;
|
|
|
|
|
Content = content;
|
|
|
|
|
}
|
|
|
|
|
}
|