Skip to content

Commit

Permalink
create openai deployments with default capacity as per model list
Browse files Browse the repository at this point in the history
  • Loading branch information
robch committed Aug 26, 2023
1 parent 5e7d295 commit b6b137e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/common/details/azcli/AzCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public struct CognitiveServicesModelInfo
public string Name { get; set; }
public string Format { get; set; }
public string Version { get; set; }
public string DefaultCapacity { get; set; }
}

public struct CognitiveSearchResourceInfo
Expand Down Expand Up @@ -245,7 +246,7 @@ public static async Task<ProcessResponse<CognitiveServicesModelInfo[]>> ListCogn
var cmdPart = "cognitiveservices model list";
var subPart = subscriptionId != null ? $"--subscription {subscriptionId}" : "";

var process = await ProcessHelpers.ParseShellCommandJson<JArray>("az", $"{cmdPart} {subPart} -l {regionLocation} --query \"[].{{Name:model.name,Format:model.format,Version:model.version}}\"", GetAzureHttpUserAgentEnvironment());
var process = await ProcessHelpers.ParseShellCommandJson<JArray>("az", $"{cmdPart} {subPart} -l {regionLocation} --query \"[].{{Name:model.name,Format:model.format,Version:model.version,DefaultCapacity:model.skus[0].capacity.default}}\"", GetAzureHttpUserAgentEnvironment());

var x = new ProcessResponse<CognitiveServicesModelInfo[]>();
x.StdOutput = process.StdOutput;
Expand All @@ -260,6 +261,7 @@ public static async Task<ProcessResponse<CognitiveServicesModelInfo[]>> ListCogn
x.Payload[i].Name = model["Name"].Value<string>();
x.Payload[i].Format = model["Format"].Value<string>();
x.Payload[i].Version = model["Version"].Value<string>();
x.Payload[i].DefaultCapacity = model["DefaultCapacity"].Value<string>();
i++;
}

Expand Down Expand Up @@ -313,12 +315,12 @@ public static async Task<ProcessResponse<ResourceGroupInfo>> CreateResourceGroup
return x;
}

public static async Task<ProcessResponse<CognitiveServicesDeploymentInfo>> CreateCognitiveServicesDeployment(string subscriptionId, string group, string resourceName, string deploymentName, string modelName, string modelVersion, string modelFormat)
public static async Task<ProcessResponse<CognitiveServicesDeploymentInfo>> CreateCognitiveServicesDeployment(string subscriptionId, string group, string resourceName, string deploymentName, string modelName, string modelVersion, string modelFormat, string scaleCapacity)
{
var cmdPart = "cognitiveservices account deployment create";
var subPart = subscriptionId != null ? $"--subscription {subscriptionId}" : "";

var process = await ProcessHelpers.ParseShellCommandJson<JObject>("az", $"{cmdPart} {subPart} -g {group} -n {resourceName} --deployment-name {deploymentName} --model-name {modelName} --model-version {modelVersion} --model-format {modelFormat} --sku-capacity 1 --sku-name \"Standard\"", GetAzureHttpUserAgentEnvironment());
var process = await ProcessHelpers.ParseShellCommandJson<JObject>("az", $"{cmdPart} {subPart} -g {group} -n {resourceName} --deployment-name {deploymentName} --model-name {modelName} --model-version {modelVersion} --model-format {modelFormat} --sku-capacity {scaleCapacity} --sku-name \"Standard\"", GetAzureHttpUserAgentEnvironment());

var x = new ProcessResponse<CognitiveServicesDeploymentInfo>();
x.StdOutput = process.StdOutput;
Expand Down
13 changes: 10 additions & 3 deletions src/common/details/azcli/AzCliConsoleGui_AiDeploymentPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,22 @@ public class AiResourceDeploymentPicker
Console.Write("\rModel: ");
var choices = models.Payload.Select(x => x.Name + " (version " + x.Version + ")").ToArray();

var select = Array.FindIndex(choices, x => x.StartsWith("gpt"));
var scanFor = deploymentExtra.ToLower() switch {
"chat" => "gpt",
"embeddings" => "embedding",
_ => deploymentExtra.ToLower()
};
var select = Math.Max(0, Array.FindIndex(choices, x => x.Contains(scanFor)));

var index = ListBoxPicker.PickIndexOf(choices, 60, 30, normal, selected, select);
if (index < 0) return (null, null);

var modelName = models.Payload[index].Name;
Console.WriteLine($"\rModel: {modelName}");

var modelVersion = modelName.Contains("gpt") ? "0613" : "2";
var modelFormat = "OpenAI";
var modelVersion = models.Payload[index].Version;
var scaleCapacity = models.Payload[index].DefaultCapacity;

Console.Write("\rName: ");
choices = new string[] {
Expand All @@ -134,7 +141,7 @@ public class AiResourceDeploymentPicker
if (pick != choices.Length - 1) Console.WriteLine($"\rName: {deploymentName}");

Console.Write("*** CREATING ***");
var response = await AzCli.CreateCognitiveServicesDeployment(subscriptionId, resource.Group, resource.Name, deploymentName, modelName, modelVersion, modelFormat);
var response = await AzCli.CreateCognitiveServicesDeployment(subscriptionId, resource.Group, resource.Name, deploymentName, modelName, modelVersion, modelFormat, scaleCapacity);

Console.Write("\r");
if (string.IsNullOrEmpty(response.StdOutput) && !string.IsNullOrEmpty(response.StdError))
Expand Down

0 comments on commit b6b137e

Please sign in to comment.