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:
@@ -14,6 +14,11 @@ public abstract class BaseMessageRequest
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Model { get; init; } = string.Empty;
|
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>
|
/// <summary>
|
||||||
/// Gets the system message that will be used as the system prompt if no system messages are provided.
|
/// Gets the system message that will be used as the system prompt if no system messages are provided.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -105,12 +110,33 @@ public abstract class BaseMessageRequest
|
|||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
internal BaseMessageRequest() { }
|
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,
|
string model,
|
||||||
List<Message> messages,
|
List<Message> messages,
|
||||||
int maxTokens,
|
int maxTokens,
|
||||||
string? system,
|
string? system,
|
||||||
List<TextContent>? systemMessages,
|
|
||||||
Dictionary<string, object>? metadata,
|
Dictionary<string, object>? metadata,
|
||||||
decimal temperature,
|
decimal temperature,
|
||||||
int? topK,
|
int? topK,
|
||||||
@@ -118,7 +144,8 @@ public abstract class BaseMessageRequest
|
|||||||
ToolChoice? toolChoice,
|
ToolChoice? toolChoice,
|
||||||
List<Tool>? tools,
|
List<Tool>? tools,
|
||||||
bool stream,
|
bool stream,
|
||||||
List<string>? stopSequences
|
List<string>? stopSequences,
|
||||||
|
List<TextContent>? systemMessages
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ArgumentValidator.ThrowIfNull(model, nameof(model));
|
ArgumentValidator.ThrowIfNull(model, nameof(model));
|
||||||
@@ -158,108 +185,4 @@ public abstract class BaseMessageRequest
|
|||||||
Stream = stream;
|
Stream = stream;
|
||||||
StopSequences = stopSequences ?? [];
|
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
|
|
||||||
)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ public class MessageRequest : BaseMessageRequest
|
|||||||
/// <param name="model">The model ID to use for the request.</param>
|
/// <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="messages">The messages to send to the model.</param>
|
||||||
/// <param name="maxTokens">The maximum number of tokens to generate.</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="metadata">The metadata to include with the request.</param>
|
||||||
/// <param name="temperature">The temperature to use for 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="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="toolChoice">The tool choice mode to use for the request.</param>
|
||||||
/// <param name="tools">The tools 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="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="ArgumentException">Thrown when the model ID is invalid.</exception>
|
||||||
/// <exception cref="ArgumentNullException">Thrown when the model or messages is null.</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 messages contain no messages.</exception>
|
||||||
@@ -41,7 +42,8 @@ public class MessageRequest : BaseMessageRequest
|
|||||||
decimal? topP = null,
|
decimal? topP = null,
|
||||||
ToolChoice? toolChoice = null,
|
ToolChoice? toolChoice = null,
|
||||||
List<Tool>? tools = null,
|
List<Tool>? tools = null,
|
||||||
List<string>? stopSequences = null
|
List<string>? stopSequences = null,
|
||||||
|
List<TextContent>? systemMessages = null
|
||||||
) : base(
|
) : base(
|
||||||
model,
|
model,
|
||||||
messages,
|
messages,
|
||||||
@@ -54,7 +56,8 @@ public class MessageRequest : BaseMessageRequest
|
|||||||
toolChoice,
|
toolChoice,
|
||||||
tools,
|
tools,
|
||||||
false,
|
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="model">The model ID to use for the request.</param>
|
||||||
/// <param name="messages">The messages to send to the model.</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="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="metadata">The metadata to include with the request.</param>
|
||||||
/// <param name="temperature">The temperature to use for 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="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="toolChoice">The tool choice mode to use for the request.</param>
|
||||||
/// <param name="tools">The tools 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="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="ArgumentException">Thrown when the model ID is invalid.</exception>
|
||||||
/// <exception cref="ArgumentNullException">Thrown when the model or messages is null.</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 messages contain no messages.</exception>
|
||||||
@@ -41,7 +42,8 @@ public class StreamMessageRequest : BaseMessageRequest
|
|||||||
decimal? topP = null,
|
decimal? topP = null,
|
||||||
ToolChoice? toolChoice = null,
|
ToolChoice? toolChoice = null,
|
||||||
List<Tool>? tools = null,
|
List<Tool>? tools = null,
|
||||||
List<string>? stopSequences = null
|
List<string>? stopSequences = null,
|
||||||
|
List<TextContent>? systemMessages = null
|
||||||
) : base(
|
) : base(
|
||||||
model,
|
model,
|
||||||
messages,
|
messages,
|
||||||
@@ -54,7 +56,8 @@ public class StreamMessageRequest : BaseMessageRequest
|
|||||||
toolChoice,
|
toolChoice,
|
||||||
tools,
|
tools,
|
||||||
true,
|
true,
|
||||||
stopSequences
|
stopSequences,
|
||||||
|
systemMessages
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user