Skip to content

Commit

Permalink
Update more APIs to use typed responses
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 25, 2024
1 parent 07e1850 commit 22edcaa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
16 changes: 8 additions & 8 deletions AiServer.ServiceInterface/ImageServices.Generation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task<QueueGenerationResponse> Any(QueueTextToImage request)
return await diffRequest.ProcessQueuedGenerationAsync(jobs, diffServices);
}

public async Task<object> Any(QueueImageUpscale request)
public async Task<QueueGenerationResponse> Any(QueueImageUpscale request)
{
if(Request?.Files == null || Request.Files.Length == 0)
{
Expand All @@ -70,10 +70,10 @@ public async Task<object> Any(QueueImageUpscale request)
};

await using var diffServices = ResolveService<MediaProviderServices>();
return await diffRequest.ProcessSyncGenerationAsync(jobs, diffServices);
return await diffRequest.ProcessQueuedGenerationAsync(jobs, diffServices);
}

public async Task<object> Any(QueueImageToImage request)
public async Task<QueueGenerationResponse> Any(QueueImageToImage request)
{
if (Request?.Files == null || Request.Files.Length == 0)
{
Expand All @@ -100,10 +100,10 @@ public async Task<object> Any(QueueImageToImage request)
};

await using var diffServices = ResolveService<MediaProviderServices>();
return await diffRequest.ProcessSyncGenerationAsync(jobs, diffServices);
return await diffRequest.ProcessQueuedGenerationAsync(jobs, diffServices);
}

public async Task<object> Any(QueueImageWithMask request)
public async Task<QueueGenerationResponse> Any(QueueImageWithMask request)
{
if (Request?.Files == null || Request.Files.Length > 2)
{
Expand All @@ -129,10 +129,10 @@ public async Task<object> Any(QueueImageWithMask request)
};

await using var diffServices = ResolveService<MediaProviderServices>();
return await diffRequest.ProcessSyncGenerationAsync(jobs, diffServices);
return await diffRequest.ProcessQueuedGenerationAsync(jobs, diffServices);
}

public async Task<object> Any(QueueImageToText request)
public async Task<QueueGenerationResponse> Any(QueueImageToText request)
{
var diffRequest = new CreateGeneration
{
Expand All @@ -147,7 +147,7 @@ public async Task<object> Any(QueueImageToText request)
};

await using var genServices = ResolveService<MediaProviderServices>();
return await diffRequest.ProcessSyncGenerationAsync(jobs, genServices);
return await diffRequest.ProcessQueuedGenerationAsync(jobs, genServices);
}
}

Expand Down
17 changes: 7 additions & 10 deletions AiServer.ServiceInterface/OpenAiChatServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public async Task<object> Post(OpenAiChatCompletion request)
return await chatRequest.ProcessSync(jobs, this);
}

public async Task<object> Any(QueueOpenAiChatCompletion request)
public QueueOpenAiChatResponse Any(QueueOpenAiChatCompletion request)
{
if (request.Request == null)
throw new ArgumentNullException(nameof(request.Request));
Expand Down Expand Up @@ -428,15 +428,14 @@ public object Any(DeleteAiProvider request)

public static class OpenAiChatServiceExtensions
{
public static async Task<object> ProcessSync(this QueueOpenAiChatCompletion chatRequest,
IBackgroundJobs jobs,
OpenAiChatServices chatService)
public static async Task<OpenAiChatResponse> ProcessSync(this QueueOpenAiChatCompletion chatRequest,
IBackgroundJobs jobs, OpenAiChatServices chatService)
{
QueueOpenAiChatResponse? chatResponse = null;
try
{
var response = await chatService.Any(chatRequest);
chatResponse = response as QueueOpenAiChatResponse;
var response = chatService.Any(chatRequest);
chatResponse = response;
}
catch (Exception e)
{
Expand All @@ -458,14 +457,12 @@ public static async Task<object> ProcessSync(this QueueOpenAiChatCompletion chat
// We know at this point, we definitely have a job
JobResult queuedJob = job;

var completedResponse = new OpenAiChatResponse()
{
};
var completedResponse = new OpenAiChatResponse();

// Handle failed jobs
if (job.Failed != null)
{
throw new Exception(job.Failed.Error.Message);
throw new Exception(job.Failed.Error!.Message);
}

// Wait for the job to complete max 1 minute
Expand Down
10 changes: 5 additions & 5 deletions AiServer.ServiceInterface/VideoServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void ValidateTimeFormat(string time, string fieldName)
}
}

public async Task<object> Any(QueueScaleVideo request)
public async Task<QueueMediaTransformResponse> Any(QueueScaleVideo request)
{
// Convert request
var transformRequest = new CreateMediaTransform
Expand All @@ -144,7 +144,7 @@ public async Task<object> Any(QueueScaleVideo request)
return await transformRequest.ProcessQueuedTransformAsync(jobs, transformService);
}

public async Task<object> Any(QueueWatermarkVideo request)
public async Task<QueueMediaTransformResponse> Any(QueueWatermarkVideo request)
{
string watermarkPosition;
switch (request.Position)
Expand Down Expand Up @@ -205,7 +205,7 @@ private bool IsVideoFormat(MediaOutputFormat outputFormat)
}
}

public async Task<object> Any(QueueConvertVideo request)
public async Task<QueueMediaTransformResponse> Any(QueueConvertVideo request)
{
if (Request?.Files == null || Request.Files.Length == 0)
throw new ArgumentException("No video file provided");
Expand All @@ -230,7 +230,7 @@ public async Task<object> Any(QueueConvertVideo request)
return await transformRequest.ProcessQueuedTransformAsync(jobs, transformService);
}

public async Task<object> Any(QueueCropVideo request)
public async Task<QueueMediaTransformResponse> Any(QueueCropVideo request)
{
// Convert request
var transformRequest = new CreateMediaTransform
Expand All @@ -251,7 +251,7 @@ public async Task<object> Any(QueueCropVideo request)
return await transformRequest.ProcessQueuedTransformAsync(jobs, transformService);
}

public async Task<object> Any(QueueTrimVideo request)
public async Task<QueueMediaTransformResponse> Any(QueueTrimVideo request)
{
if (Request?.Files == null || Request.Files.Length == 0)
throw new ArgumentException("No video file provided");
Expand Down

0 comments on commit 22edcaa

Please sign in to comment.