Skip to content

Commit

Permalink
Fix usage of PostFilesWithRequest and fix response dto for queued.
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Nov 25, 2024
1 parent c24d30f commit 0071ee6
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion AiServer.ServiceModel/QueueGenerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetTextGenerationStatusResponse>
public class QueueSpeechToText : IQueueGeneration, IReturn<QueueGenerationResponse>
{
[ApiMember(Description = "The audio stream containing the speech to be transcribed")]
[Description("The audio stream containing the speech to be transcribed")]
Expand Down
6 changes: 3 additions & 3 deletions AiServer.Tests/AudioIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task Can_convert_audio_to_mp3()
{
var inputAudioPath = "files/test_audio.wav";
await using var audioStream = File.OpenRead(inputAudioPath);
response = client.PostFilesWithRequest<ArtifactGenerationResponse>(new ConvertAudio
response = client.PostFilesWithRequest(new ConvertAudio
{
OutputFormat = AudioFormat.MP3
}, [
Expand Down Expand Up @@ -62,7 +62,7 @@ public async Task Can_convert_audio_to_wav()
try
{
await using var audioStream = File.OpenRead("files/test_audio.mp3");
response = client.PostFilesWithRequest<ArtifactGenerationResponse>(new ConvertAudio
response = client.PostFilesWithRequest(new ConvertAudio
{
OutputFormat = AudioFormat.WAV
}, [
Expand Down Expand Up @@ -105,7 +105,7 @@ public async Task Can_convert_audio()
try
{
await using var audioStream = File.OpenRead("files/test_audio.mp3");
response = client.PostFilesWithRequest<ArtifactGenerationResponse>(new ConvertAudio
response = client.PostFilesWithRequest(new ConvertAudio
{
OutputFormat = AudioFormat.FLAC
}, [
Expand Down
12 changes: 6 additions & 6 deletions AiServer.Tests/ImageServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task Can_convert_image_to_png()
try
{
await using var imageStream = File.OpenRead("files/test_image.jpg");
response = client.PostFilesWithRequest<ArtifactGenerationResponse>(new ConvertImage
response = client.PostFilesWithRequest(new ConvertImage
{
OutputFormat = ImageOutputFormat.Png
}, [
Expand Down Expand Up @@ -70,7 +70,7 @@ public async Task Can_convert_image_to_jpeg()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<ArtifactGenerationResponse>(new ConvertImage
response = client.PostFilesWithRequest(new ConvertImage
{
OutputFormat = ImageOutputFormat.Jpg
}, [
Expand Down Expand Up @@ -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<ArtifactGenerationResponse>(new ConvertImage
var response = client.PostFilesWithRequest(new ConvertImage
{
OutputFormat = null
}, [
Expand All @@ -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<ArtifactGenerationResponse>(new CropImage
var response = client.PostFilesWithRequest(new CropImage
{
X = -10,
Y = -10,
Expand All @@ -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<ArtifactGenerationResponse>(new CropImage
var response = client.PostFilesWithRequest(new CropImage
{
X = 10,
Y = 10,
Expand Down Expand Up @@ -195,7 +195,7 @@ public async Task Can_apply_image_watermark()
{
await using var imageStream = File.OpenRead("files/test_image.jpg");
await using var watermarkStream = File.OpenRead("files/watermark_image.png");
response = client.PostFilesWithRequest<ArtifactGenerationResponse>(new WatermarkImage
response = client.PostFilesWithRequest(new WatermarkImage
{
Position = WatermarkPosition.BottomRight,
Opacity = 0.7f
Expand Down
20 changes: 10 additions & 10 deletions AiServer.Tests/ImageToImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public async Task Can_queue_generate_image()
{
var client = CreateClient();

GenerationResponse? response = null;
ArtifactGenerationResponse? response = null;
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<GenerationResponse>(new ImageToImage
response = client.PostFilesWithRequest(new ImageToImage
{
PositivePrompt = "A futuristic version of the input image",
BatchSize = 1
Expand All @@ -33,11 +33,11 @@ public async Task Can_queue_generate_image()

Assert.That(response, Is.Not.Null);

Assert.That(response.Outputs, Is.Not.Null);
Assert.That(response.Outputs, Is.Not.Empty);
Assert.That(response.Results, Is.Not.Null);
Assert.That(response.Results, Is.Not.Empty);

// Validate that the output image is a valid image
var outputImage = response.Outputs[0];
var outputImage = response.Results[0];
Assert.That(outputImage.FileName, Does.EndWith(".webp"));
// Download the image
var downloadResponse = await client.GetHttpClient().GetStreamAsync(outputImage.Url);
Expand Down Expand Up @@ -66,13 +66,13 @@ public async Task Can_queue_generate_image_with_mask()
{
var client = CreateClient();

GenerationResponse? response = null;
ArtifactGenerationResponse? response = null;
try
{
using var imageStream = new MemoryStream(File.ReadAllBytes("files/comfyui_upload_test.png"));
using var maskStream = new MemoryStream(File.ReadAllBytes("files/comfyui_upload_test_mask.png"));

response = client.PostFilesWithRequest<GenerationResponse>(new ImageWithMask
response = client.PostFilesWithRequest(new ImageWithMask
{
PositivePrompt = "A beautiful flower in the masked area",
NegativePrompt = "No insects or weeds"
Expand All @@ -89,11 +89,11 @@ public async Task Can_queue_generate_image_with_mask()

Assert.That(response, Is.Not.Null);

Assert.That(response.Outputs, Is.Not.Null);
Assert.That(response.Outputs, Is.Not.Empty);
Assert.That(response.Results, Is.Not.Null);
Assert.That(response.Results, Is.Not.Empty);

// Validate that the output image is a valid image
var outputImage = response.Outputs[0];
var outputImage = response.Results[0];
Assert.That(outputImage.FileName, Does.EndWith(".webp"));
// Download the image
var downloadResponse = await client.GetHttpClient().GetStreamAsync(outputImage.Url);
Expand Down
2 changes: 1 addition & 1 deletion AiServer.Tests/ImageToTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task Can_queue_convert_image_to_text()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<TextGenerationResponse>(new ImageToText
response = client.PostFilesWithRequest(new ImageToText
{

}, [
Expand Down
10 changes: 5 additions & 5 deletions AiServer.Tests/ImageUpscaleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public async Task Can_queue_upscale_image()
{
var client = CreateClient();

GenerationResponse? response = null;
ArtifactGenerationResponse? response = null;
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<GenerationResponse>(new ImageUpscale
response = client.PostFilesWithRequest(new ImageUpscale
{

}, [
Expand All @@ -33,12 +33,12 @@ public async Task Can_queue_upscale_image()
Assert.That(response, Is.Not.Null);
Assert.That(response, Is.Not.Null);

Assert.That(response.Outputs, Is.Not.Null);
Assert.That(response.Outputs, Is.Not.Empty);
Assert.That(response.Results, Is.Not.Null);
Assert.That(response.Results, Is.Not.Empty);

// Download image
// Validate that the output image is a valid image
var outputImage = response.Outputs[0];
var outputImage = response.Results[0];
Assert.That(outputImage.FileName, Does.EndWith(".webp"));
// Download the image
var downloadResponse = await client.GetHttpClient().GetStreamAsync(outputImage.Url);
Expand Down
6 changes: 3 additions & 3 deletions AiServer.Tests/QueueAudioIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task Can_convert_audio_to_mp3()
{
var inputAudioPath = "files/test_audio.wav";
await using var audioStream = File.OpenRead(inputAudioPath);
response = client.PostFilesWithRequest<QueueMediaTransformResponse>(new QueueConvertAudio
response = client.PostFilesWithRequest(new QueueConvertAudio
{
OutputFormat = AudioFormat.MP3
}, [
Expand Down Expand Up @@ -63,7 +63,7 @@ public async Task Can_convert_audio_to_wav()
try
{
await using var audioStream = File.OpenRead("files/test_audio.mp3");
response = client.PostFilesWithRequest<QueueMediaTransformResponse>(new QueueConvertAudio
response = client.PostFilesWithRequest(new QueueConvertAudio
{
OutputFormat = AudioFormat.WAV
}, [
Expand Down Expand Up @@ -107,7 +107,7 @@ public async Task Can_convert_audio()
try
{
await using var audioStream = File.OpenRead("files/test_audio.mp3");
response = client.PostFilesWithRequest<QueueMediaTransformResponse>(new QueueConvertAudio
response = client.PostFilesWithRequest(new QueueConvertAudio
{
OutputFormat = AudioFormat.FLAC
}, [
Expand Down
12 changes: 6 additions & 6 deletions AiServer.Tests/QueueImageServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task Can_convert_image_to_png()
try
{
await using var imageStream = File.OpenRead("files/test_image.jpg");
response = client.PostFilesWithRequest<QueueMediaTransformResponse>(new QueueConvertImage
response = client.PostFilesWithRequest(new QueueConvertImage
{
OutputFormat = ImageOutputFormat.Png
}, [
Expand Down Expand Up @@ -88,7 +88,7 @@ public async Task Can_convert_image_to_jpeg()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<QueueMediaTransformResponse>(new QueueConvertImage
response = client.PostFilesWithRequest(new QueueConvertImage
{
OutputFormat = ImageOutputFormat.Jpg
}, [
Expand Down Expand Up @@ -146,7 +146,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<QueueMediaTransformResponse>(
var response = client.PostFilesWithRequest(
new QueueConvertImage
{
OutputFormat = null
Expand All @@ -173,7 +173,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<QueueMediaTransformResponse>(new QueueCropImage
var response = client.PostFilesWithRequest(new QueueCropImage
{
X = -10,
Y = -10,
Expand All @@ -199,7 +199,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<QueueMediaTransformResponse>(new QueueCropImage
var response = client.PostFilesWithRequest(new QueueCropImage
{
X = 10,
Y = 10,
Expand Down Expand Up @@ -256,7 +256,7 @@ public async Task Can_apply_image_watermark()
{
await using var imageStream = File.OpenRead("files/test_image.jpg");
await using var watermarkStream = File.OpenRead("files/watermark_image.png");
response = client.PostFilesWithRequest<QueueMediaTransformResponse>(new QueueWatermarkImage
response = client.PostFilesWithRequest(new QueueWatermarkImage
{
Position = WatermarkPosition.BottomRight,
Opacity = 0.7f
Expand Down
6 changes: 3 additions & 3 deletions AiServer.Tests/QueueImageToImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task Can_queue_generate_image()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageToImage
response = client.PostFilesWithRequest(new QueueImageToImage
{
PositivePrompt = "A futuristic version of the input image",
BatchSize = 1
Expand Down Expand Up @@ -51,7 +51,7 @@ public async Task Can_generate_image_with_reply_to()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageToImage
response = client.PostFilesWithRequest(new QueueImageToImage
{
PositivePrompt = "A futuristic version of the input image",
BatchSize = 1,
Expand Down Expand Up @@ -113,7 +113,7 @@ public async Task Can_generate_image_without_sync_or_reply_to()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageToImage
response = client.PostFilesWithRequest(new QueueImageToImage
{
PositivePrompt = "A futuristic version of the input image",
BatchSize = 1
Expand Down
6 changes: 3 additions & 3 deletions AiServer.Tests/QueueImageToTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task Can_queue_convert_image_to_text()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageToText
response = client.PostFilesWithRequest(new QueueImageToText
{

}, [
Expand Down Expand Up @@ -49,7 +49,7 @@ public async Task Can_convert_image_to_text_with_reply_to()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageToText
response = client.PostFilesWithRequest(new QueueImageToText
{
ReplyTo = "https://localhost:5005/dummyreplyto"
}, [
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task Can_convert_image_to_text_without_sync_or_reply_to()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageToText
response = client.PostFilesWithRequest(new QueueImageToText
{
}, [
new UploadFile("image.png", imageStream){ FieldName = "image"}
Expand Down
6 changes: 3 additions & 3 deletions AiServer.Tests/QueueImageUpscaleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task Can_queue_upscale_image()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageUpscale
response = client.PostFilesWithRequest(new QueueImageUpscale
{

}, [
Expand Down Expand Up @@ -50,7 +50,7 @@ public async Task Can_upscale_image_with_reply_to()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageUpscale
response = client.PostFilesWithRequest(new QueueImageUpscale
{
ReplyTo = "https://localhost:5005/dummyreplyto"
}, [
Expand Down Expand Up @@ -110,7 +110,7 @@ public async Task Can_upscale_image_without_sync_or_reply_to()
try
{
await using var imageStream = File.OpenRead("files/comfyui_upload_test.png");
response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageUpscale
response = client.PostFilesWithRequest(new QueueImageUpscale
{
}, [
new UploadFile("image.png", imageStream){ FieldName = "image"}
Expand Down
6 changes: 3 additions & 3 deletions AiServer.Tests/QueueImageWithMaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task Can_queue_generate_image_with_mask()
using var imageStream = new MemoryStream(File.ReadAllBytes("files/comfyui_upload_test.png"));
using var maskStream = new MemoryStream(File.ReadAllBytes("files/comfyui_upload_test_mask.png"));

response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageWithMask
response = client.PostFilesWithRequest(new QueueImageWithMask
{
PositivePrompt = "A beautiful flower in the masked area",
NegativePrompt = "No insects or weeds"
Expand Down Expand Up @@ -56,7 +56,7 @@ public async Task Can_generate_image_with_mask_with_reply_to()
using var imageStream = new MemoryStream(File.ReadAllBytes("files/comfyui_upload_test.png"));
using var maskStream = new MemoryStream(File.ReadAllBytes("files/comfyui_upload_test_mask.png"));

response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageWithMask
response = client.PostFilesWithRequest(new QueueImageWithMask
{
PositivePrompt = "A scary storm is brewing",
NegativePrompt = "No insects or weeds",
Expand Down Expand Up @@ -123,7 +123,7 @@ public async Task Can_generate_image_with_mask_without_sync_or_reply_to()
using var imageStream = new MemoryStream(File.ReadAllBytes("files/comfyui_upload_test.png"));
using var maskStream = new MemoryStream(File.ReadAllBytes("files/comfyui_upload_test_mask.png"));

response = client.PostFilesWithRequest<QueueGenerationResponse>(new QueueImageWithMask
response = client.PostFilesWithRequest(new QueueImageWithMask
{
PositivePrompt = "A beautiful flower in the masked area",
NegativePrompt = "No insects or weeds"
Expand Down
Loading

0 comments on commit 0071ee6

Please sign in to comment.