From 2d56ecbf27173a6bd3091b9d3f73faf81b1be52e Mon Sep 17 00:00:00 2001 From: Darren Reid Date: Mon, 25 Nov 2024 17:27:32 +1100 Subject: [PATCH] Refactor based on discussion about status endpoints and how they should be more consistently typed. - Split GenerationResponse to ArtifactGenerationResponse and TextGenerationResponse. - Added ffmpeg to use artifact generation response. - Got specific APIs to return specific generation response and use consistent `Results`. Down stream tests and apps will need to be updated to prep for release. --- .../GenerationServices.cs | 56 +++++++++++++------ .../OpenAiChatServices.cs | 2 +- AiServer.ServiceInterface/VideoServices.cs | 6 +- AiServer.ServiceModel/Generations.cs | 38 ++++++++++--- AiServer.ServiceModel/MediaTransforms.cs | 37 ++++-------- AiServer.ServiceModel/OpenAiChatServer.cs | 6 +- AiServer.ServiceModel/QueueGenerations.cs | 52 +++++++++++++---- AiServer.ServiceModel/QueueMediaTransforms.cs | 2 +- AiServer.Tests/AudioIntegrationTests.cs | 36 ++++++------ AiServer.Tests/ImageServiceTests.cs | 42 +++++++------- AiServer.Tests/ImageToTextTests.cs | 8 +-- AiServer.Tests/OpenAiChatTaskTests.cs | 8 +-- AiServer.Tests/QueueImageServiceTests.cs | 40 ++++++------- AiServer.Tests/QueueImageToImageTests.cs | 6 +- AiServer.Tests/QueueImageToTextTests.cs | 6 +- AiServer.Tests/QueueImageUpscaleTests.cs | 6 +- AiServer.Tests/QueueImageWithMaskTests.cs | 6 +- AiServer.Tests/QueueSpeechToTextTests.cs | 20 +++---- AiServer.Tests/QueueTextToImageTests.cs | 6 +- AiServer.Tests/QueueTextToSpeechTests.cs | 12 ++-- AiServer.Tests/SpeechToTextTests.cs | 16 +++--- AiServer.Tests/TextToImageTests.cs | 8 +-- AiServer.Tests/VideoIntegrationTests.cs | 46 +++++++-------- 23 files changed, 263 insertions(+), 202 deletions(-) diff --git a/AiServer.ServiceInterface/GenerationServices.cs b/AiServer.ServiceInterface/GenerationServices.cs index e50d66f..eb432e3 100644 --- a/AiServer.ServiceInterface/GenerationServices.cs +++ b/AiServer.ServiceInterface/GenerationServices.cs @@ -9,7 +9,7 @@ namespace AiServer.ServiceInterface; public class GenerationServices(IBackgroundJobs jobs, AppData appData) : Service { - public async Task Any(GetJobStatus request) + public async Task Any(GetArtifactGenerationStatus request) { JobResult? job = null; if (request.JobId != null) @@ -22,17 +22,17 @@ public async Task Any(GetJobStatus request) job = jobs.GetJobByRefId(request.RefId); } - if(job == null || job.Summary.RefId == null) + if(job == null || job.Job == null || job.Summary.RefId == null) throw HttpError.NotFound("Job not found"); // We know at this point, we definitely have a job JobResult queuedJob = job; - var completedResponse = new GetJobStatusResponse + var completedResponse = new GetArtifactGenerationStatusResponse { RefId = queuedJob.Job?.RefId ?? queuedJob.Summary.RefId, JobId = queuedJob.Job?.Id ?? queuedJob.Summary.Id, - Status = queuedJob.Job?.Status, + Status = queuedJob.Job?.Status ?? queuedJob.Job!.State.ToString(), JobState = queuedJob.Job?.State ?? queuedJob.Summary.State }; @@ -47,8 +47,7 @@ public async Task Any(GetJobStatus request) // Process successful job results var outputs = queuedJob.GetOutputs(); - completedResponse.Outputs = outputs.Item1; - completedResponse.TextOutputs = outputs.Item2; + completedResponse.Results = outputs.Item1; return completedResponse; } @@ -89,7 +88,8 @@ public async Task Any(TextToImage request) }; await using var diffServices = ResolveService(); - return await diffRequest.ProcessGeneration(jobs, diffServices, sync: true); + var result = await diffRequest.ProcessGeneration(jobs, diffServices, sync: true) as GenerationResponse; + return result.ConvertTo(); } public async Task Any(ImageToImage request) @@ -110,7 +110,8 @@ public async Task Any(ImageToImage request) }; await using var diffServices = ResolveService(); - return await diffRequest.ProcessGeneration(jobs, diffServices, sync: true); + var result = await diffRequest.ProcessGeneration(jobs, diffServices, sync: true) as GenerationResponse; + return result.ConvertTo(); } public async Task Any(ImageUpscale request) @@ -127,7 +128,8 @@ public async Task Any(ImageUpscale request) }; await using var diffServices = ResolveService(); - return await diffRequest.ProcessGeneration(jobs, diffServices, sync: true); + var result = await diffRequest.ProcessGeneration(jobs, diffServices, sync: true) as GenerationResponse; + return result.ConvertTo(); } public async Task Any(ImageWithMask request) @@ -148,7 +150,8 @@ public async Task Any(ImageWithMask request) }; await using var diffServices = ResolveService(); - return await diffRequest.ProcessGeneration(jobs, diffServices, sync: true); + var result = await diffRequest.ProcessGeneration(jobs, diffServices, sync: true) as GenerationResponse; + return result.ConvertTo(); } public async Task Any(ImageToText request) @@ -164,7 +167,8 @@ public async Task Any(ImageToText request) }; await using var diffServices = ResolveService(); - return await diffRequest.ProcessGeneration(jobs, diffServices, sync: true); + var result = await diffRequest.ProcessGeneration(jobs, diffServices, sync: true) as GenerationResponse; + return result.ConvertTo(); } } @@ -201,7 +205,7 @@ public static async Task ProcessGeneration(this CreateGeneration diffReq // Return the job status URL var jobStatusUrl = AppConfig.Instance.ApplicationBaseUrl.CombineWith( - $"/api/{nameof(GetJobStatus)}?RefId=" + diffResponse.RefId); + $"/api/{nameof(GetArtifactGenerationStatus)}?RefId=" + diffResponse.RefId); var queueResponse = new QueueGenerationResponse { @@ -209,7 +213,7 @@ public static async Task ProcessGeneration(this CreateGeneration diffReq JobId = diffResponse.Id, Status = queuedJob.Job?.Status, JobState = queuedJob.Job?.State ?? queuedJob.Summary.State, - StatusUrl = jobStatusUrl + StatusUrl = GetStatusUrl(diffRequest, diffResponse) }; // Handle failed jobs @@ -224,10 +228,7 @@ public static async Task ProcessGeneration(this CreateGeneration diffReq return queueResponse; } - var completedResponse = new GenerationResponse() - { - - }; + var completedResponse = new GenerationResponse { }; // Wait for the job to complete max 1 minute var timeout = DateTime.UtcNow.AddMinutes(1); @@ -262,6 +263,27 @@ public static async Task ProcessGeneration(this CreateGeneration diffReq return completedResponse; } + + public static string GetStatusUrl(this CreateGeneration request, CreateGenerationResponse response) + { + switch (request.Request.TaskType) + { + case AiTaskType.TextToImage: + case AiTaskType.ImageToImage: + case AiTaskType.ImageUpscale: + case AiTaskType.ImageWithMask: + case AiTaskType.TextToSpeech: + case AiTaskType.TextToAudio: + return AppConfig.Instance.ApplicationBaseUrl.CombineWith( + $"/api/{nameof(GetArtifactGenerationStatus)}?RefId=" + response.RefId); + case AiTaskType.SpeechToText: + case AiTaskType.ImageToText: + return AppConfig.Instance.ApplicationBaseUrl.CombineWith( + $"/api/{nameof(GetTextGenerationStatus)}?RefId=" + response.RefId); + default: + throw new ArgumentOutOfRangeException(); + } + } public static Tuple?,List?> GetOutputs(this JobResult? job) { diff --git a/AiServer.ServiceInterface/OpenAiChatServices.cs b/AiServer.ServiceInterface/OpenAiChatServices.cs index df0964b..f06d0db 100644 --- a/AiServer.ServiceInterface/OpenAiChatServices.cs +++ b/AiServer.ServiceInterface/OpenAiChatServices.cs @@ -320,7 +320,7 @@ public async Task Get(GetOpenAiChatStatus request) RefId = request.RefId, JobState = job.State, Status = job.State.ToString(), - ChatResponse = chatResponse, + Result = chatResponse, }; } diff --git a/AiServer.ServiceInterface/VideoServices.cs b/AiServer.ServiceInterface/VideoServices.cs index f96bdb2..87fafff 100644 --- a/AiServer.ServiceInterface/VideoServices.cs +++ b/AiServer.ServiceInterface/VideoServices.cs @@ -337,7 +337,7 @@ public static async Task ProcessTransform(this CreateMediaTransform medi // Return the job status URL var jobStatusUrl = AppConfig.Instance.ApplicationBaseUrl.CombineWith( - $"/api/{nameof(GetJobStatus)}?RefId=" + transformResponse.RefId); + $"/api/{nameof(GetArtifactGenerationStatus)}?RefId=" + transformResponse.RefId); var queueTransformResponse = new QueueMediaTransformResponse { @@ -360,7 +360,7 @@ public static async Task ProcessTransform(this CreateMediaTransform medi return queueTransformResponse; } - var completedResponse = new MediaTransformResponse(); + var completedResponse = new ArtifactGenerationResponse(); // Wait for the job to complete max 1 minute var timeout = DateTime.UtcNow.AddMinutes(1); @@ -376,7 +376,7 @@ public static async Task ProcessTransform(this CreateMediaTransform medi var outputs = queuedJob.GetOutputs(); - completedResponse.Outputs = outputs.Item1; + completedResponse.Results = outputs.Item1; return completedResponse; } } \ No newline at end of file diff --git a/AiServer.ServiceModel/Generations.cs b/AiServer.ServiceModel/Generations.cs index d0938ac..f0b57fe 100644 --- a/AiServer.ServiceModel/Generations.cs +++ b/AiServer.ServiceModel/Generations.cs @@ -13,7 +13,7 @@ public class ActiveMediaModels : IGet, IReturn {} [Api("Convert speech to text")] [Description("Transcribe audio content to text")] [SystemJson(UseSystemJson.Response)] -public class SpeechToText : IGeneration, IReturn +public class SpeechToText : IGeneration, IReturn { [ApiMember(Description = "The audio stream containing the speech to be transcribed")] [Description("The audio stream containing the speech to be transcribed")] @@ -35,7 +35,7 @@ public class SpeechToText : IGeneration, IReturn [Api("Convert text to speech")] [Description("Generate speech audio from text input")] [SystemJson(UseSystemJson.Response)] -public class TextToSpeech : IGeneration, IReturn +public class TextToSpeech : IGeneration, IReturn { [ApiMember(Description = "The text to be converted to speech")] [Description("The text to be converted to speech")] @@ -65,7 +65,7 @@ public class TextToSpeech : IGeneration, IReturn [Api("Generate image from text description")] [Description("Create an image based on a text prompt")] [SystemJson(UseSystemJson.Response)] -public class TextToImage : IGeneration, IReturn +public class TextToImage : IGeneration, IReturn { [ApiMember(Description = "The main prompt describing the desired image")] [Description("The main prompt describing the desired image")] @@ -116,7 +116,7 @@ public class TextToImage : IGeneration, IReturn [Api("Generate image from another image")] [Description("Create a new image based on an existing image and a text prompt")] [SystemJson(UseSystemJson.Response)] -public class ImageToImage : IGeneration, IReturn +public class ImageToImage : IGeneration, IReturn { [ApiMember(Description = "The image to use as input")] [Description("The image to use as input")] @@ -168,7 +168,7 @@ public class ImageToImage : IGeneration, IReturn [Api("Upscale an image")] [Description("Increase the resolution and quality of an input image")] [SystemJson(UseSystemJson.Response)] -public class ImageUpscale : IGeneration, IReturn +public class ImageUpscale : IGeneration, IReturn { [ApiMember(Description = "The image to upscale")] [Description("The image to upscale")] @@ -195,7 +195,7 @@ public class ImageUpscale : IGeneration, IReturn [Api("Generate image with masked area")] [Description("Create a new image by applying a mask to an existing image and generating content for the masked area")] [SystemJson(UseSystemJson.Response)] -public class ImageWithMask : IGeneration, IReturn +public class ImageWithMask : IGeneration, IReturn { [ApiMember(Description = "Prompt describing the desired output in the masked area")] [Description("Prompt describing the desired output in the masked area")] @@ -244,7 +244,7 @@ public class ImageWithMask : IGeneration, IReturn [Api("Convert image to text")] [Description("Extract text content from an image")] [SystemJson(UseSystemJson.Response)] -public class ImageToText : IGeneration, IReturn +public class ImageToText : IGeneration, IReturn { [ApiMember(Description = "The image to convert to text")] [Description("The image to convert to text")] @@ -261,6 +261,30 @@ public class ImageToText : IGeneration, IReturn public string? Tag { get; set; } } +[Description("Response object for artifact generation requests")] +public class ArtifactGenerationResponse +{ + [ApiMember(Description = "List of generated outputs")] + [Description("List of generated outputs")] + public List? Results { get; set; } + + [ApiMember(Description = "Detailed response status information")] + [Description("Detailed response status information")] + public ResponseStatus? ResponseStatus { get; set; } +} + +[Description("Response object for text generation requests")] +public class TextGenerationResponse +{ + [ApiMember(Description = "List of generated text outputs")] + [Description("List of generated text outputs")] + public List? Results { get; set; } + + [ApiMember(Description = "Detailed response status information")] + [Description("Detailed response status information")] + public ResponseStatus? ResponseStatus { get; set; } +} + [Description("Response object for generation requests")] public class GenerationResponse { diff --git a/AiServer.ServiceModel/MediaTransforms.cs b/AiServer.ServiceModel/MediaTransforms.cs index 08d6b0a..f3190a2 100644 --- a/AiServer.ServiceModel/MediaTransforms.cs +++ b/AiServer.ServiceModel/MediaTransforms.cs @@ -7,7 +7,7 @@ namespace AiServer.ServiceModel; [Tag(Tags.Media)] [Api("Scale video")] [Description("Scale a video to specified dimensions")] -public class ScaleVideo : IMediaTransform, IReturn +public class ScaleVideo : IMediaTransform, IReturn { [ApiMember(Description = "The video file to be scaled")] [Description("The video file to be scaled")] @@ -38,7 +38,7 @@ public class ScaleVideo : IMediaTransform, IReturn [Tag(Tags.Media)] [Api("Watermark video")] [Description("Add a watermark to a video")] -public class WatermarkVideo : IMediaTransform, IReturn +public class WatermarkVideo : IMediaTransform, IReturn { [ApiMember(Description = "The video file to be watermarked")] [Description("The video file to be watermarked")] @@ -78,7 +78,7 @@ public enum WatermarkPosition [Description("Convert an image to a different format")] [Tag(Tags.Media)] [ValidateApiKey] -public class ConvertImage : IMediaTransform, IPost, IReturn +public class ConvertImage : IMediaTransform, IPost, IReturn { [ApiMember(Description = "The image file to be converted")] [Description("The image file to be converted")] @@ -103,7 +103,7 @@ public class ConvertImage : IMediaTransform, IPost, IReturn +public class CropImage : IMediaTransform, IPost, IReturn { [ApiMember(Description = "The X-coordinate of the top-left corner of the crop area")] [Description("The X-coordinate of the top-left corner of the crop area")] @@ -139,7 +139,7 @@ public class CropImage : IMediaTransform, IPost, IReturn [Description("Scale an image to a specified size")] [Tag(Tags.Media)] [ValidateApiKey] -public class ScaleImage : IMediaTransform, IPost, IReturn +public class ScaleImage : IMediaTransform, IPost, IReturn { [ApiMember(Description = "The image file to be scaled")] [Description("The image file to be scaled")] @@ -167,7 +167,7 @@ public class ScaleImage : IMediaTransform, IPost, IReturn +public class WatermarkImage : IMediaTransform, IPost, IReturn { [ApiMember(Description = "The image file to be watermarked")] [Description("The image file to be watermarked")] @@ -199,7 +199,7 @@ public class WatermarkImage : IMediaTransform, IPost, IReturn +public class ConvertVideo : IMediaTransform, IReturn { [ApiMember(Description = "The desired output format for the converted video")] [Description("The desired output format for the converted video")] @@ -222,7 +222,7 @@ public class ConvertVideo : IMediaTransform, IReturn [Description("Crop a video to a specified area")] [Tag(Tags.Media)] [ValidateApiKey] -public class CropVideo : IMediaTransform, IReturn +public class CropVideo : IMediaTransform, IReturn { [ApiMember(Description = "The X-coordinate of the top-left corner of the crop area")] [Description("The X-coordinate of the top-left corner of the crop area")] @@ -264,7 +264,7 @@ public class CropVideo : IMediaTransform, IReturn [Description("Trim a video to a specified duration via start and end times")] [Tag(Tags.Media)] [ValidateApiKey] -public class TrimVideo : IMediaTransform, IReturn +public class TrimVideo : IMediaTransform, IReturn { [ApiMember(Description = "The start time of the trimmed video (format: MM:SS)")] [Description("The start time of the trimmed video (format: MM:SS)")] @@ -291,7 +291,7 @@ public class TrimVideo : IMediaTransform, IReturn [Description("Convert an audio file to a different format")] [Tag(Tags.Media)] [ValidateApiKey] -public class ConvertAudio : IMediaTransform, IReturn +public class ConvertAudio : IMediaTransform, IReturn { [ApiMember(Description = "The desired output format for the converted audio")] [Description("The desired output format for the converted audio")] @@ -315,21 +315,4 @@ public interface IMediaTransform { public string? RefId { get; set; } public string? Tag { get; set; } -} - -[Description("Response object for transform requests")] -public class MediaTransformResponse -{ - - [ApiMember(Description = "List of generated outputs")] - [Description("List of generated outputs")] - public List? Outputs { get; set; } - - [ApiMember(Description = "List of generated text outputs")] - [Description("List of generated text outputs")] - public List? TextOutputs { get; set; } - - [ApiMember(Description = "Detailed response status information")] - [Description("Detailed response status information")] - public ResponseStatus? ResponseStatus { get; set; } } \ No newline at end of file diff --git a/AiServer.ServiceModel/OpenAiChatServer.cs b/AiServer.ServiceModel/OpenAiChatServer.cs index aec118c..50294fe 100644 --- a/AiServer.ServiceModel/OpenAiChatServer.cs +++ b/AiServer.ServiceModel/OpenAiChatServer.cs @@ -48,9 +48,9 @@ public class GetOpenAiChatStatusResponse [Description("Detailed response status information")] public ResponseStatus? ResponseStatus { get; set; } - [ApiMember(Description = "Chat response")] - [Description("Chat response")] - public OpenAiChatResponse? ChatResponse { get; set; } + [ApiMember(Description = "Chat result")] + [Description("Chat result")] + public OpenAiChatResponse? Result { get; set; } } [Tag(Tags.AiInfo)] diff --git a/AiServer.ServiceModel/QueueGenerations.cs b/AiServer.ServiceModel/QueueGenerations.cs index 7efa9cb..3c46318 100644 --- a/AiServer.ServiceModel/QueueGenerations.cs +++ b/AiServer.ServiceModel/QueueGenerations.cs @@ -8,7 +8,7 @@ namespace AiServer.ServiceModel; [Tag(Tags.AI)] [Api("Convert speech to text")] [Description("Transcribe audio content to text")] -public class QueueSpeechToText : IQueueGeneration, IReturn +public class QueueSpeechToText : IQueueGeneration, IReturn { [ApiMember(Description = "The audio stream containing the speech to be transcribed")] [Description("The audio stream containing the speech to be transcribed")] @@ -329,7 +329,7 @@ public interface IQueueGeneration [Tag(Tags.Admin)] [Api("Get job status")] [Description("Retrieve the status of a background job")] -public class GetJobStatus : IGet, IReturn +public class GetArtifactGenerationStatus : IGet, IReturn { [ApiMember(Description = "Unique identifier of the background job")] [Description("Unique identifier of the background job")] @@ -340,7 +340,7 @@ public class GetJobStatus : IGet, IReturn public string? RefId { get; set; } } -public class GetJobStatusResponse +public class GetArtifactGenerationStatusResponse { [ApiMember(Description = "Unique identifier of the background job")] [Description("Unique identifier of the background job")] @@ -356,21 +356,53 @@ public class GetJobStatusResponse [ApiMember(Description = "Current status of the generation request")] [Description("Current status of the generation request")] - public string? Status { get; set; } + public string Status { get; set; } [ApiMember(Description = "List of generated outputs")] [Description("List of generated outputs")] - public List? Outputs { get; set; } - - [ApiMember(Description = "List of generated text outputs")] - [Description("List of generated text outputs")] - public List? TextOutputs { get; set; } + public List? Results { get; set; } [ApiMember(Description = "Detailed response status information")] [Description("Detailed response status information")] public ResponseStatus? ResponseStatus { get; set; } +} + +public class GetTextGenerationStatus : IGet, IReturn +{ + [ApiMember(Description = "Unique identifier of the background job")] + [Description("Unique identifier of the background job")] + public long? JobId { get; set; } + + [ApiMember(Description = "Client-provided identifier for the request")] + [Description("Client-provided identifier for the request")] + public string? RefId { get; set; } +} + +public class GetTextGenerationStatusResponse +{ + [ApiMember(Description = "Unique identifier of the background job")] + [Description("Unique identifier of the background job")] + public long JobId { get; set; } + + [ApiMember(Description = "Client-provided identifier for the request")] + [Description("Client-provided identifier for the request")] + public string RefId { get; set; } + + [ApiMember(Description = "Current state of the background job")] + [Description("Current state of the background job")] + public BackgroundJobState JobState { get; set; } + + [ApiMember(Description = "Current status of the generation request")] + [Description("Current status of the generation request")] + public string Status { get; set; } - + [ApiMember(Description = "Generated text")] + [Description("Generated text")] + public List? Results { get; set; } + + [ApiMember(Description = "Detailed response status information")] + [Description("Detailed response status information")] + public ResponseStatus? ResponseStatus { get; set; } } public class QueueGenerationResponse diff --git a/AiServer.ServiceModel/QueueMediaTransforms.cs b/AiServer.ServiceModel/QueueMediaTransforms.cs index 1926d78..c909ef1 100644 --- a/AiServer.ServiceModel/QueueMediaTransforms.cs +++ b/AiServer.ServiceModel/QueueMediaTransforms.cs @@ -220,7 +220,7 @@ public class QueueWatermarkImage : IQueueMediaTransform, IPost, IReturn +public class QueueScaleImage : IQueueMediaTransform,IPost, IReturn { [ApiMember(Description = "The image file to be scaled")] [Description("The image file to be scaled")] diff --git a/AiServer.Tests/AudioIntegrationTests.cs b/AiServer.Tests/AudioIntegrationTests.cs index f08c5d7..efd8f17 100644 --- a/AiServer.Tests/AudioIntegrationTests.cs +++ b/AiServer.Tests/AudioIntegrationTests.cs @@ -14,12 +14,12 @@ public async Task Can_convert_audio_to_mp3() { var client = CreateClient(); - MediaTransformResponse response = null; + ArtifactGenerationResponse response = null; try { var inputAudioPath = "files/test_audio.wav"; await using var audioStream = File.OpenRead(inputAudioPath); - response = client.PostFilesWithRequest(new ConvertAudio + response = client.PostFilesWithRequest(new ConvertAudio { OutputFormat = AudioFormat.MP3 }, [ @@ -33,12 +33,12 @@ public async Task Can_convert_audio_to_mp3() Assert.That(response, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Empty); - Assert.That(response.Outputs[0].FileName, Does.EndWith(".mp3")); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results, Is.Not.Empty); + Assert.That(response.Results[0].FileName, Does.EndWith(".mp3")); // Test download - var downloadResponse = await client.GetHttpClient().GetStreamAsync(response.Outputs[0].Url); + var downloadResponse = await client.GetHttpClient().GetStreamAsync(response.Results[0].Url); Assert.That(downloadResponse, Is.Not.Null); // Save to disk var audioPath = "files/test_audio.mp3"; @@ -58,11 +58,11 @@ public async Task Can_convert_audio_to_wav() { var client = CreateClient(); - MediaTransformResponse response = null; + ArtifactGenerationResponse response = null; try { await using var audioStream = File.OpenRead("files/test_audio.mp3"); - response = client.PostFilesWithRequest(new ConvertAudio + response = client.PostFilesWithRequest(new ConvertAudio { OutputFormat = AudioFormat.WAV }, [ @@ -76,12 +76,12 @@ public async Task Can_convert_audio_to_wav() Assert.That(response, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Empty); - Assert.That(response.Outputs[0].FileName, Does.EndWith(".wav")); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results, Is.Not.Empty); + Assert.That(response.Results[0].FileName, Does.EndWith(".wav")); // Test download - var downloadResponse = await client.GetHttpClient().GetStreamAsync(response.Outputs[0].Url); + var downloadResponse = await client.GetHttpClient().GetStreamAsync(response.Results[0].Url); Assert.That(downloadResponse, Is.Not.Null); // Save to disk var audioPath = "files/test_audio.wav"; @@ -101,11 +101,11 @@ public async Task Can_convert_audio() { var client = CreateClient(); - MediaTransformResponse response = null; + ArtifactGenerationResponse response = null; try { await using var audioStream = File.OpenRead("files/test_audio.mp3"); - response = client.PostFilesWithRequest(new ConvertAudio + response = client.PostFilesWithRequest(new ConvertAudio { OutputFormat = AudioFormat.FLAC }, [ @@ -119,12 +119,12 @@ public async Task Can_convert_audio() Assert.That(response, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Empty); - Assert.That(response.Outputs[0].FileName, Does.EndWith(".flac")); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results, Is.Not.Empty); + Assert.That(response.Results[0].FileName, Does.EndWith(".flac")); // Test download - var downloadResponse = await client.GetHttpClient().GetStreamAsync(response.Outputs[0].Url); + var downloadResponse = await client.GetHttpClient().GetStreamAsync(response.Results[0].Url); Assert.That(downloadResponse, Is.Not.Null); // Save to disk var audioPath = "files/test_audio.flac"; diff --git a/AiServer.Tests/ImageServiceTests.cs b/AiServer.Tests/ImageServiceTests.cs index 102049f..78e5bfa 100644 --- a/AiServer.Tests/ImageServiceTests.cs +++ b/AiServer.Tests/ImageServiceTests.cs @@ -29,11 +29,11 @@ public async Task Can_convert_image_to_png() { var client = CreateClient(); - MediaTransformResponse response = null; + ArtifactGenerationResponse response = null; try { await using var imageStream = File.OpenRead("files/test_image.jpg"); - response = client.PostFilesWithRequest(new ConvertImage + response = client.PostFilesWithRequest(new ConvertImage { OutputFormat = ImageOutputFormat.Png }, [ @@ -46,11 +46,11 @@ public async Task Can_convert_image_to_png() } Assert.That(response, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Null); - Assert.That(response.Outputs.Count, Is.GreaterThan(0)); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results.Count, Is.GreaterThan(0)); // Download the image - var outputUrl = response.Outputs[0].Url; + var outputUrl = response.Results[0].Url; Assert.That(outputUrl, Is.Not.Null); var outputImage = await client.GetAsync(outputUrl!); @@ -66,11 +66,11 @@ public async Task Can_convert_image_to_jpeg() { var client = CreateClient(); - MediaTransformResponse response = null; + ArtifactGenerationResponse response = null; try { await using var imageStream = File.OpenRead("files/comfyui_upload_test.png"); - response = client.PostFilesWithRequest(new ConvertImage + response = client.PostFilesWithRequest(new ConvertImage { OutputFormat = ImageOutputFormat.Jpg }, [ @@ -83,11 +83,11 @@ public async Task Can_convert_image_to_jpeg() } Assert.That(response, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Null); - Assert.That(response.Outputs.Count, Is.GreaterThan(0)); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results.Count, Is.GreaterThan(0)); // Download the image - var outputUrl = response.Outputs[0].Url; + var outputUrl = response.Results[0].Url; Assert.That(outputUrl, Is.Not.Null); var outputImage = await client.GetAsync(outputUrl!); @@ -107,7 +107,7 @@ public async Task Cannot_convert_image_with_invalid_format() try { await using var imageStream = File.OpenRead("files/comfyui_upload_test.png"); - var response = client.PostFilesWithRequest(new ConvertImage + var response = client.PostFilesWithRequest(new ConvertImage { OutputFormat = null }, [ @@ -133,7 +133,7 @@ public async Task Cannot_crop_image_with_invalid_dimensions() try { await using var imageStream = File.OpenRead("files/test_image.jpg"); - var response = client.PostFilesWithRequest(new CropImage + var response = client.PostFilesWithRequest(new CropImage { X = -10, Y = -10, @@ -159,7 +159,7 @@ public async Task Can_crop_image() var client = CreateClient(); await using var imageStream = File.OpenRead("files/comfyui_upload_test.png"); - var response = client.PostFilesWithRequest(new CropImage + var response = client.PostFilesWithRequest(new CropImage { X = 10, Y = 10, @@ -171,11 +171,11 @@ public async Task Can_crop_image() Assert.That(response, Is.Not.Null); var stream = response; - Assert.That(response.Outputs, Is.Not.Null); - Assert.That(response.Outputs.Count, Is.GreaterThan(0)); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results.Count, Is.GreaterThan(0)); // Download the image - var outputUrl = response.Outputs[0].Url; + var outputUrl = response.Results[0].Url; Assert.That(outputUrl, Is.Not.Null); var outputImage = await client.GetAsync(outputUrl!); @@ -190,12 +190,12 @@ public async Task Can_apply_image_watermark() { var client = CreateClient(); - MediaTransformResponse response = null; + ArtifactGenerationResponse response = null; try { await using var imageStream = File.OpenRead("files/test_image.jpg"); await using var watermarkStream = File.OpenRead("files/watermark_image.png"); - response = client.PostFilesWithRequest(new WatermarkImage + response = client.PostFilesWithRequest(new WatermarkImage { Position = WatermarkPosition.BottomRight, Opacity = 0.7f @@ -210,11 +210,11 @@ public async Task Can_apply_image_watermark() } Assert.That(response, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Null); - Assert.That(response.Outputs.Count, Is.GreaterThan(0)); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results.Count, Is.GreaterThan(0)); // Download the image - var outputUrl = response.Outputs[0].Url; + var outputUrl = response.Results[0].Url; Assert.That(outputUrl, Is.Not.Null); var outputImage = await client.GetAsync(outputUrl!); diff --git a/AiServer.Tests/ImageToTextTests.cs b/AiServer.Tests/ImageToTextTests.cs index d3f59bc..9a635b8 100644 --- a/AiServer.Tests/ImageToTextTests.cs +++ b/AiServer.Tests/ImageToTextTests.cs @@ -13,11 +13,11 @@ public async Task Can_queue_convert_image_to_text() { var client = CreateClient(); - GenerationResponse? response = null; + TextGenerationResponse? response = null; try { await using var imageStream = File.OpenRead("files/comfyui_upload_test.png"); - response = client.PostFilesWithRequest(new ImageToText + response = client.PostFilesWithRequest(new ImageToText { }, [ @@ -31,8 +31,8 @@ public async Task Can_queue_convert_image_to_text() Assert.That(response, Is.Not.Null); - Assert.That(response.TextOutputs, Is.Not.Null); - Assert.That(response.TextOutputs, Is.Not.Empty); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results, Is.Not.Empty); } } \ No newline at end of file diff --git a/AiServer.Tests/OpenAiChatTaskTests.cs b/AiServer.Tests/OpenAiChatTaskTests.cs index 138565b..030c5a6 100644 --- a/AiServer.Tests/OpenAiChatTaskTests.cs +++ b/AiServer.Tests/OpenAiChatTaskTests.cs @@ -92,10 +92,10 @@ public async Task Generate_llama3_async_and_fetch_results() answer.PrintDump(); Assert.That(answer, Is.Not.Null); - Assert.That(answer.ChatResponse, Is.Not.Null); - Assert.That(answer.ChatResponse.Choices, Is.Not.Empty); - Assert.That(answer.ChatResponse.Choices[0].Message, Is.Not.Null); - Assert.That(answer.ChatResponse.Choices[0].Message.Content, Is.Not.Empty); + Assert.That(answer.Result, Is.Not.Null); + Assert.That(answer.Result.Choices, Is.Not.Empty); + Assert.That(answer.Result.Choices[0].Message, Is.Not.Null); + Assert.That(answer.Result.Choices[0].Message.Content, Is.Not.Empty); } private async Task QueueQuestionTasks(IEnumerable questionFiles, string model, string? provider = null, string? replyTo = null) diff --git a/AiServer.Tests/QueueImageServiceTests.cs b/AiServer.Tests/QueueImageServiceTests.cs index 1e6a846..77dfed0 100644 --- a/AiServer.Tests/QueueImageServiceTests.cs +++ b/AiServer.Tests/QueueImageServiceTests.cs @@ -45,7 +45,7 @@ public async Task Can_convert_image_to_png() Assert.That(response, Is.Not.Null); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -53,7 +53,7 @@ public async Task Can_convert_image_to_png() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -64,11 +64,11 @@ public async Task Can_convert_image_to_png() Assert.That(getStatusResponse.RefId, Is.EqualTo(response.RefId)); Assert.That(getStatusResponse.JobState, Is.Not.Null); - Assert.That(getStatusResponse.Outputs, Is.Not.Null); - Assert.That(getStatusResponse.Outputs.Count, Is.GreaterThan(0)); + Assert.That(getStatusResponse.Results, Is.Not.Null); + Assert.That(getStatusResponse.Results.Count, Is.GreaterThan(0)); // Download the image - var outputUrl = getStatusResponse.Outputs[0].Url; + var outputUrl = getStatusResponse.Results[0].Url; Assert.That(outputUrl, Is.Not.Null); var outputImage = await client.GetAsync(outputUrl!); @@ -103,7 +103,7 @@ public async Task Can_convert_image_to_jpeg() Assert.That(response, Is.Not.Null); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -111,7 +111,7 @@ public async Task Can_convert_image_to_jpeg() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -122,11 +122,11 @@ public async Task Can_convert_image_to_jpeg() Assert.That(getStatusResponse.RefId, Is.EqualTo(response.RefId)); Assert.That(getStatusResponse.JobState, Is.Not.Null); - Assert.That(getStatusResponse.Outputs, Is.Not.Null); - Assert.That(getStatusResponse.Outputs.Count, Is.GreaterThan(0)); + Assert.That(getStatusResponse.Results, Is.Not.Null); + Assert.That(getStatusResponse.Results.Count, Is.GreaterThan(0)); // Download the image - var outputUrl = getStatusResponse.Outputs[0].Url; + var outputUrl = getStatusResponse.Results[0].Url; Assert.That(outputUrl, Is.Not.Null); var outputImage = await client.GetAsync(outputUrl!); @@ -212,7 +212,7 @@ public async Task Can_crop_image() Assert.That(response, Is.Not.Null); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -220,7 +220,7 @@ public async Task Can_crop_image() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -231,12 +231,12 @@ public async Task Can_crop_image() Assert.That(getStatusResponse.RefId, Is.EqualTo(response.RefId)); Assert.That(getStatusResponse.JobState, Is.Not.Null); - Assert.That(getStatusResponse.Outputs, Is.Not.Null); - Assert.That(getStatusResponse.Outputs.Count, Is.GreaterThan(0)); + Assert.That(getStatusResponse.Results, Is.Not.Null); + Assert.That(getStatusResponse.Results.Count, Is.GreaterThan(0)); // Download the image - var outputUrl = getStatusResponse.Outputs[0].Url; + var outputUrl = getStatusResponse.Results[0].Url; Assert.That(outputUrl, Is.Not.Null); var outputImage = await client.GetAsync(outputUrl!); @@ -273,7 +273,7 @@ public async Task Can_apply_image_watermark() Assert.That(response, Is.Not.Null); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -281,7 +281,7 @@ public async Task Can_apply_image_watermark() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -292,12 +292,12 @@ public async Task Can_apply_image_watermark() Assert.That(getStatusResponse.RefId, Is.EqualTo(response.RefId)); Assert.That(getStatusResponse.JobState, Is.Not.Null); - Assert.That(getStatusResponse.Outputs, Is.Not.Null); - Assert.That(getStatusResponse.Outputs.Count, Is.GreaterThan(0)); + Assert.That(getStatusResponse.Results, Is.Not.Null); + Assert.That(getStatusResponse.Results.Count, Is.GreaterThan(0)); // Download the image - var outputUrl = getStatusResponse.Outputs[0].Url; + var outputUrl = getStatusResponse.Results[0].Url; Assert.That(outputUrl, Is.Not.Null); var outputImage = await client.GetAsync(outputUrl!); diff --git a/AiServer.Tests/QueueImageToImageTests.cs b/AiServer.Tests/QueueImageToImageTests.cs index b01c875..4901d27 100644 --- a/AiServer.Tests/QueueImageToImageTests.cs +++ b/AiServer.Tests/QueueImageToImageTests.cs @@ -72,7 +72,7 @@ public async Task Can_generate_image_with_reply_to() Assert.That(response?.JobId, Is.Not.Zero); // Get Job - var job = await client.ApiAsync(new GetJobStatus + var job = await client.ApiAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -134,7 +134,7 @@ public async Task Can_generate_image_without_sync_or_reply_to() Assert.That(response.JobState is BackgroundJobState.Started or BackgroundJobState.Queued, Is.True); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -142,7 +142,7 @@ public async Task Can_generate_image_without_sync_or_reply_to() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); diff --git a/AiServer.Tests/QueueImageToTextTests.cs b/AiServer.Tests/QueueImageToTextTests.cs index e2a4945..50d7b0d 100644 --- a/AiServer.Tests/QueueImageToTextTests.cs +++ b/AiServer.Tests/QueueImageToTextTests.cs @@ -68,7 +68,7 @@ public async Task Can_convert_image_to_text_with_reply_to() Assert.That(response?.JobId, Is.Not.Zero); // Get Job - var job = await client.ApiAsync(new GetJobStatus + var job = await client.ApiAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -128,7 +128,7 @@ public async Task Can_convert_image_to_text_without_sync_or_reply_to() Assert.That(response.JobState is BackgroundJobState.Started or BackgroundJobState.Queued, Is.True); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -136,7 +136,7 @@ public async Task Can_convert_image_to_text_without_sync_or_reply_to() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); diff --git a/AiServer.Tests/QueueImageUpscaleTests.cs b/AiServer.Tests/QueueImageUpscaleTests.cs index c8b1904..d35297b 100644 --- a/AiServer.Tests/QueueImageUpscaleTests.cs +++ b/AiServer.Tests/QueueImageUpscaleTests.cs @@ -69,7 +69,7 @@ public async Task Can_upscale_image_with_reply_to() Assert.That(response?.JobId, Is.Not.Zero); // Get Job - var job = await client.ApiAsync(new GetJobStatus + var job = await client.ApiAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -129,7 +129,7 @@ public async Task Can_upscale_image_without_sync_or_reply_to() Assert.That(response.JobState is BackgroundJobState.Started or BackgroundJobState.Queued, Is.True); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -137,7 +137,7 @@ public async Task Can_upscale_image_without_sync_or_reply_to() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); diff --git a/AiServer.Tests/QueueImageWithMaskTests.cs b/AiServer.Tests/QueueImageWithMaskTests.cs index 25a1afc..9cdd7e2 100644 --- a/AiServer.Tests/QueueImageWithMaskTests.cs +++ b/AiServer.Tests/QueueImageWithMaskTests.cs @@ -80,7 +80,7 @@ public async Task Can_generate_image_with_mask_with_reply_to() Assert.That(response?.JobId, Is.Not.Zero); // Get Job - var job = await client.ApiAsync(new GetJobStatus + var job = await client.ApiAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -146,7 +146,7 @@ public async Task Can_generate_image_with_mask_without_sync_or_reply_to() Assert.That(response.JobState is BackgroundJobState.Started or BackgroundJobState.Queued, Is.True); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -154,7 +154,7 @@ public async Task Can_generate_image_with_mask_without_sync_or_reply_to() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); diff --git a/AiServer.Tests/QueueSpeechToTextTests.cs b/AiServer.Tests/QueueSpeechToTextTests.cs index abfddae..7cb0adf 100644 --- a/AiServer.Tests/QueueSpeechToTextTests.cs +++ b/AiServer.Tests/QueueSpeechToTextTests.cs @@ -78,7 +78,7 @@ public async Task Can_transcribe_speech_with_reply_to() Assert.That(response?.JobId, Is.Not.Zero); // Get Job - var job = await client.ApiAsync(new GetJobStatus + var job = await client.ApiAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -110,13 +110,13 @@ public async Task Can_transcribe_speech_with_reply_to() Assert.That(hasRepyTo.Succeeded, Is.True); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); - Assert.That(getStatusResponse.TextOutputs, Is.Not.Null); - Assert.That(getStatusResponse.TextOutputs, Is.Not.Empty); + Assert.That(getStatusResponse.Results, Is.Not.Null); + Assert.That(getStatusResponse.Results, Is.Not.Empty); } [Test] @@ -147,7 +147,7 @@ public async Task Can_transcribe_speech_without_sync_or_reply_to() Assert.True(response.JobState is BackgroundJobState.Queued or BackgroundJobState.Started); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetTextGenerationStatus { JobId = response.JobId }); @@ -155,7 +155,7 @@ public async Task Can_transcribe_speech_without_sync_or_reply_to() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetTextGenerationStatus { JobId = response.JobId }); @@ -166,9 +166,9 @@ public async Task Can_transcribe_speech_without_sync_or_reply_to() Assert.That(getStatusResponse.RefId, Is.EqualTo(response.RefId)); Assert.That(getStatusResponse.JobState, Is.Not.Null); Assert.That(getStatusResponse.JobState, Is.EqualTo(BackgroundJobState.Completed)); - Assert.That(getStatusResponse.TextOutputs, Is.Not.Null); - Assert.That(getStatusResponse.TextOutputs, Is.Not.Empty); - Assert.That(getStatusResponse.TextOutputs[0].Text, Is.Not.Null); - Assert.That(getStatusResponse.TextOutputs[0].Text, Is.Not.Empty); + Assert.That(getStatusResponse.Results, Is.Not.Null); + Assert.That(getStatusResponse.Results, Is.Not.Empty); + Assert.That(getStatusResponse.Results?[0].Text, Is.Not.Null); + Assert.That(getStatusResponse.Results?[0].Text, Is.Not.Empty); } } \ No newline at end of file diff --git a/AiServer.Tests/QueueTextToImageTests.cs b/AiServer.Tests/QueueTextToImageTests.cs index 640b741..6e154b6 100644 --- a/AiServer.Tests/QueueTextToImageTests.cs +++ b/AiServer.Tests/QueueTextToImageTests.cs @@ -99,7 +99,7 @@ public async Task Can_generate_image_with_reply_to() Assert.That(response?.Response?.JobId, Is.Not.Zero); // Get Job - var job = await client.ApiAsync(new GetJobStatus + var job = await client.ApiAsync(new GetArtifactGenerationStatus { JobId = response.Response.JobId }); @@ -161,7 +161,7 @@ public async Task Can_generate_image_without_sync_or_reply_to() Assert.That(response.JobState is BackgroundJobState.Started or BackgroundJobState.Queued, Is.True); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -169,7 +169,7 @@ public async Task Can_generate_image_without_sync_or_reply_to() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); diff --git a/AiServer.Tests/QueueTextToSpeechTests.cs b/AiServer.Tests/QueueTextToSpeechTests.cs index 0e962b5..b7ea1b6 100644 --- a/AiServer.Tests/QueueTextToSpeechTests.cs +++ b/AiServer.Tests/QueueTextToSpeechTests.cs @@ -61,7 +61,7 @@ public async Task Can_generate_speech_with_reply_to() Assert.That(response?.Response?.JobId, Is.Not.Zero); // Get Job - var job = await client.ApiAsync(new GetJobStatus + var job = await client.ApiAsync(new GetArtifactGenerationStatus { JobId = response.Response.JobId }); @@ -119,7 +119,7 @@ public async Task Can_generate_speech_without_sync_or_reply_to() Assert.True(response.JobState is BackgroundJobState.Queued or BackgroundJobState.Started or BackgroundJobState.Completed); // Verify that we can get the job status - var getStatusResponse = await client.PostAsync(new GetJobStatus + var getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -127,7 +127,7 @@ public async Task Can_generate_speech_without_sync_or_reply_to() while (getStatusResponse.JobState == BackgroundJobState.Queued || getStatusResponse.JobState == BackgroundJobState.Started) { await Task.Delay(1000); - getStatusResponse = await client.PostAsync(new GetJobStatus + getStatusResponse = await client.PostAsync(new GetArtifactGenerationStatus { JobId = response.JobId }); @@ -138,8 +138,8 @@ public async Task Can_generate_speech_without_sync_or_reply_to() Assert.That(getStatusResponse.RefId, Is.EqualTo(response.RefId)); Assert.That(getStatusResponse.JobState, Is.Not.Null); Assert.That(getStatusResponse.JobState, Is.EqualTo(BackgroundJobState.Completed)); - Assert.That(getStatusResponse.Outputs, Is.Not.Null); - Assert.That(getStatusResponse.Outputs, Is.Not.Empty); - Assert.That(getStatusResponse.Outputs[0].FileName, Does.EndWith(".mp3").Or.EndWith(".wav")); + Assert.That(getStatusResponse.Results, Is.Not.Null); + Assert.That(getStatusResponse.Results, Is.Not.Empty); + Assert.That(getStatusResponse.Results[0].FileName, Does.EndWith(".mp3").Or.EndWith(".wav")); } } \ No newline at end of file diff --git a/AiServer.Tests/SpeechToTextTests.cs b/AiServer.Tests/SpeechToTextTests.cs index 387c2c4..ece2902 100644 --- a/AiServer.Tests/SpeechToTextTests.cs +++ b/AiServer.Tests/SpeechToTextTests.cs @@ -15,12 +15,12 @@ public async Task Can_transcribe_speech() { var client = CreateClient(); - GenerationResponse? response = null; + TextGenerationResponse? response = null; await using var fileStream = new FileStream(TestAudioPath, FileMode.Open); try { - response = client.PostFilesWithRequest(new SpeechToText + response = client.PostFilesWithRequest(new SpeechToText { }, new []{ new UploadFile("speech.wav", fileStream) { FieldName = "audio"} }); @@ -33,8 +33,8 @@ public async Task Can_transcribe_speech() Assert.That(response, Is.Not.Null); Assert.That(response, Is.Not.Null); - Assert.That(response.TextOutputs, Is.Not.Null); - Assert.That(response.TextOutputs, Is.Not.Empty); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results, Is.Not.Empty); } [Test] @@ -42,7 +42,7 @@ public async Task Can_generate_speech() { var client = CreateClient(); - ApiResult? response = null; + ApiResult? response = null; try { response = await client.ApiAsync(new TextToSpeech @@ -59,9 +59,9 @@ public async Task Can_generate_speech() Assert.That(response, Is.Not.Null); Assert.That(response.Response, Is.Not.Null); - Assert.That(response.Response.Outputs, Is.Not.Null); - Assert.That(response.Response.Outputs, Is.Not.Empty); - Assert.That(response.Response.Outputs[0].FileName, Does.EndWith(".mp3").Or.EndWith(".wav")); + Assert.That(response.Response.Results, Is.Not.Null); + Assert.That(response.Response.Results, Is.Not.Empty); + Assert.That(response.Response.Results[0].FileName, Does.EndWith(".mp3").Or.EndWith(".wav")); } } \ No newline at end of file diff --git a/AiServer.Tests/TextToImageTests.cs b/AiServer.Tests/TextToImageTests.cs index 0448cbe..a01272c 100644 --- a/AiServer.Tests/TextToImageTests.cs +++ b/AiServer.Tests/TextToImageTests.cs @@ -22,7 +22,7 @@ public async Task Can_generate_image() { var client = CreateClient(); - ApiResult? response = null; + ApiResult? response = null; try { response = await client.ApiAsync(new TextToImage @@ -43,11 +43,11 @@ public async Task Can_generate_image() Assert.That(response, Is.Not.Null); Assert.That(response.Response, Is.Not.Null); - Assert.That(response.Response.Outputs, Is.Not.Null); - Assert.That(response.Response.Outputs, Is.Not.Empty); + Assert.That(response.Response.Results, Is.Not.Null); + Assert.That(response.Response.Results, Is.Not.Empty); // Validate that the output image is a valid image - var outputImage = response.Response.Outputs[0]; + var outputImage = response.Response.Results[0]; Assert.That(outputImage.FileName, Does.EndWith(".webp")); // Download the image diff --git a/AiServer.Tests/VideoIntegrationTests.cs b/AiServer.Tests/VideoIntegrationTests.cs index d9ec8c8..829d095 100644 --- a/AiServer.Tests/VideoIntegrationTests.cs +++ b/AiServer.Tests/VideoIntegrationTests.cs @@ -24,11 +24,11 @@ public async Task Can_convert_video_to_mp4() { var client = CreateClient(); - MediaTransformResponse response = null; + ArtifactGenerationResponse response = null; try { await using var videoStream = File.OpenRead("files/test_video.webm"); - response = client.PostFilesWithRequest(new ConvertVideo + response = client.PostFilesWithRequest(new ConvertVideo { OutputFormat = ConvertVideoOutputFormat.MP4, }, [ @@ -42,13 +42,13 @@ public async Task Can_convert_video_to_mp4() Assert.That(response, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Empty); - Assert.That(response.Outputs[0].FileName, Does.EndWith(".mp4")); - Assert.That(response.Outputs[0].Url, Does.StartWith("http")); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results, Is.Not.Empty); + Assert.That(response.Results[0].FileName, Does.EndWith(".mp4")); + Assert.That(response.Results[0].Url, Does.StartWith("http")); // Download the output file - var output = await response.Outputs[0].Url.GetStreamFromUrlAsync(); + var output = await response.Results[0].Url.GetStreamFromUrlAsync(); Assert.That(output, Is.Not.Null); // Download the output file await using var fs = File.Create("files/test_video.mp4"); @@ -60,11 +60,11 @@ public async Task Can_crop_video() { var client = CreateClient(); - MediaTransformResponse response = null; + ArtifactGenerationResponse response = null; try { await using var videoStream = File.OpenRead("files/test_video.mp4"); - response = client.PostFilesWithRequest(new CropVideo + response = client.PostFilesWithRequest(new CropVideo { X = 100, Y = 100, @@ -81,15 +81,15 @@ public async Task Can_crop_video() Assert.That(response, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Empty); - Assert.That(response.Outputs[0].FileName, Does.EndWith(".mp4")); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results, Is.Not.Empty); + Assert.That(response.Results[0].FileName, Does.EndWith(".mp4")); // Download the output file - Assert.That(response.Outputs[0].Url, Does.StartWith("http")); + Assert.That(response.Results[0].Url, Does.StartWith("http")); // Download the output file - var output = await response.Outputs[0].Url.GetStreamFromUrlAsync(); + var output = await response.Results[0].Url.GetStreamFromUrlAsync(); Assert.That(output, Is.Not.Null); // Save the cropped video @@ -110,11 +110,11 @@ public async Task Can_trim_video() { var client = CreateClient(); - MediaTransformResponse response = null; + ArtifactGenerationResponse response = null; try { await using var videoStream = File.OpenRead("files/test_video.mp4"); - response = client.PostFilesWithRequest(new TrimVideo + response = client.PostFilesWithRequest(new TrimVideo { StartTime = "00:01", EndTime = "00:06" @@ -129,14 +129,14 @@ public async Task Can_trim_video() Assert.That(response, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Null); - Assert.That(response.Outputs, Is.Not.Empty); - Assert.That(response.Outputs[0].FileName, Does.EndWith(".mp4")); + Assert.That(response.Results, Is.Not.Null); + Assert.That(response.Results, Is.Not.Empty); + Assert.That(response.Results[0].FileName, Does.EndWith(".mp4")); - Assert.That(response.Outputs[0].Url, Does.StartWith("http")); + Assert.That(response.Results[0].Url, Does.StartWith("http")); // Download the output file - var output = await response.Outputs[0].Url.GetStreamFromUrlAsync(); + var output = await response.Results[0].Url.GetStreamFromUrlAsync(); Assert.That(output, Is.Not.Null); // Save the trimmed video @@ -160,7 +160,7 @@ public async Task Cannot_trim_video_with_invalid_start_time() try { await using var videoStream = File.OpenRead("files/test_video.mp4"); - var response = client.PostFilesWithRequest(new TrimVideo + var response = client.PostFilesWithRequest(new TrimVideo { StartTime = "invalid", EndTime = "00:05" @@ -187,7 +187,7 @@ public async Task Cannot_trim_video_with_invalid_end_time() try { await using var videoStream = File.OpenRead("files/test_video.mp4"); - var response = client.PostFilesWithRequest(new TrimVideo + var response = client.PostFilesWithRequest(new TrimVideo { StartTime = "00:01", EndTime = "invalid"