feat: add models for streaming messages

This commit is contained in:
Stevan Freeborn
2024-06-28 10:54:00 -05:00
parent 422719f509
commit a4784fd5db
27 changed files with 551 additions and 111 deletions
@@ -1,7 +1,5 @@
using System.Text.Json.Serialization;
using AnthropicClient.Utils;
namespace AnthropicClient.Models;
/// <summary>
@@ -9,66 +7,8 @@ namespace AnthropicClient.Models;
/// </summary>
public class ChatMessageRequest : MessageRequest
{
/// <summary>
/// Gets the model ID to use for the request.
/// </summary>
public string Model { get; init; } = string.Empty;
/// <summary>
/// Gets the system ID to use for the request.
/// </summary>
public string? System { get; init; } = null;
/// <summary>
/// Gets the messages to send to the model.
/// </summary>
public List<ChatMessage> Messages { get; init; } = [];
/// <summary>
/// Gets the maximum number of tokens to generate.
/// </summary>
[JsonPropertyName("max_tokens")]
public int MaxTokens { get; init; } = 1024;
/// <summary>
/// Gets the metadata to include with the request.
/// </summary>
public Dictionary<string, object>? Metadata { get; init; } = null;
/// <summary>
/// Gets the prompt stop sequences.
/// </summary>
[JsonPropertyName("stop_sequences")]
public List<string> StopSequences { get; init; } = [];
/// <summary>
/// Gets the temperature to use for the request.
/// </summary>
public decimal Temperature { get; init; } = 0.0m;
/// <summary>
/// Gets the top-K value to use for the request.
/// </summary>
public int? TopK { get; init; } = null;
/// <summary>
/// Gets the top-P value to use for the request.
/// </summary>
public decimal? TopP { get; init; } = null;
/// <summary>
/// Gets the tool choice mode to use for the request.
/// </summary>
[JsonPropertyName("tool_choice")]
public ToolChoice? ToolChoice { get; init; } = null;
/// <summary>
/// Gets the tools to use for the request.
/// </summary>
public List<Tool>? Tools { get; init; } = null;
[JsonConstructor]
internal ChatMessageRequest() : base(false) { }
internal ChatMessageRequest() : base() { }
/// <summary>
/// Initializes a new instance of the <see cref="ChatMessageRequest"/> class.
@@ -100,40 +40,19 @@ public class ChatMessageRequest : MessageRequest
decimal? topP = null,
ToolChoice? toolChoice = null,
List<Tool>? tools = null
) : base(false)
) : base(
model,
messages,
maxTokens,
system,
metadata,
temperature,
topK,
topP,
toolChoice,
tools,
false
)
{
ArgumentValidator.ThrowIfNull(model, nameof(model));
ArgumentValidator.ThrowIfNull(messages, nameof(messages));
if (AnthropicModels.IsValidModel(model) is false)
{
throw new ArgumentException($"Invalid model ID: {model}");
}
if (messages.Count < 1)
{
throw new ArgumentException("Messages must contain at least one message");
}
if (maxTokens < 1)
{
throw new ArgumentException($"Invalid max tokens: {maxTokens}");
}
if (temperature < 0.0m || temperature > 1.0m)
{
throw new ArgumentException($"Invalid temperature: {temperature}");
}
Model = model;
Messages = messages;
MaxTokens = maxTokens;
System = system;
Metadata = metadata;
Temperature = temperature;
TopK = topK;
TopP = topP;
ToolChoice = toolChoice;
Tools = tools;
}
}