Skip to content

Commit

Permalink
Smartly pick deployment or model name based on deployment extra
Browse files Browse the repository at this point in the history
  • Loading branch information
robch committed Aug 26, 2023
1 parent b6b137e commit cdc0f36
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/common/details/azcli/AzCliConsoleGui_AiDeploymentPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,18 @@ public class AiResourceDeploymentPicker
return (null, null);
}

var scanFor = deploymentExtra.ToLower() switch {
"chat" => "gpt",
"embeddings" => "embedding",
_ => deploymentExtra.ToLower()
};

var choices = deployments.ToArray();
var select = Math.Max(0, Array.FindIndex(choices, x => x.Name.Contains(scanFor)));
if (allowCreateDeployment) select++;

return interactive
? ListBoxPickDeployment(deployments.ToArray(), allowCreateDeploymentOption)
? ListBoxPickDeployment(choices, allowCreateDeploymentOption, select)
: (null, null);
}

Expand All @@ -111,7 +121,7 @@ public class AiResourceDeploymentPicker
"embeddings" => "embedding",
_ => deploymentExtra.ToLower()
};
var select = Math.Max(0, Array.FindIndex(choices, x => x.Contains(scanFor)));
var select = Math.Max(0, Array.FindLastIndex(choices, x => x.Contains(scanFor)));

var index = ListBoxPicker.PickIndexOf(choices, 60, 30, normal, selected, select);
if (index < 0) return (null, null);
Expand Down Expand Up @@ -154,7 +164,7 @@ public class AiResourceDeploymentPicker
return (response.Payload, null);
}

private static (AzCli.CognitiveServicesDeploymentInfo? Deployment, string Error) ListBoxPickDeployment(AzCli.CognitiveServicesDeploymentInfo[] deployments, string p0)
private static (AzCli.CognitiveServicesDeploymentInfo? Deployment, string Error) ListBoxPickDeployment(AzCli.CognitiveServicesDeploymentInfo[] deployments, string p0, int select = 0)
{
var list = deployments.Select(x => $"{x.Name} ({x.ModelFormat})").ToList();

Expand All @@ -164,7 +174,7 @@ private static (AzCli.CognitiveServicesDeploymentInfo? Deployment, string Error)
var normal = new Colors(ConsoleColor.White, ConsoleColor.Blue);
var selected = new Colors(ConsoleColor.White, ConsoleColor.Red);

var picked = ListBoxPicker.PickIndexOf(list.ToArray(), 60, 30, normal, selected);
var picked = ListBoxPicker.PickIndexOf(list.ToArray(), 60, 30, normal, selected, select);
if (picked < 0)
{
return (null, null);
Expand Down

0 comments on commit cdc0f36

Please sign in to comment.