Skip to content

Commit

Permalink
Ensure json text is always last.
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Nov 25, 2024
1 parent e7df42c commit 7be9fb5
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions AiServer.ServiceInterface/Generation/ComfyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,27 @@ private ComfyClient GetClient(MediaProvider provider)
var status = await comfyClient.GetWorkflowStatusAsync(response.PromptId, token);
var previewQ = GetPreviewQueryStringByTaskType(request.TaskType ?? AiTaskType.TextToImage);
var duration = DateTime.UtcNow - start;
var diffResponse = new GenerationResult
var diffResponse = new GenerationResult { };
if (!status.Outputs.IsNullOrEmpty())
{
Outputs = status.Outputs.SelectMany(x => x.Files)
.Select(x => new AiProviderFileOutput {
FileName = x.Filename,
Url = $"{provider.ApiBaseUrl}/view?filename={x.Filename}&type={x.Type}&subfolder={x.Subfolder}{previewQ}"
}).ToList(),
TextOutputs = status.Outputs.SelectMany(x => x.Texts)
.Select(x => new AiProviderTextOutput { Text = x.Text }).ToList()
};
if (!status.Outputs.Any(x => x.Files.IsNullOrEmpty()))
{
diffResponse.Outputs = status.Outputs.SelectMany(x => x.Files)
.Select(x => new AiProviderFileOutput
{
FileName = x.Filename,
Url =
$"{provider.ApiBaseUrl}/view?filename={x.Filename}&type={x.Type}&subfolder={x.Subfolder}{previewQ}"
}).ToList();
}
if(!status.Outputs.Any(x => x.Texts.IsNullOrEmpty()))
{
var textOutputs = status.Outputs.SelectMany(x => x.Texts)
.Select(x => new AiProviderTextOutput { Text = x.Text }).ToList();
// Sort text outputs intentionally so that text that is JSON is last
diffResponse.TextOutputs = textOutputs.OrderBy(x => x.Text != null && x.Text.StartsWith("{")).ToList();
}
}
return (diffResponse, duration);
}

Expand Down

0 comments on commit 7be9fb5

Please sign in to comment.