mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 04:27:21 +00:00
35 lines
1.7 KiB
C#
35 lines
1.7 KiB
C#
using System.Text.Json;
|
|
|
|
using AIStudio.Provider;
|
|
|
|
namespace AIStudio.Tests.Serialization;
|
|
|
|
/// <summary>
|
|
/// Writes requests the way AI Studio sends them, and checks that they get sent just as before.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The files in the folder Fixtures were written with the contracts of reflection, before AI Studio got
|
|
/// contracts of its own. A provider reads every byte of a request, and one which got written otherwise, e.g.,
|
|
/// with a field under another name or without the tools, gets refused or misread. The requests are made up,
|
|
/// see <see cref="JsonSampleRequests"/>.
|
|
/// </remarks>
|
|
[TestFixture]
|
|
public sealed class JsonGoldenRequestTests
|
|
{
|
|
private static IEnumerable<JsonGoldenRequest> GoldenRequests()
|
|
{
|
|
TestHost.PrepareStaticState();
|
|
yield return new("chat-completion-request.json", JsonSampleRequests.ChatCompletion, ProviderJsonOptions.OPTIONS);
|
|
yield return new("responses-request.json", JsonSampleRequests.Responses, ProviderJsonOptions.OPTIONS);
|
|
yield return new("anthropic-messages-request.json", () => JsonSampleRequests.Anthropic(), ProviderJsonOptions.OPTIONS);
|
|
yield return new("embedding-request.json", JsonSampleRequests.Embedding, ProviderJsonOptions.OPTIONS);
|
|
yield return new("google-embedding-request.json", JsonSampleRequests.GoogleEmbedding, ProviderJsonOptions.OPTIONS);
|
|
}
|
|
|
|
[TestCaseSource(nameof(GoldenRequests))]
|
|
public void ARequestIsSentAsBefore(JsonGoldenRequest goldenRequest)
|
|
{
|
|
var request = goldenRequest.Create();
|
|
Assert.That(JsonSerializer.Serialize(request, request.GetType(), goldenRequest.Options), Is.EqualTo(JsonGoldenFileTests.ReadFixture(goldenRequest.FileName)));
|
|
}
|
|
} |