feat: implement CreateMessageBatchAsync method
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
namespace AnthropicClient.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to create a batch of messages.
|
||||
/// </summary>
|
||||
public class MessageBatchRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the requests to create messages.
|
||||
/// </summary>
|
||||
public List<MessageBatchRequestItem> Requests { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MessageBatchRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="requests">The requests to create messages.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when <paramref name="requests"/> is empty.</exception>
|
||||
/// <returns>An instance of the <see cref="MessageBatchRequest"/> class.</returns>
|
||||
public MessageBatchRequest(List<MessageBatchRequestItem> requests)
|
||||
{
|
||||
if (requests.Count == 0)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(requests)} must not be empty.", nameof(requests));
|
||||
}
|
||||
|
||||
Requests = requests;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using AnthropicClient.Utils;
|
||||
|
||||
namespace AnthropicClient.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an item in a batch of messages.
|
||||
/// </summary>
|
||||
public class MessageBatchRequestItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the custom identifier for the message.
|
||||
/// </summary>
|
||||
[JsonPropertyName("custom_id")]
|
||||
public string CustomId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the message request parameters.
|
||||
/// </summary>
|
||||
public MessageRequest Params { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MessageBatchRequestItem"/> class.
|
||||
/// </summary>
|
||||
/// <param name="customId">The custom identifier for the message.</param>
|
||||
/// <param name="messageRequest">The message request parameters.</param>
|
||||
/// <exception cref="ArgumentException">Thrown when <paramref name="customId"/> is null or whitespace.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown when <paramref name="messageRequest"/> is null.</exception>
|
||||
/// <returns>An instance of the <see cref="MessageBatchRequestItem"/> class.</returns>
|
||||
public MessageBatchRequestItem(string customId, MessageRequest messageRequest)
|
||||
{
|
||||
ArgumentValidator.ThrowIfNullOrWhitespace(customId, nameof(customId));
|
||||
ArgumentValidator.ThrowIfNull(messageRequest, nameof(messageRequest));
|
||||
|
||||
CustomId = customId;
|
||||
Params = messageRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AnthropicClient.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a response to a batch of messages.
|
||||
/// </summary>
|
||||
public class MessageBatchResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the identifier of the batch.
|
||||
/// </summary>
|
||||
public string Id { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the batch.
|
||||
/// </summary>
|
||||
public string Type { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the processing status of the batch.
|
||||
/// </summary>
|
||||
[JsonPropertyName("processing_status")]
|
||||
public string ProcessingStatus { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the counts of requests in the batch.
|
||||
/// </summary>
|
||||
[JsonPropertyName("request_counts")]
|
||||
public MessageBatchRequestCounts RequestCounts { get; init; } = new MessageBatchRequestCounts();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the batch ended.
|
||||
/// </summary>
|
||||
[JsonPropertyName("ended_at")]
|
||||
public DateTimeOffset EndedAt { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the batch was created.
|
||||
/// </summary>
|
||||
[JsonPropertyName("created_at")]
|
||||
public DateTimeOffset CreatedAt { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the batch expires.
|
||||
/// </summary>
|
||||
[JsonPropertyName("expires_at")]
|
||||
public DateTimeOffset ExpiresAt { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the batch was archived.
|
||||
/// </summary>
|
||||
[JsonPropertyName("archived_at")]
|
||||
public DateTimeOffset ArchivedAt { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the batch cancellation was initiated.
|
||||
/// </summary>
|
||||
[JsonPropertyName("cancel_initiated_at")]
|
||||
public DateTimeOffset CancelInitiatedAt { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL to the results of the batch.
|
||||
/// </summary>
|
||||
[JsonPropertyName("results_url")]
|
||||
public string ResultsUrl { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the counts of requests in a batch of messages.
|
||||
/// </summary>
|
||||
public class MessageBatchRequestCounts
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the number of requests in the batch that are processing.
|
||||
/// </summary>
|
||||
public int Processing { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of requests in the batch that succeeded.
|
||||
/// </summary>
|
||||
public int Succeeded { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of requests in the batch that errored.
|
||||
/// </summary>
|
||||
public int Errored { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of requests in the batch that were cancelled.
|
||||
/// </summary>
|
||||
public int Canceled { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of requests in the batch that expired.
|
||||
/// </summary>
|
||||
public int Expired { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user