fix: use additional constructor param with default value instead of overloaded constructor to avoid potentially breaking others code with that would then contain ambigious constructor calls.

This commit is contained in:
Stevan Freeborn
2024-08-16 13:49:50 -05:00
parent 900a7a3549
commit 90e9b9f75e
3 changed files with 42 additions and 113 deletions
+30 -107
View File
@@ -14,6 +14,11 @@ public abstract class BaseMessageRequest
/// </summary>
public string Model { get; init; } = string.Empty;
// TODO: I do not like this. I would prefer to have a single property that is a list of TextContent objects.
// This approach was taken to maintain compatibility with the API. As someone could be using the System property
// and changing it to a list of TextContent objects would break their code.
// However if an opportunity arises for a breaking change release, this should be changed.
/// <summary>
/// Gets the system message that will be used as the system prompt if no system messages are provided.
/// </summary>
@@ -105,12 +110,33 @@ public abstract class BaseMessageRequest
[JsonConstructor]
internal BaseMessageRequest() { }
private BaseMessageRequest(
/// <summary>
/// Initializes a new instance of the <see cref="BaseMessageRequest"/> class.
/// </summary>
/// <param name="model">The model ID to use for the request.</param>
/// <param name="messages">The messages to send to the model.</param>
/// <param name="maxTokens">The maximum number of tokens to generate.</param>
/// <param name="system">The system prompt to use for the request.</param>
/// <param name="metadata">The metadata to include with the request.</param>
/// <param name="temperature">The temperature to use for the request.</param>
/// <param name="topK">The top-K value to use for the request.</param>
/// <param name="topP">The top-P value to use for the request.</param>
/// <param name="toolChoice">The tool choice mode to use for the request.</param>
/// <param name="tools">The tools to use for the request.</param>
/// <param name="stream">A value indicating whether the message should be streamed.</param>
/// <param name="stopSequences">The prompt stop sequences.</param>
/// <param name="systemMessages">The system messages to use for the request.</param>
/// <exception cref="ArgumentException">Thrown when the model ID is invalid.</exception>
/// <exception cref="ArgumentNullException">Thrown when the model or messages is null.</exception>
/// <exception cref="ArgumentException">Thrown when the messages contain no messages.</exception>
/// <exception cref="ArgumentException">Thrown when the max tokens is less than one.</exception>
/// <exception cref="ArgumentException">Thrown when the temperature is less than zero or greater than one.</exception>
/// <returns>A new instance of the <see cref="BaseMessageRequest"/> class.</returns>
protected BaseMessageRequest(
string model,
List<Message> messages,
int maxTokens,
string? system,
List<TextContent>? systemMessages,
Dictionary<string, object>? metadata,
decimal temperature,
int? topK,
@@ -118,7 +144,8 @@ public abstract class BaseMessageRequest
ToolChoice? toolChoice,
List<Tool>? tools,
bool stream,
List<string>? stopSequences
List<string>? stopSequences,
List<TextContent>? systemMessages
)
{
ArgumentValidator.ThrowIfNull(model, nameof(model));
@@ -158,108 +185,4 @@ public abstract class BaseMessageRequest
Stream = stream;
StopSequences = stopSequences ?? [];
}
/// <summary>
/// Initializes a new instance of the <see cref="BaseMessageRequest"/> class.
/// </summary>
/// <param name="model">The model ID to use for the request.</param>
/// <param name="messages">The messages to send to the model.</param>
/// <param name="maxTokens">The maximum number of tokens to generate.</param>
/// <param name="system">The system prompt to use for the request.</param>
/// <param name="metadata">The metadata to include with the request.</param>
/// <param name="temperature">The temperature to use for the request.</param>
/// <param name="topK">The top-K value to use for the request.</param>
/// <param name="topP">The top-P value to use for the request.</param>
/// <param name="toolChoice">The tool choice mode to use for the request.</param>
/// <param name="tools">The tools to use for the request.</param>
/// <param name="stream">A value indicating whether the message should be streamed.</param>
/// <param name="stopSequences">The prompt stop sequences.</param>
/// <exception cref="ArgumentException">Thrown when the model ID is invalid.</exception>
/// <exception cref="ArgumentNullException">Thrown when the model or messages is null.</exception>
/// <exception cref="ArgumentException">Thrown when the messages contain no messages.</exception>
/// <exception cref="ArgumentException">Thrown when the max tokens is less than one.</exception>
/// <exception cref="ArgumentException">Thrown when the temperature is less than zero or greater than one.</exception>
/// <returns>A new instance of the <see cref="BaseMessageRequest"/> class.</returns>
protected BaseMessageRequest(
string model,
List<Message> messages,
int maxTokens = 1024,
string? system = null,
Dictionary<string, object>? metadata = null,
decimal temperature = 0.0m,
int? topK = null,
decimal? topP = null,
ToolChoice? toolChoice = null,
List<Tool>? tools = null,
bool stream = false,
List<string>? stopSequences = null
) : this(
model,
messages,
maxTokens,
system,
null,
metadata,
temperature,
topK,
topP,
toolChoice,
tools,
stream,
stopSequences
)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="BaseMessageRequest"/> class.
/// </summary>
/// <param name="model">The model ID to use for the request.</param>
/// <param name="messages">The messages to send to the model.</param>
/// <param name="maxTokens">The maximum number of tokens to generate.</param>
/// <param name="systemMessages">The system messages to send to the model to be used as the system prompt.</param>
/// <param name="metadata">The metadata to include with the request.</param>
/// <param name="temperature">The temperature to use for the request.</param>
/// <param name="topK">The top-K value to use for the request.</param>
/// <param name="topP">The top-P value to use for the request.</param>
/// <param name="toolChoice">The tool choice mode to use for the request.</param>
/// <param name="tools">The tools to use for the request.</param>
/// <param name="stream">A value indicating whether the message should be streamed.</param>
/// <param name="stopSequences">The prompt stop sequences.</param>
/// <exception cref="ArgumentException">Thrown when the model ID is invalid.</exception>
/// <exception cref="ArgumentNullException">Thrown when the model or messages is null.</exception>
/// <exception cref="ArgumentException">Thrown when the messages contain no messages.</exception>
/// <exception cref="ArgumentException">Thrown when the max tokens is less than one.</exception>
/// <exception cref="ArgumentException">Thrown when the temperature is less than zero or greater than one.</exception>
/// <returns>A new instance of the <see cref="BaseMessageRequest"/> class.</returns>
protected BaseMessageRequest(
string model,
List<Message> messages,
int maxTokens = 1024,
List<TextContent>? systemMessages = null,
Dictionary<string, object>? metadata = null,
decimal temperature = 0.0m,
int? topK = null,
decimal? topP = null,
ToolChoice? toolChoice = null,
List<Tool>? tools = null,
bool stream = false,
List<string>? stopSequences = null
) : this(
model,
messages,
maxTokens,
null,
systemMessages,
metadata,
temperature,
topK,
topP,
toolChoice,
tools,
stream,
stopSequences
)
{
}
}
+6 -3
View File
@@ -16,7 +16,7 @@ public class MessageRequest : BaseMessageRequest
/// <param name="model">The model ID to use for the request.</param>
/// <param name="messages">The messages to send to the model.</param>
/// <param name="maxTokens">The maximum number of tokens to generate.</param>
/// <param name="system">The system ID to use for the request.</param>
/// <param name="system">The system prompt to use for the request.</param>
/// <param name="metadata">The metadata to include with the request.</param>
/// <param name="temperature">The temperature to use for the request.</param>
/// <param name="topK">The top-K value to use for the request.</param>
@@ -24,6 +24,7 @@ public class MessageRequest : BaseMessageRequest
/// <param name="toolChoice">The tool choice mode to use for the request.</param>
/// <param name="tools">The tools to use for the request.</param>
/// <param name="stopSequences">The prompt stop sequences.</param>
/// <param name="systemMessages">The system messages to include with the request.</param>
/// <exception cref="ArgumentException">Thrown when the model ID is invalid.</exception>
/// <exception cref="ArgumentNullException">Thrown when the model or messages is null.</exception>
/// <exception cref="ArgumentException">Thrown when the messages contain no messages.</exception>
@@ -41,7 +42,8 @@ public class MessageRequest : BaseMessageRequest
decimal? topP = null,
ToolChoice? toolChoice = null,
List<Tool>? tools = null,
List<string>? stopSequences = null
List<string>? stopSequences = null,
List<TextContent>? systemMessages = null
) : base(
model,
messages,
@@ -54,7 +56,8 @@ public class MessageRequest : BaseMessageRequest
toolChoice,
tools,
false,
stopSequences
stopSequences,
systemMessages
)
{
}
@@ -16,7 +16,7 @@ public class StreamMessageRequest : BaseMessageRequest
/// <param name="model">The model ID to use for the request.</param>
/// <param name="messages">The messages to send to the model.</param>
/// <param name="maxTokens">The maximum number of tokens to generate.</param>
/// <param name="system">The system ID to use for the request.</param>
/// <param name="system">The system prompt to use for the request.</param>
/// <param name="metadata">The metadata to include with the request.</param>
/// <param name="temperature">The temperature to use for the request.</param>
/// <param name="topK">The top-K value to use for the request.</param>
@@ -24,6 +24,7 @@ public class StreamMessageRequest : BaseMessageRequest
/// <param name="toolChoice">The tool choice mode to use for the request.</param>
/// <param name="tools">The tools to use for the request.</param>
/// <param name="stopSequences">The prompt stop sequences.</param>
/// <param name="systemMessages">The system messages to include with the request.</param>
/// <exception cref="ArgumentException">Thrown when the model ID is invalid.</exception>
/// <exception cref="ArgumentNullException">Thrown when the model or messages is null.</exception>
/// <exception cref="ArgumentException">Thrown when the messages contain no messages.</exception>
@@ -41,7 +42,8 @@ public class StreamMessageRequest : BaseMessageRequest
decimal? topP = null,
ToolChoice? toolChoice = null,
List<Tool>? tools = null,
List<string>? stopSequences = null
List<string>? stopSequences = null,
List<TextContent>? systemMessages = null
) : base(
model,
messages,
@@ -54,7 +56,8 @@ public class StreamMessageRequest : BaseMessageRequest
toolChoice,
tools,
true,
stopSequences
stopSequences,
systemMessages
)
{
}