tests: update tests to account for serialization and deserialization changes with new/modified model properties to support caching

This commit is contained in:
Stevan Freeborn
2024-08-16 09:21:43 -05:00
parent 66008717e1
commit 900a7a3549
10 changed files with 137 additions and 31 deletions
@@ -191,6 +191,8 @@ public class AnthropicApiClient : IAnthropicApiClient
{
InputTokens = existingUsage.InputTokens + msgDeltaData.Usage.InputTokens,
OutputTokens = existingUsage.OutputTokens + msgDeltaData.Usage.OutputTokens,
CacheCreationInputTokens = existingUsage.CacheCreationInputTokens + msgDeltaData.Usage.CacheCreationInputTokens,
CacheReadInputTokens = existingUsage.CacheReadInputTokens + msgDeltaData.Usage.CacheReadInputTokens,
};
msgResponse = new MessageResponse()
@@ -17,7 +17,6 @@ static class JsonSerializationOptions
new EventDataConverter(),
new ContentDeltaConverter(),
new JsonStringEnumConverter(),
new MessageRequestConverter(),
},
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
};
@@ -15,15 +15,40 @@ public abstract class BaseMessageRequest
public string Model { get; init; } = string.Empty;
/// <summary>
/// Gets the system prompt to use for the request.
/// Gets the system message that will be used as the system prompt if no system messages are provided.
/// </summary>
[JsonIgnore]
public string? System { get; init; } = null;
/// <summary>
/// Gets the messages to send to the model.
/// Gets the system messages to send to the model to be used as the system prompt.
/// </summary>
[JsonIgnore]
public List<TextContent>? SystemMessages { get; init; } = null;
/// <summary>
/// Gets the system prompt that will be used for the request.
/// If will return the system messages if they are provided, otherwise it will return the system message.
/// If neither are provided, it will return null.
/// </summary>
[JsonPropertyName("system")]
public List<TextContent>? SystemPrompt => GetSystemPrompt();
private List<TextContent>? GetSystemPrompt()
{
if (SystemMessages is not null)
{
return SystemMessages;
}
if (System is not null)
{
return [new TextContent(System)];
}
return null;
}
/// <summary>
/// Gets the messages to send to the model.
/// </summary>