Skip to content

Commit d42ecc8

Browse files
authored
[Azure.AI.Projects] Fix Inference endpoint construction and expose Connection types (Azure#47219)
* [Azure.AI.Projects] Fix Inference Endpoint Construction and Expose Connection Types
1 parent b2ca234 commit d42ecc8

29 files changed

+375
-185
lines changed

sdk/ai/Azure.AI.Projects/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ To further diagnose and troubleshoot issues, you can enable logging following th
370370
371371
## Next steps
372372

373-
Beyond the introductory scenarios discussed, the AI Projects client library offers support for additional scenarios to help take advantage of the full feature set of the AI services. In order to help explore some of these scenarios, the AI Projects client library offers a set of samples to serve as an illustration for common scenarios. Please see the `Azure.AI.Projects/tests/Samples` for details.
373+
Beyond the introductory scenarios discussed, the AI Projects client library offers support for additional scenarios to help take advantage of the full feature set of the AI services. In order to help explore some of these scenarios, the AI Projects client library offers a set of samples to serve as an illustration for common scenarios. Please see the [Samples][samples] for details.
374374

375375
## Contributing
376376

@@ -384,6 +384,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
384384

385385
<!-- LINKS -->
386386
[RequestFailedException]: https://learn.microsoft.com/dotnet/api/azure.requestfailedexception?view=azure-dotnet
387+
[samples]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/ai/Azure.AI.Projects/tests/Samples
387388
[azure_identity]: https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet
388389
[azure_identity_dac]: https://learn.microsoft.com/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet
389390
[aiprojects_contrib]: https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md

sdk/ai/Azure.AI.Projects/api/Azure.AI.Projects.netstandard2.0.cs

Lines changed: 60 additions & 20 deletions
Large diffs are not rendered by default.

sdk/ai/Azure.AI.Projects/src/Custom/AIProjectClient.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Linq;
56
using Azure.AI.Inference;
67
using Azure.Core;
78

@@ -65,9 +66,9 @@ private T InitializeInferenceClient<T>(Func<Uri, AzureKeyCredential, T> clientFa
6566
bool useServerlessConnection = Environment.GetEnvironmentVariable("USE_SERVERLESS_CONNECTION") == "true";
6667
ConnectionType connectionType = useServerlessConnection ? ConnectionType.Serverless : ConnectionType.AzureAIServices;
6768

68-
GetConnectionResponse connectionSecret = connectionsClient.GetDefaultConnection(connectionType, true);
69+
ConnectionResponse connection = connectionsClient.GetDefaultConnection(connectionType, true);
6970

70-
if (connectionSecret.Properties is InternalConnectionPropertiesApiKeyAuth apiKeyAuthProperties)
71+
if (connection.Properties is ConnectionPropertiesApiKeyAuth apiKeyAuthProperties)
7172
{
7273
if (string.IsNullOrWhiteSpace(apiKeyAuthProperties.Target))
7374
{
@@ -80,6 +81,14 @@ private T InitializeInferenceClient<T>(Func<Uri, AzureKeyCredential, T> clientFa
8081
}
8182

8283
var credential = new AzureKeyCredential(apiKeyAuthProperties.Credentials.Key);
84+
if (!useServerlessConnection)
85+
{
86+
// Be sure to use the Azure resource name here, not the connection name. Connection name is something that
87+
// admins can pick when they manually create a new connection (or use bicep). Get the Azure resource name
88+
// from the end of the connection id.
89+
var azureResourceName = connection.Id.Split('/').Last();
90+
endpoint = new Uri($"https://{azureResourceName}.services.ai.azure.com/models");
91+
}
8392
return clientFactory(endpoint, credential);
8493
}
8594
else
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
6+
namespace Azure.AI.Projects
7+
{
8+
[CodeGenModel("InternalConnectionProperties")]
9+
public abstract partial class ConnectionProperties
10+
{
11+
/// <summary> Authentication type of the connection target. </summary>
12+
public AuthenticationType AuthType { get; set; }
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
6+
namespace Azure.AI.Projects
7+
{
8+
[CodeGenModel("InternalConnectionPropertiesApiKeyAuth")]
9+
public partial class ConnectionPropertiesApiKeyAuth : ConnectionProperties
10+
{
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using Azure.Core;
7+
8+
namespace Azure.AI.Projects
9+
{
10+
/// <summary> Response from the listSecrets operation. </summary>
11+
[CodeGenModel("GetConnectionResponse")]
12+
public partial class ConnectionResponse
13+
{
14+
}
15+
}

sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionsClient.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,27 +292,27 @@ public virtual Response GetConnections(string category, bool? includeAll, string
292292
/// <param name="cancellationToken"> The cancellation token to use. </param>
293293
/// <exception cref="ArgumentNullException"> <paramref name="connectionName"/> is null. </exception>
294294
/// <exception cref="ArgumentException"> <paramref name="connectionName"/> is an empty string, and was expected to be non-empty. </exception>
295-
public virtual async Task<Response<GetConnectionResponse>> GetConnectionAsync(string connectionName, CancellationToken cancellationToken = default)
295+
public virtual async Task<Response<ConnectionResponse>> GetConnectionAsync(string connectionName, CancellationToken cancellationToken = default)
296296
{
297297
Argument.AssertNotNullOrEmpty(connectionName, nameof(connectionName));
298298

299299
RequestContext context = FromCancellationToken(cancellationToken);
300300
Response response = await GetConnectionAsync(connectionName, context).ConfigureAwait(false);
301-
return Response.FromValue(GetConnectionResponse.FromResponse(response), response);
301+
return Response.FromValue(ConnectionResponse.FromResponse(response), response);
302302
}
303303

304304
/// <summary> Get the details of a single connection, without credentials. </summary>
305305
/// <param name="connectionName"> Connection Name. </param>
306306
/// <param name="cancellationToken"> The cancellation token to use. </param>
307307
/// <exception cref="ArgumentNullException"> <paramref name="connectionName"/> is null. </exception>
308308
/// <exception cref="ArgumentException"> <paramref name="connectionName"/> is an empty string, and was expected to be non-empty. </exception>
309-
public virtual Response<GetConnectionResponse> GetConnection(string connectionName, CancellationToken cancellationToken = default)
309+
public virtual Response<ConnectionResponse> GetConnection(string connectionName, CancellationToken cancellationToken = default)
310310
{
311311
Argument.AssertNotNullOrEmpty(connectionName, nameof(connectionName));
312312

313313
RequestContext context = FromCancellationToken(cancellationToken);
314314
Response response = GetConnection(connectionName, context);
315-
return Response.FromValue(GetConnectionResponse.FromResponse(response), response);
315+
return Response.FromValue(ConnectionResponse.FromResponse(response), response);
316316
}
317317

318318
/// <summary>
@@ -399,15 +399,15 @@ public virtual Response GetConnection(string connectionName, RequestContext cont
399399
/// <param name="cancellationToken"> The cancellation token to use. </param>
400400
/// <exception cref="ArgumentNullException"> <paramref name="connectionName"/> or <paramref name="ignored"/> is null. </exception>
401401
/// <exception cref="ArgumentException"> <paramref name="connectionName"/> is an empty string, and was expected to be non-empty. </exception>
402-
public virtual async Task<Response<GetConnectionResponse>> GetConnectionWithSecretsAsync(string connectionName, string ignored, CancellationToken cancellationToken = default)
402+
public virtual async Task<Response<ConnectionResponse>> GetConnectionWithSecretsAsync(string connectionName, string ignored, CancellationToken cancellationToken = default)
403403
{
404404
Argument.AssertNotNullOrEmpty(connectionName, nameof(connectionName));
405405
Argument.AssertNotNull(ignored, nameof(ignored));
406406

407407
GetConnectionWithSecretsRequest getConnectionWithSecretsRequest = new GetConnectionWithSecretsRequest(ignored, null);
408408
RequestContext context = FromCancellationToken(cancellationToken);
409409
Response response = await GetConnectionWithSecretsAsync(connectionName, getConnectionWithSecretsRequest.ToRequestContent(), context).ConfigureAwait(false);
410-
return Response.FromValue(GetConnectionResponse.FromResponse(response), response);
410+
return Response.FromValue(ConnectionResponse.FromResponse(response), response);
411411
}
412412

413413
/// <summary> Get the details of a single connection, including credentials (if available). </summary>
@@ -416,15 +416,15 @@ public virtual async Task<Response<GetConnectionResponse>> GetConnectionWithSecr
416416
/// <param name="cancellationToken"> The cancellation token to use. </param>
417417
/// <exception cref="ArgumentNullException"> <paramref name="connectionName"/> or <paramref name="ignored"/> is null. </exception>
418418
/// <exception cref="ArgumentException"> <paramref name="connectionName"/> is an empty string, and was expected to be non-empty. </exception>
419-
public virtual Response<GetConnectionResponse> GetConnectionWithSecrets(string connectionName, string ignored, CancellationToken cancellationToken = default)
419+
public virtual Response<ConnectionResponse> GetConnectionWithSecrets(string connectionName, string ignored, CancellationToken cancellationToken = default)
420420
{
421421
Argument.AssertNotNullOrEmpty(connectionName, nameof(connectionName));
422422
Argument.AssertNotNull(ignored, nameof(ignored));
423423

424424
GetConnectionWithSecretsRequest getConnectionWithSecretsRequest = new GetConnectionWithSecretsRequest(ignored, null);
425425
RequestContext context = FromCancellationToken(cancellationToken);
426426
Response response = GetConnectionWithSecrets(connectionName, getConnectionWithSecretsRequest.ToRequestContent(), context);
427-
return Response.FromValue(GetConnectionResponse.FromResponse(response), response);
427+
return Response.FromValue(ConnectionResponse.FromResponse(response), response);
428428
}
429429

430430
/// <summary>
@@ -515,7 +515,7 @@ public virtual Response GetConnectionWithSecrets(string connectionName, RequestC
515515
/// <param name="includeAll"> Indicates whether to list datastores. Service default: do not list datastores. </param>
516516
/// <param name="target"> Target of the workspace connection. </param>
517517
/// <param name="cancellationToken"> The cancellation token to use. </param>
518-
public virtual async Task<Response<GetConnectionResponse>> GetDefaultConnectionAsync(ConnectionType category, bool? withCredential = null, bool? includeAll = null, string target = null, CancellationToken cancellationToken = default)
518+
public virtual async Task<Response<ConnectionResponse>> GetDefaultConnectionAsync(ConnectionType category, bool? withCredential = null, bool? includeAll = null, string target = null, CancellationToken cancellationToken = default)
519519
{
520520
ListConnectionsResponse connections = await GetConnectionsAsync(category, includeAll, target, cancellationToken).ConfigureAwait(false);
521521

@@ -536,7 +536,7 @@ public virtual async Task<Response<GetConnectionResponse>> GetDefaultConnectionA
536536
/// <param name="includeAll"> Indicates whether to list datastores. Service default: do not list datastores. </param>
537537
/// <param name="target"> Target of the workspace connection. </param>
538538
/// <param name="cancellationToken"> The cancellation token to use. </param>
539-
public virtual Response<GetConnectionResponse> GetDefaultConnection(ConnectionType category, bool? withCredential = null, bool? includeAll = null, string target = null, CancellationToken cancellationToken = default)
539+
public virtual Response<ConnectionResponse> GetDefaultConnection(ConnectionType category, bool? withCredential = null, bool? includeAll = null, string target = null, CancellationToken cancellationToken = default)
540540
{
541541
ListConnectionsResponse connections = GetConnections(category, includeAll, target, cancellationToken);
542542

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
namespace Azure.AI.Projects
5+
{
6+
/// <summary> The credentials needed for API key authentication. </summary>
7+
public partial class CredentialsApiKeyAuth
8+
{
9+
}
10+
}

sdk/ai/Azure.AI.Projects/src/Custom/Connection/GetConnectionResponse.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

sdk/ai/Azure.AI.Projects/src/Generated/AIProjectsModelFactory.cs

Lines changed: 43 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)