Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding c# ai resource management #248

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/ai/.x/help/search.index.update
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ SEARCH INDEX UPDATE

USAGE: ai index update [...]

AZURE AI
--subscription SUBSCRIPTION (see: ai help search subscription)
--project PROJECT (see: ai help search project)
--group group (see: ai help search group)

AZURE SEARCH
--index-name NAME (see: ai help search index name)
--index-kind KIND (see: ai help search index kind)
Expand All @@ -26,12 +21,10 @@ USAGE: ai index update [...]

OPENAI EMBEDDINGS
--embedding-deployment DEPLOYMENT (see: ai help search embedding deployment)
--embedding-model MODEL (see: ai help search embedding model)

DATA
--file FILE (see: ai help search index file)
--files FILEs (see: ai help search index files)
--external-source (see: ai help search index external source)

EXAMPLE

Expand Down
2 changes: 1 addition & 1 deletion src/ai/ai-cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

<ItemGroup>
<PackageReference Include="Azure.AI.Vision.ImageAnalysis" Version="1.0.0-beta.2" />
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Azure.Identity" Version="1.11.0-beta.1" />
<PackageReference Include="Azure.Search.Documents" Version="11.5.0-beta.5" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageReference Include="JmesPath.Net" Version="1.0.308" />
Expand Down
24 changes: 3 additions & 21 deletions src/ai/commands/search_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,9 @@ private void DoIndexUpdate()

DoIndexUpdateWithSK(searchEndpoint, searchApiKey, embeddingsEndpoint, embeddingsDeployment, embeddingsApiKey, searchIndexName, pattern);
}
else // use GenAi
else
{
var subscription = SubscriptionToken.Data().Demand(_values, action, command, checkConfig: "subscription");
var project = ProjectNameToken.Data().Demand(_values, action, command, checkConfig: "project");
var group = ResourceGroupNameToken.Data().Demand(_values, action, command, checkConfig: "group");
var searchEndpoint = DemandSearchEndpointUri(action, command);
var searchApiKey = DemandSearchApiKey(action, command);
var embeddingsEndpoint = DemandEmbeddingsEndpointUri(action, command);
var embeddingsApiKey = DemandEmbeddingsApiKey(action, command);
var embeddingModelDeployment = SearchEmbeddingModelDeploymentNameToken.Data().Demand(_values, action, command, checkConfig: "embedding.model.deployment.name");
var embeddingModelName = SearchEmbeddingModelNameToken.Data().Demand(_values, action, command, checkConfig: "embedding.model.name");
var externalSourceUrl = ExternalSourceToken.Data().GetOrDefault(_values);

output = DoIndexUpdateWithGenAi(subscription, group, project, searchIndexName, embeddingModelDeployment, embeddingModelName, pattern, externalSourceUrl);

var parsed = !string.IsNullOrEmpty(output) ? JToken.Parse(output) : null;
var index = parsed?.Type == JTokenType.Object ? parsed["index"] : null;
if (index == null)
{
_values.AddThrowError("ERROR:", $"Failed to update search index '{searchIndexName}'");
}
_values.AddThrowError("ERROR:", $"No blob container or sk index kind specified.");
}

if (!_quiet) Console.WriteLine($"{message} Done!\n");
Expand All @@ -165,7 +147,7 @@ private string DoIndexUpdateWithGenAi(string subscription, string groupName, str
var env = ConfigEnvironmentHelpers.GetEnvironment(_values);
env = new Dictionary<string, string>(env.Where(x => x.Key == "AZURE_OPENAI_KEY"));

return PythonSDKWrapper.UpdateMLIndex(_values, subscription, groupName, projectName, indexName, embeddingModelDeployment, embeddingModelName, dataFiles, externalSourceUrl, env);
return AIClientWrapper.UpdateMLIndex(_values, subscription, groupName, projectName, indexName, embeddingModelDeployment, embeddingModelName, dataFiles, externalSourceUrl, env);
}

private async Task<string> DoIndexUpdateWithAISearch(string aiServicesApiKey, string searchEndpoint, string searchApiKey, string embeddingsEndpoint, string embeddingsDeployment, string embeddingsApiKey, string searchIndexName, string dataSourceConnectionName, string blobContainer, string pattern, string skillsetName, string indexerName, string idFieldName, string contentFieldName, string vectorFieldName)
Expand Down
18 changes: 9 additions & 9 deletions src/ai/commands/service_command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void DoCreateResource()
var message = $"{action} '{name}'";

if (!_quiet) Console.WriteLine(message);
var output = PythonSDKWrapper.CreateResource(_values, subscription, group, name, location, displayName, description);
var output = AIClientWrapper.CreateResource(_values, subscription, group, name, location, displayName, description);
if (!_quiet) Console.WriteLine($"{message} Done!\n");

if (!_quiet) Console.WriteLine(output);
Expand All @@ -114,7 +114,7 @@ private void DoCreateProject()
var message = $"{action} '{name}'";

if (!_quiet) Console.WriteLine(message);
var output = PythonSDKWrapper.CreateProject(_values, subscription, group, resource, name, location, displayName, description);
var output = AIClientWrapper.CreateProject(_values, subscription, group, resource, name, location, displayName, description);
if (!_quiet) Console.WriteLine($"{message} Done!\n");

if (!_quiet) Console.WriteLine(output);
Expand All @@ -141,7 +141,7 @@ private void DoCreateConnection()
var message = $"{action} '{connectionName}'";

if (!_quiet) Console.WriteLine(message);
var output = PythonSDKWrapper.CreateConnection(_values, subscription, group, project, connectionName, connectionType, cogServicesResourceKind, connectionEndpoint, connectionKey);
var output = AIClientWrapper.CreateConnection(_values, subscription, group, project, connectionName, connectionType, cogServicesResourceKind, connectionEndpoint, connectionKey);
if (!_quiet) Console.WriteLine($"{message} Done!\n");

if (!_quiet) Console.WriteLine(output);
Expand All @@ -157,7 +157,7 @@ private void DoListResources()
var message = $"{action} for '{subscription}'";

if (!_quiet) Console.WriteLine(message);
var output = PythonSDKWrapper.ListResources(_values, subscription);
var output = AIClientWrapper.ListResources(_values, subscription);
if (!_quiet) Console.WriteLine($"{message} Done!\n");

if (!_quiet) Console.WriteLine(output);
Expand All @@ -173,7 +173,7 @@ private void DoListProjects()
var message = $"{action} for '{subscription}'";

if (!_quiet) Console.WriteLine(message);
var output = PythonSDKWrapper.ListProjects(_values, subscription);
var output = AIClientWrapper.ListProjects(_values, subscription);
if (!_quiet) Console.WriteLine($"{message} Done!\n");

if (!_quiet) Console.WriteLine(output);
Expand All @@ -191,7 +191,7 @@ private void DoListConnections()
var message = $"{action} for '{project}'";

if (!_quiet) Console.WriteLine(message);
var output = PythonSDKWrapper.ListConnections(_values, subscription, group, project);
var output = AIClientWrapper.ListConnections(_values, subscription, group, project);
if (!_quiet) Console.WriteLine($"{message} Done!\n");

if (!_quiet) Console.WriteLine(output);
Expand All @@ -212,7 +212,7 @@ private void DoDeleteResource()
var message = $"{action} for '{resourceName}'";

if (!_quiet) Console.WriteLine(message);
var output = PythonSDKWrapper.DeleteResource(_values, subscription, group, resourceName, deleteDependentResources);
var output = AIClientWrapper.DeleteResource(_values, subscription, group, resourceName, deleteDependentResources);
if (!_quiet) Console.WriteLine($"{message} Done!\n");

if (!_quiet) Console.WriteLine(output);
Expand All @@ -233,7 +233,7 @@ private void DoDeleteProject()
var message = $"{action} for '{projectName}'";

if (!_quiet) Console.WriteLine(message);
var output = PythonSDKWrapper.DeleteProject(_values, subscription, group, projectName, deleteDependentResources);
var output = AIClientWrapper.DeleteProject(_values, subscription, group, projectName, deleteDependentResources);
if (!_quiet) Console.WriteLine($"{message} Done!\n");

if (!_quiet) Console.WriteLine(output);
Expand All @@ -253,7 +253,7 @@ private void DoDeleteConnection()
var message = $"{action} for '{connectionName}'";

if (!_quiet) Console.WriteLine(message);
var output = PythonSDKWrapper.DeleteConnection(_values, subscription, group, projectName, connectionName);
var output = AIClientWrapper.DeleteConnection(_values, subscription, group, projectName, connectionName);
if (!_quiet) Console.WriteLine($"{message} Done!\n");

if (!_quiet) Console.WriteLine(output);
Expand Down
6 changes: 6 additions & 0 deletions src/common/common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.0-beta.1" />
<PackageReference Include="Azure.ResourceManager" Version="1.11.0-beta.1" />
<PackageReference Include="Azure.ResourceManager.CognitiveServices" Version="1.3.1" />
<PackageReference Include="Azure.ResourceManager.KeyVault" Version="1.2.0" />
<PackageReference Include="Azure.ResourceManager.MachineLearning" Version="1.2.0-beta.3" />
<PackageReference Include="Azure.ResourceManager.Storage" Version="1.2.0" />
<PackageReference Include="JmesPath.Net" Version="1.0.308" />
<PackageReference Include="Microsoft.CognitiveServices.Speech" Version="1.35.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public partial class AiSdkConsoleGui
{
try
{
var projectJson = PythonSDKWrapper.ListProjects(values, subscription);
var projectJson = AIClientWrapper.ListProjects(values, subscription);
var projects = JObject.Parse(projectJson)["projects"] as JArray;
var project = projects.FirstOrDefault(x => x["name"].ToString() == projectName);
if (project == null) return (null, null, null);

var hub = project["workspace_hub"].ToString();
var hubName = hub.Split('/').Last();

var json = PythonSDKWrapper.ListConnections(values, subscription, groupName, projectName);
var json = AIClientWrapper.ListConnections(values, subscription, groupName, projectName);
if (string.IsNullOrEmpty(json)) return (null, null, null);

var connections = JObject.Parse(json)["connections"] as JArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static async Task<AiHubResourceInfo> PickOrCreateAiHubResource(bool allo
ConsoleHelpers.WriteLineWithHighlight($"\n`AZURE AI RESOURCE`");
Console.Write("\rName: *** Loading choices ***");

var json = PythonSDKWrapper.ListResources(values, subscription);
var json = AIClientWrapper.ListResources(values, subscription);
if (Program.Debug) Console.WriteLine(json);

var parsed = !string.IsNullOrEmpty(json) ? JToken.Parse(json) : null;
Expand Down Expand Up @@ -174,7 +174,7 @@ private static async Task<JToken> TryCreateAiHubResourceInteractive(ICommandValu
description ??= name;

Console.Write("*** CREATING ***");
var json = PythonSDKWrapper.CreateResource(values, subscription, groupName, name, locationName, displayName, description, openAiResourceId, openAiResourceKind);
var json = AIClientWrapper.CreateResource(values, subscription, groupName, name, locationName, displayName, description, openAiResourceId, openAiResourceKind);

Console.WriteLine("\r*** CREATED *** ");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static AiHubProjectInfo PickOrCreateAiHubProject(bool allowCreate, IComm
ConsoleHelpers.WriteLineWithHighlight($"\n`AZURE AI PROJECT`");
Console.Write("\rName: *** Loading choices ***");

var json = PythonSDKWrapper.ListProjects(values, subscription);
var json = AIClientWrapper.ListProjects(values, subscription);
if (Program.Debug) Console.WriteLine(json);

var parsed = !string.IsNullOrEmpty(json) ? JToken.Parse(json) : null;
Expand Down Expand Up @@ -204,7 +204,7 @@ private static JToken TryCreateAiHubProjectInteractive(ICommandValues values, st
description ??= name;

Console.Write("*** CREATING ***");
var json = PythonSDKWrapper.CreateProject(values, subscription, group, resourceId, name, location, displayName, description);
var json = AIClientWrapper.CreateProject(values, subscription, group, resourceId, name, location, displayName, description);

Console.WriteLine("\r*** CREATED *** ");

Expand Down Expand Up @@ -236,7 +236,7 @@ public static void GetOrCreateAiHubProjectConnections(ICommandValues values, boo

var connectionType = "azure_open_ai";
var connectionJson = createOpenAiConnection
? PythonSDKWrapper.CreateConnection(values, subscription, groupName, projectName, connectionName, connectionType, null, openAiEndpoint, openAiKey)
? AIClientWrapper.CreateConnection(values, subscription, groupName, projectName, connectionName, connectionType, null, openAiEndpoint, openAiKey)
: GetConnection(values, subscription, groupName, projectName, connectionName);

var message = createSearchConnection ? "\r*** CREATED *** " : null;
Expand Down Expand Up @@ -276,7 +276,7 @@ public static void GetOrCreateAiHubProjectConnections(ICommandValues values, boo

var connectionType = "cognitive_search";
var connectionJson = createSearchConnection
? PythonSDKWrapper.CreateConnection(values, subscription, groupName, projectName, connectionName, connectionType, null, searchEndpoint, searchKey)
? AIClientWrapper.CreateConnection(values, subscription, groupName, projectName, connectionName, connectionType, null, searchEndpoint, searchKey)
: GetConnection(values, subscription, groupName, projectName, connectionName);

var message = createSearchConnection ? "\r*** CREATED *** " : null;
Expand Down Expand Up @@ -308,7 +308,7 @@ private static string GetConnection(ICommandValues values, string subscription,
{
try
{
return PythonSDKWrapper.GetConnection(values, subscription, groupName, projectName, connectionName);
return AIClientWrapper.GetConnection(values, subscription, groupName, projectName, connectionName);
}
catch (Exception)
{
Expand Down
Loading