Skip to content

Commit

Permalink
added model names and evaluation deployment; populated other env vari…
Browse files Browse the repository at this point in the history
…ables as requested by dan (#58)
  • Loading branch information
robch authored Oct 19, 2023
1 parent 4247ad5 commit 35c76c3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/ai/commands/chat_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private Uri GetEmbeddingsDeploymentEndpoint()
return baseOk && pathOk ? new Uri(embeddingsEndpoint) : null;
}

private static string GetOpenAIClientVersionNumber()
public static string GetOpenAIClientVersionNumber()
{
var latest = ((OpenAIClientOptions.ServiceVersion[])Enum.GetValues(typeof(OpenAIClientOptions.ServiceVersion))).MaxBy(i => (int)i);
var latestVersion = latest.ToString().ToLower().Replace("_", "-").Substring(1);
Expand Down
26 changes: 16 additions & 10 deletions src/ai/commands/dev_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,28 @@ private Dictionary<string, string> GetEnvironment()
env.Add("AZURE_AI_PROJECT_NAME", ReadConfig("project"));
env.Add("AZURE_AI_HUB_NAME", ReadConfig("hub"));

env.Add("OPENAI_API_KEY", ReadConfig("chat.key"));
env.Add("OPENAI_API_VERSION", ReadConfig("chat.version"));
env.Add("OPENAI_API_BASE", ReadConfig("chat.base"));
env.Add("OPENAI_ENDPOINT", ReadConfig("chat.endpoint"));
env.Add("AZURE_OPENAI_CHAT_DEPLOYMENT", ReadConfig("chat.deployment"));
env.Add("AZURE_OPENAI_EVALUATION_DEPLOYMENT", ReadConfig("chat.evaluation.deployment") ?? ReadConfig("chat.deployment"));
env.Add("AZURE_OPENAI_EMBEDDING_DEPLOYMENT", ReadConfig("search.embeddings.deployment"));

env.Add("OPENAI_CHAT_DEPLOYMENT", ReadConfig("chat.deployment"));
env.Add("OPENAI_EVALUATION_DEPLOYMENT", ReadConfig("chat.evaluation.deployment"));
env.Add("OPENAI_EMBEDDING_DEPLOYMENT", ReadConfig("search.embeddings.deployment"));
env.Add("AZURE_OPENAI_CHAT_MODEL", ReadConfig("chat.deployment.model.name"));
env.Add("AZURE_OPENAI_EVALUATION_MODEL", ReadConfig("chat.evaluation.deployment.model.name") ?? ReadConfig("chat.deployment.model.name"));
env.Add("AZURE_OPENAI_EMBEDDING_MODEL", ReadConfig("search.embeddings.deployment.model.name"));

env.Add("AZURE_AI_SEARCH_ENDPOINT", ReadConfig("search.endpoint"));
env.Add("AZURE_AI_SEARCH_INDEX_NAME", ReadConfig("chat.search.index"));
env.Add("AZURE_AI_SEARCH_INDEX_NAME", ReadConfig("search.index.name"));
env.Add("AZURE_AI_SEARCH_KEY", ReadConfig("search.key"));

// HACK: this is a temporary hack to allow the CLI to work with the current
// version of various SDKs
// Add "non-standard" AZURE_AI_" prefixed env variables to interop with various SDKs

// OpenAI's SDK
env.Add("OPENAI_ENDPOINT", ReadConfig("chat.endpoint"));
env.Add("OPENAI_API_BASE", ReadConfig("chat.endpoint"));
env.Add("OPENAI_API_KEY", ReadConfig("chat.key"));
env.Add("OPENAI_API_TYPE", "azure");
env.Add("OPENAI_API_VERSION", ChatCommand.GetOpenAIClientVersionNumber());

// Cognitive Search SDK
env.Add("AZURE_COGNITIVE_SEARCH_TARGET", env["AZURE_AI_SEARCH_ENDPOINT"]);
env.Add("AZURE_COGNITIVE_SEARCH_KEY", env["AZURE_AI_SEARCH_KEY"]);

Expand Down
4 changes: 4 additions & 0 deletions src/common/details/azcli/AzCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public struct CognitiveServicesOpenAiResourceInfo
public string Key;
public string ChatDeployment;
public string EmbeddingsDeployment;
public string EvaluationDeployment;
}

public struct CognitiveServicesSpeechResourceInfo
Expand All @@ -83,6 +84,7 @@ public struct CognitiveServicesDeploymentInfo
{
public string Name { get; set; }
public string ModelFormat { get; set; }
public string ModelName { get; set; }
}

public struct CognitiveServicesModelInfo
Expand Down Expand Up @@ -296,6 +298,7 @@ public static async Task<ParsedJsonProcessOutput<CognitiveServicesDeploymentInfo
{
x.Payload[i].Name = deployment["Name"].Value<string>();
x.Payload[i].ModelFormat = deployment["Format"].Value<string>();
x.Payload[i].ModelName = deployment["Model"].Value<string>();
i++;
}

Expand Down Expand Up @@ -380,6 +383,7 @@ public static async Task<ParsedJsonProcessOutput<CognitiveServicesDeploymentInfo
{
Name = resource?["name"]?.Value<string>(),
ModelFormat = resource?["kind"]?.Value<string>(),
ModelName = modelName
};

return x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class AiResourceDeploymentPicker
var scanFor = deploymentExtra.ToLower() switch {
"chat" => "gpt",
"embeddings" => "embedding",
"evaluation" => "gpt",
_ => deploymentExtra.ToLower()
};

Expand Down Expand Up @@ -163,7 +164,7 @@ public class AiResourceDeploymentPicker

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

var hasP0 = !string.IsNullOrEmpty(p0);
if (hasP0) list.Insert(0, p0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public partial class AzCliConsoleGui
var regionLocation = !string.IsNullOrEmpty(regionFilter) ? await AzCliConsoleGui.PickRegionLocationAsync(interactive, regionFilter) : new AzCli.AccountRegionLocationInfo();
var resource = await AzCliConsoleGui.PickOrCreateCognitiveResource(sectionHeader, interactive, subscriptionId, regionLocation.Name, groupFilter, resourceFilter, kind, sku, yes);

var deployment = await AzCliConsoleGui.PickOrCreateDeployment(interactive, "Chat", subscriptionId, resource.Group, resource.RegionLocation, resource.Name, null);
var chatDeployment = await AzCliConsoleGui.PickOrCreateDeployment(interactive, "Chat", subscriptionId, resource.Group, resource.RegionLocation, resource.Name, null);
var embeddingsDeployment = await AzCliConsoleGui.PickOrCreateDeployment(interactive, "Embeddings", subscriptionId, resource.Group, resource.RegionLocation, resource.Name, null);
var evaluationDeployment = await AzCliConsoleGui.PickOrCreateDeployment(interactive, "Evaluation", subscriptionId, resource.Group, resource.RegionLocation, resource.Name, null);

var keys = await AzCliConsoleGui.LoadCognitiveServicesResourceKeys(sectionHeader, subscriptionId, resource);

ConfigSetHelpers.ConfigOpenAiResource(subscriptionId, resource.RegionLocation, resource.Endpoint, deployment.Name, embeddingsDeployment.Name, keys.Key1);
ConfigSetHelpers.ConfigOpenAiResource(subscriptionId, resource.RegionLocation, resource.Endpoint, chatDeployment, embeddingsDeployment, evaluationDeployment, keys.Key1);

return new AzCli.CognitiveServicesOpenAiResourceInfo
{
Expand All @@ -43,8 +44,9 @@ public partial class AzCliConsoleGui
RegionLocation = resource.RegionLocation,
Endpoint = resource.Endpoint,
Key = keys.Key1,
ChatDeployment = deployment.Name,
ChatDeployment = chatDeployment.Name,
EmbeddingsDeployment = embeddingsDeployment.Name,
EvaluationDeployment = evaluationDeployment.Name
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/details/commands/init_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ private async Task DoInitRootConfirmVerifiedProjectResources(bool interactive, s

var chatDeployment = await AzCliConsoleGui.PickOrCreateDeployment(interactive, "Chat", subscription, openaiResource.Group, openaiResource.RegionLocation, openaiResource.Name, null);
var embeddingsDeployment = await AzCliConsoleGui.PickOrCreateDeployment(interactive, "Embeddings", subscription, openaiResource.Group, openaiResource.RegionLocation, openaiResource.Name, null);
var evaluateDeployment = await AzCliConsoleGui.PickOrCreateDeployment(interactive, "Evaluation", subscription, openaiResource.Group, openaiResource.RegionLocation, openaiResource.Name, null);
var keys = await AzCliConsoleGui.LoadCognitiveServicesResourceKeys("OPENAI RESOURCE", subscription, openaiResource);
ConfigSetHelpers.ConfigOpenAiResource(subscription, openaiResource.RegionLocation, openaiResource.Endpoint, chatDeployment.Name, embeddingsDeployment.Name, keys.Key1);
ConfigSetHelpers.ConfigOpenAiResource(subscription, openaiResource.RegionLocation, openaiResource.Endpoint, chatDeployment, embeddingsDeployment, evaluateDeployment, keys.Key1);

var searchKeys = await AzCliConsoleGui.LoadSearchResourceKeys(subscription, searchResource);
ConfigSetHelpers.ConfigSearchResource(searchResource.Endpoint, searchKeys.Key1);
Expand Down
25 changes: 16 additions & 9 deletions src/common/details/helpers/config_set_helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,30 @@ public static void ConfigureProject(string subscriptionId, string groupName, str
actions.ForEach(x => x?.Invoke(maxLabelWidth));
}

public static void ConfigOpenAiResource(string subscriptionId, string region, string endpoint, string chatDeployment, string embeddingsDeployment, string key)
public static void ConfigOpenAiResource(string subscriptionId, string region, string endpoint, AzCli.CognitiveServicesDeploymentInfo chatDeployment, AzCli.CognitiveServicesDeploymentInfo embeddingsDeployment, AzCli.CognitiveServicesDeploymentInfo evaluationDeployment, string key)
{
ConsoleHelpers.WriteLineWithHighlight($"\n`CONFIG OPEN AI RESOURCE`");
Console.WriteLine();

int maxLabelWidth = 0;
var actions = new List<Action<int>>(new Action<int>[] {
Program.InitConfigsSubscription ?
ConfigSetLambda("@subscription", subscriptionId, "Subscription", subscriptionId, ref maxLabelWidth) : null,
Program.InitConfigsEndpoint ?
ConfigSetLambda("@chat.endpoint", endpoint, "Endpoint (chat)", endpoint, ref maxLabelWidth) : null,
ConfigSetLambda("@chat.deployment", chatDeployment, "Deployment (chat)", chatDeployment, ref maxLabelWidth),
ConfigSetLambda("@subscription", subscriptionId, "Subscription", subscriptionId, ref maxLabelWidth),

ConfigSetLambda("@chat.endpoint", endpoint, "Endpoint (chat)", endpoint, ref maxLabelWidth),
ConfigSetLambda("@chat.deployment", chatDeployment.Name, "Deployment (chat)", chatDeployment.Name, ref maxLabelWidth),
ConfigSetLambda("@chat.deployment.model.name", chatDeployment.ModelName, "Model Name (chat)", chatDeployment.ModelName, ref maxLabelWidth),
ConfigSetLambda("@chat.key", key, "Key (chat)", key.Substring(0, 4) + "****************************", ref maxLabelWidth),
Program.InitConfigsEndpoint ?
ConfigSetLambda("@search.embeddings.endpoint", endpoint, "Endpoint (embeddings)", endpoint, ref maxLabelWidth) : null,
ConfigSetLambda("@search.embeddings.deployment", embeddingsDeployment, "Deployment (embeddings)", embeddingsDeployment, ref maxLabelWidth),

ConfigSetLambda("@search.embeddings.endpoint", endpoint, "Endpoint (embeddings)", endpoint, ref maxLabelWidth),
ConfigSetLambda("@search.embeddings.deployment", embeddingsDeployment.Name, "Deployment (embeddings)", embeddingsDeployment.Name, ref maxLabelWidth),
ConfigSetLambda("@search.embeddings.deployment.model.name", embeddingsDeployment.ModelName, "Model Name (embeddings)", embeddingsDeployment.ModelName, ref maxLabelWidth),
ConfigSetLambda("@search.embeddings.key", key, "Key (embeddings)", key.Substring(0, 4) + "****************************", ref maxLabelWidth),

ConfigSetLambda("@chat.evaluation.endpoint", endpoint, "Endpoint (evaluation)", endpoint, ref maxLabelWidth),
ConfigSetLambda("@chat.evaluation.deployment", evaluationDeployment.Name, "Deployment (evaluation)", evaluationDeployment.Name, ref maxLabelWidth),
ConfigSetLambda("@chat.evaluation.deployment.model.name", evaluationDeployment.ModelName, "Model Name (evaluation)", evaluationDeployment.ModelName, ref maxLabelWidth),
ConfigSetLambda("@chat.evaluation.key", key, "Key (evaluation)", key.Substring(0, 4) + "****************************", ref maxLabelWidth),

ConfigSetLambda("@chat.region", region, "Region", region, ref maxLabelWidth),
});
actions.ForEach(x => x?.Invoke(maxLabelWidth));
Expand Down

0 comments on commit 35c76c3

Please sign in to comment.