Skip to content

Commit

Permalink
possible models
Browse files Browse the repository at this point in the history
  • Loading branch information
sdcb committed Dec 6, 2024
1 parent 41632e1 commit c88fc41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/BE/Controllers/Admin/ModelKeys/Dtos/PossibleModelDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public record PossibleModelDto
[JsonPropertyName("isExists")]
public required bool IsExists { get; init; }

[JsonPropertyName("deploymentName")]
public required string? DeploymentName { get; init; }

[JsonPropertyName("isLegacy")]
public required bool IsLegacy { get; init; }
}
9 changes: 4 additions & 5 deletions src/BE/Controllers/Admin/ModelKeys/ModelKeysController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,19 @@ public async Task<ActionResult<PossibleModelDto[]>> ListModelKeyPossibleModels(s
return NotFound();
}

HashSet<short> existingModelRefIds = modelKey.Models
.Select(x => x.ModelReferenceId)
.ToHashSet();

PossibleModelDto[] readyRefs = await db.ModelReferences
.Where(x => x.ProviderId == modelKey.ModelProviderId)
.OrderBy(x => x.Name)
.Select(x => new PossibleModelDto()
{
IsExists = x.Models.Any(m => m.ModelKeyId == modelKeyId),
DeploymentName = x.Models.FirstOrDefault(m => m.ModelKeyId == modelKeyId)!.DeploymentName,
ReferenceId = x.Id,
ReferenceName = x.Name,
IsLegacy = x.IsLegacy,
IsExists = x.Models.Any(m => m.ModelKeyId == modelKeyId),
})
.OrderBy(x => (x.IsLegacy ? 1 : 0) + (x.IsExists ? 2 : 0))
.ThenByDescending(x => x.ReferenceId)
.ToArrayAsync(cancellationToken);

return Ok(readyRefs);
Expand Down

0 comments on commit c88fc41

Please sign in to comment.