diff --git a/sdk/ai/Azure.AI.Projects/README.md b/sdk/ai/Azure.AI.Projects/README.md index 8f6391aa9603d..289cf65ef2063 100644 --- a/sdk/ai/Azure.AI.Projects/README.md +++ b/sdk/ai/Azure.AI.Projects/README.md @@ -370,7 +370,7 @@ To further diagnose and troubleshoot issues, you can enable logging following th ## Next steps -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. +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. ## Contributing @@ -384,6 +384,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [RequestFailedException]: https://learn.microsoft.com/dotnet/api/azure.requestfailedexception?view=azure-dotnet +[samples]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/ai/Azure.AI.Projects/tests/Samples [azure_identity]: https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet [azure_identity_dac]: https://learn.microsoft.com/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet [aiprojects_contrib]: https://github.com/Azure/azure-sdk-for-net/blob/main/CONTRIBUTING.md diff --git a/sdk/ai/Azure.AI.Projects/api/Azure.AI.Projects.netstandard2.0.cs b/sdk/ai/Azure.AI.Projects/api/Azure.AI.Projects.netstandard2.0.cs index cf672807e64ae..d44558f16948d 100644 --- a/sdk/ai/Azure.AI.Projects/api/Azure.AI.Projects.netstandard2.0.cs +++ b/sdk/ai/Azure.AI.Projects/api/Azure.AI.Projects.netstandard2.0.cs @@ -483,10 +483,14 @@ public static partial class AIProjectsModelFactory { public static Azure.AI.Projects.AgentPageableListOfVectorStore AgentPageableListOfVectorStore(Azure.AI.Projects.AgentPageableListOfVectorStoreObject @object = default(Azure.AI.Projects.AgentPageableListOfVectorStoreObject), System.Collections.Generic.IEnumerable data = null, string firstId = null, string lastId = null, bool hasMore = false) { throw null; } public static Azure.AI.Projects.AgentPageableListOfVectorStoreFile AgentPageableListOfVectorStoreFile(Azure.AI.Projects.AgentPageableListOfVectorStoreFileObject @object = default(Azure.AI.Projects.AgentPageableListOfVectorStoreFileObject), System.Collections.Generic.IEnumerable data = null, string firstId = null, string lastId = null, bool hasMore = false) { throw null; } + public static Azure.AI.Projects.ConnectionProperties ConnectionProperties(Azure.AI.Projects.ConnectionType category = Azure.AI.Projects.ConnectionType.AzureOpenAI, string target = null) { throw null; } + public static Azure.AI.Projects.ConnectionPropertiesApiKeyAuth ConnectionPropertiesApiKeyAuth(Azure.AI.Projects.ConnectionType category = Azure.AI.Projects.ConnectionType.AzureOpenAI, string target = null, Azure.AI.Projects.CredentialsApiKeyAuth credentials = null) { throw null; } + public static Azure.AI.Projects.ConnectionResponse ConnectionResponse(string id = null, string name = null, Azure.AI.Projects.ConnectionProperties properties = null) { throw null; } + public static Azure.AI.Projects.CredentialsApiKeyAuth CredentialsApiKeyAuth(string key = null) { throw null; } public static Azure.AI.Projects.Evaluation Evaluation(string id = null, Azure.AI.Projects.InputData data = null, string displayName = null, string description = null, Azure.AI.Projects.SystemData systemData = null, string status = null, System.Collections.Generic.IDictionary tags = null, System.Collections.Generic.IDictionary properties = null, System.Collections.Generic.IDictionary evaluators = null) { throw null; } public static Azure.AI.Projects.EvaluationSchedule EvaluationSchedule(string name = null, Azure.AI.Projects.ApplicationInsightsConfiguration data = null, string description = null, Azure.AI.Projects.SystemData systemData = null, string provisioningStatus = null, System.Collections.Generic.IDictionary tags = null, System.Collections.Generic.IDictionary properties = null, System.Collections.Generic.IDictionary evaluators = null, Azure.AI.Projects.Trigger trigger = null) { throw null; } public static Azure.AI.Projects.GetWorkspaceResponse GetWorkspaceResponse(string id = null, string name = null, Azure.AI.Projects.WorkspaceProperties properties = null) { throw null; } - public static Azure.AI.Projects.ListConnectionsResponse ListConnectionsResponse(System.Collections.Generic.IEnumerable value = null) { throw null; } + public static Azure.AI.Projects.ListConnectionsResponse ListConnectionsResponse(System.Collections.Generic.IEnumerable value = null) { throw null; } public static Azure.AI.Projects.MessageDelta MessageDelta(Azure.AI.Projects.MessageRole role = default(Azure.AI.Projects.MessageRole), System.Collections.Generic.IEnumerable content = null) { throw null; } public static Azure.AI.Projects.MessageDeltaChunk MessageDeltaChunk(string id = null, Azure.AI.Projects.MessageDeltaChunkObject @object = default(Azure.AI.Projects.MessageDeltaChunkObject), Azure.AI.Projects.MessageDelta delta = null) { throw null; } public static Azure.AI.Projects.MessageDeltaContent MessageDeltaContent(int index = 0, string type = null) { throw null; } @@ -636,6 +640,43 @@ protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } + public abstract partial class ConnectionProperties : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + protected ConnectionProperties(Azure.AI.Projects.ConnectionType category, string target) { } + public Azure.AI.Projects.AuthenticationType AuthType { get { throw null; } set { } } + public Azure.AI.Projects.ConnectionType Category { get { throw null; } } + public string Target { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Projects.ConnectionProperties System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Projects.ConnectionProperties System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class ConnectionPropertiesApiKeyAuth : Azure.AI.Projects.ConnectionProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal ConnectionPropertiesApiKeyAuth() : base (default(Azure.AI.Projects.ConnectionType), default(string)) { } + public Azure.AI.Projects.CredentialsApiKeyAuth Credentials { get { throw null; } } + protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Projects.ConnectionPropertiesApiKeyAuth System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Projects.ConnectionPropertiesApiKeyAuth System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class ConnectionResponse : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal ConnectionResponse() { } + public string Id { get { throw null; } } + public string Name { get { throw null; } } + public Azure.AI.Projects.ConnectionProperties Properties { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Projects.ConnectionResponse System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Projects.ConnectionResponse System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public partial class ConnectionsClient { protected ConnectionsClient() { } @@ -645,19 +686,19 @@ public ConnectionsClient(System.Uri endpoint, string subscriptionId, string reso public ConnectionsClient(System.Uri endpoint, string subscriptionId, string resourceGroupName, string projectName, Azure.Core.TokenCredential credential, Azure.AI.Projects.AIProjectClientOptions options) { } public virtual Azure.Core.Pipeline.HttpPipeline Pipeline { get { throw null; } } public virtual Azure.Response GetConnection(string connectionName, Azure.RequestContext context) { throw null; } - public virtual Azure.Response GetConnection(string connectionName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetConnection(string connectionName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task GetConnectionAsync(string connectionName, Azure.RequestContext context) { throw null; } - public virtual System.Threading.Tasks.Task> GetConnectionAsync(string connectionName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetConnectionAsync(string connectionName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetConnections(Azure.AI.Projects.ConnectionType? category = default(Azure.AI.Projects.ConnectionType?), bool? includeAll = default(bool?), string target = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetConnections(string category, bool? includeAll, string target, Azure.RequestContext context) { throw null; } public virtual System.Threading.Tasks.Task> GetConnectionsAsync(Azure.AI.Projects.ConnectionType? category = default(Azure.AI.Projects.ConnectionType?), bool? includeAll = default(bool?), string target = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task GetConnectionsAsync(string category, bool? includeAll, string target, Azure.RequestContext context) { throw null; } public virtual Azure.Response GetConnectionWithSecrets(string connectionName, Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; } - public virtual Azure.Response GetConnectionWithSecrets(string connectionName, string ignored, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetConnectionWithSecrets(string connectionName, string ignored, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task GetConnectionWithSecretsAsync(string connectionName, Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; } - public virtual System.Threading.Tasks.Task> GetConnectionWithSecretsAsync(string connectionName, string ignored, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response GetDefaultConnection(Azure.AI.Projects.ConnectionType category, bool? withCredential = default(bool?), bool? includeAll = default(bool?), string target = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> GetDefaultConnectionAsync(Azure.AI.Projects.ConnectionType category, bool? withCredential = default(bool?), bool? includeAll = default(bool?), string target = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetConnectionWithSecretsAsync(string connectionName, string ignored, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetDefaultConnection(Azure.AI.Projects.ConnectionType category, bool? withCredential = default(bool?), bool? includeAll = default(bool?), string target = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetDefaultConnectionAsync(Azure.AI.Projects.ConnectionType category, bool? withCredential = default(bool?), bool? includeAll = default(bool?), string target = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetWorkspace(Azure.RequestContext context) { throw null; } public virtual Azure.Response GetWorkspace(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task GetWorkspaceAsync(Azure.RequestContext context) { throw null; } @@ -672,6 +713,17 @@ public enum ConnectionType AzureAISearch = 4, ApiKey = 5, } + public partial class CredentialsApiKeyAuth : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal CredentialsApiKeyAuth() { } + public string Key { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Projects.CredentialsApiKeyAuth System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Projects.CredentialsApiKeyAuth System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public partial class CronTrigger : Azure.AI.Projects.Trigger, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public CronTrigger(string expression) { } @@ -942,18 +994,6 @@ protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter write string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class GetConnectionResponse : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel - { - internal GetConnectionResponse() { } - public string Id { get { throw null; } } - public string Name { get { throw null; } } - protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.AI.Projects.GetConnectionResponse System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.AI.Projects.GetConnectionResponse System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - } public partial class GetWorkspaceResponse : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal GetWorkspaceResponse() { } @@ -1010,7 +1050,7 @@ protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer public partial class ListConnectionsResponse : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { internal ListConnectionsResponse() { } - public System.Collections.Generic.IReadOnlyList Value { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Value { get { throw null; } } protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.AI.Projects.ListConnectionsResponse System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } diff --git a/sdk/ai/Azure.AI.Projects/src/Custom/AIProjectClient.cs b/sdk/ai/Azure.AI.Projects/src/Custom/AIProjectClient.cs index 3d83e091b5f60..12a14ba3db68a 100644 --- a/sdk/ai/Azure.AI.Projects/src/Custom/AIProjectClient.cs +++ b/sdk/ai/Azure.AI.Projects/src/Custom/AIProjectClient.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Linq; using Azure.AI.Inference; using Azure.Core; @@ -65,9 +66,9 @@ private T InitializeInferenceClient(Func clientFa bool useServerlessConnection = Environment.GetEnvironmentVariable("USE_SERVERLESS_CONNECTION") == "true"; ConnectionType connectionType = useServerlessConnection ? ConnectionType.Serverless : ConnectionType.AzureAIServices; - GetConnectionResponse connectionSecret = connectionsClient.GetDefaultConnection(connectionType, true); + ConnectionResponse connection = connectionsClient.GetDefaultConnection(connectionType, true); - if (connectionSecret.Properties is InternalConnectionPropertiesApiKeyAuth apiKeyAuthProperties) + if (connection.Properties is ConnectionPropertiesApiKeyAuth apiKeyAuthProperties) { if (string.IsNullOrWhiteSpace(apiKeyAuthProperties.Target)) { @@ -80,6 +81,14 @@ private T InitializeInferenceClient(Func clientFa } var credential = new AzureKeyCredential(apiKeyAuthProperties.Credentials.Key); + if (!useServerlessConnection) + { + // Be sure to use the Azure resource name here, not the connection name. Connection name is something that + // admins can pick when they manually create a new connection (or use bicep). Get the Azure resource name + // from the end of the connection id. + var azureResourceName = connection.Id.Split('/').Last(); + endpoint = new Uri($"https://{azureResourceName}.services.ai.azure.com/models"); + } return clientFactory(endpoint, credential); } else diff --git a/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionProperties.cs b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionProperties.cs new file mode 100644 index 0000000000000..47ccd0c0c6e1d --- /dev/null +++ b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionProperties.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.AI.Projects +{ + [CodeGenModel("InternalConnectionProperties")] + public abstract partial class ConnectionProperties + { + /// Authentication type of the connection target. + public AuthenticationType AuthType { get; set; } + } +} diff --git a/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionPropertiesApiKeyAuth.cs b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionPropertiesApiKeyAuth.cs new file mode 100644 index 0000000000000..b3b7f41f6f4ad --- /dev/null +++ b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionPropertiesApiKeyAuth.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.AI.Projects +{ + [CodeGenModel("InternalConnectionPropertiesApiKeyAuth")] + public partial class ConnectionPropertiesApiKeyAuth : ConnectionProperties + { + } +} diff --git a/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionResponse.cs b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionResponse.cs new file mode 100644 index 0000000000000..f383d087dd2d6 --- /dev/null +++ b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionResponse.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.Projects +{ + /// Response from the listSecrets operation. + [CodeGenModel("GetConnectionResponse")] + public partial class ConnectionResponse + { + } +} diff --git a/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionsClient.cs b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionsClient.cs index 2be27e4e24eca..18ec49643ecaa 100644 --- a/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionsClient.cs +++ b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/ConnectionsClient.cs @@ -292,13 +292,13 @@ public virtual Response GetConnections(string category, bool? includeAll, string /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> GetConnectionAsync(string connectionName, CancellationToken cancellationToken = default) + public virtual async Task> GetConnectionAsync(string connectionName, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(connectionName, nameof(connectionName)); RequestContext context = FromCancellationToken(cancellationToken); Response response = await GetConnectionAsync(connectionName, context).ConfigureAwait(false); - return Response.FromValue(GetConnectionResponse.FromResponse(response), response); + return Response.FromValue(ConnectionResponse.FromResponse(response), response); } /// Get the details of a single connection, without credentials. @@ -306,13 +306,13 @@ public virtual async Task> GetConnectionAsync(st /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual Response GetConnection(string connectionName, CancellationToken cancellationToken = default) + public virtual Response GetConnection(string connectionName, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(connectionName, nameof(connectionName)); RequestContext context = FromCancellationToken(cancellationToken); Response response = GetConnection(connectionName, context); - return Response.FromValue(GetConnectionResponse.FromResponse(response), response); + return Response.FromValue(ConnectionResponse.FromResponse(response), response); } /// @@ -399,7 +399,7 @@ public virtual Response GetConnection(string connectionName, RequestContext cont /// The cancellation token to use. /// or is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> GetConnectionWithSecretsAsync(string connectionName, string ignored, CancellationToken cancellationToken = default) + public virtual async Task> GetConnectionWithSecretsAsync(string connectionName, string ignored, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(connectionName, nameof(connectionName)); Argument.AssertNotNull(ignored, nameof(ignored)); @@ -407,7 +407,7 @@ public virtual async Task> GetConnectionWithSecr GetConnectionWithSecretsRequest getConnectionWithSecretsRequest = new GetConnectionWithSecretsRequest(ignored, null); RequestContext context = FromCancellationToken(cancellationToken); Response response = await GetConnectionWithSecretsAsync(connectionName, getConnectionWithSecretsRequest.ToRequestContent(), context).ConfigureAwait(false); - return Response.FromValue(GetConnectionResponse.FromResponse(response), response); + return Response.FromValue(ConnectionResponse.FromResponse(response), response); } /// Get the details of a single connection, including credentials (if available). @@ -416,7 +416,7 @@ public virtual async Task> GetConnectionWithSecr /// The cancellation token to use. /// or is null. /// is an empty string, and was expected to be non-empty. - public virtual Response GetConnectionWithSecrets(string connectionName, string ignored, CancellationToken cancellationToken = default) + public virtual Response GetConnectionWithSecrets(string connectionName, string ignored, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(connectionName, nameof(connectionName)); Argument.AssertNotNull(ignored, nameof(ignored)); @@ -424,7 +424,7 @@ public virtual Response GetConnectionWithSecrets(string c GetConnectionWithSecretsRequest getConnectionWithSecretsRequest = new GetConnectionWithSecretsRequest(ignored, null); RequestContext context = FromCancellationToken(cancellationToken); Response response = GetConnectionWithSecrets(connectionName, getConnectionWithSecretsRequest.ToRequestContent(), context); - return Response.FromValue(GetConnectionResponse.FromResponse(response), response); + return Response.FromValue(ConnectionResponse.FromResponse(response), response); } /// @@ -515,7 +515,7 @@ public virtual Response GetConnectionWithSecrets(string connectionName, RequestC /// Indicates whether to list datastores. Service default: do not list datastores. /// Target of the workspace connection. /// The cancellation token to use. - public virtual async Task> GetDefaultConnectionAsync(ConnectionType category, bool? withCredential = null, bool? includeAll = null, string target = null, CancellationToken cancellationToken = default) + public virtual async Task> GetDefaultConnectionAsync(ConnectionType category, bool? withCredential = null, bool? includeAll = null, string target = null, CancellationToken cancellationToken = default) { ListConnectionsResponse connections = await GetConnectionsAsync(category, includeAll, target, cancellationToken).ConfigureAwait(false); @@ -536,7 +536,7 @@ public virtual async Task> GetDefaultConnectionA /// Indicates whether to list datastores. Service default: do not list datastores. /// Target of the workspace connection. /// The cancellation token to use. - public virtual Response GetDefaultConnection(ConnectionType category, bool? withCredential = null, bool? includeAll = null, string target = null, CancellationToken cancellationToken = default) + public virtual Response GetDefaultConnection(ConnectionType category, bool? withCredential = null, bool? includeAll = null, string target = null, CancellationToken cancellationToken = default) { ListConnectionsResponse connections = GetConnections(category, includeAll, target, cancellationToken); diff --git a/sdk/ai/Azure.AI.Projects/src/Custom/Connection/CredentialsApiKeyAuth.cs b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/CredentialsApiKeyAuth.cs new file mode 100644 index 0000000000000..ab9278474ae90 --- /dev/null +++ b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/CredentialsApiKeyAuth.cs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.AI.Projects +{ + /// The credentials needed for API key authentication. + public partial class CredentialsApiKeyAuth + { + } +} diff --git a/sdk/ai/Azure.AI.Projects/src/Custom/Connection/GetConnectionResponse.cs b/sdk/ai/Azure.AI.Projects/src/Custom/Connection/GetConnectionResponse.cs deleted file mode 100644 index dfdbf4aee5476..0000000000000 --- a/sdk/ai/Azure.AI.Projects/src/Custom/Connection/GetConnectionResponse.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Projects -{ - /// Response from the listSecrets operation. - public partial class GetConnectionResponse - { - /// - /// The properties of the resource - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . - /// - internal InternalConnectionProperties Properties { get; } - } -} diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/AIProjectsModelFactory.cs b/sdk/ai/Azure.AI.Projects/src/Generated/AIProjectsModelFactory.cs index 2065bb08188cd..c4044af53ced2 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/AIProjectsModelFactory.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/AIProjectsModelFactory.cs @@ -114,13 +114,54 @@ public static WorkspaceProperties WorkspaceProperties(string applicationInsights /// Initializes a new instance of . /// A list of connection list secrets. /// A new instance for mocking. - public static ListConnectionsResponse ListConnectionsResponse(IEnumerable value = null) + public static ListConnectionsResponse ListConnectionsResponse(IEnumerable value = null) { - value ??= new List(); + value ??= new List(); return new ListConnectionsResponse(value?.ToList(), serializedAdditionalRawData: null); } + /// Initializes a new instance of . + /// A unique identifier for the connection. + /// The name of the resource. + /// + /// The properties of the resource + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include . + /// + /// A new instance for mocking. + public static ConnectionResponse ConnectionResponse(string id = null, string name = null, ConnectionProperties properties = null) + { + return new ConnectionResponse(id, name, properties, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Category of the connection. + /// The connection URL to be used for this service. + /// A new instance for mocking. + public static ConnectionProperties ConnectionProperties(ConnectionType category = default, string target = null) + { + return new UnknownInternalConnectionProperties(default, category, target, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Category of the connection. + /// The connection URL to be used for this service. + /// Credentials will only be present for authType=ApiKey. + /// A new instance for mocking. + public static ConnectionPropertiesApiKeyAuth ConnectionPropertiesApiKeyAuth(ConnectionType category = default, string target = null, CredentialsApiKeyAuth credentials = null) + { + return new ConnectionPropertiesApiKeyAuth(AuthenticationType.ApiKey, category, target, serializedAdditionalRawData: null, credentials); + } + + /// Initializes a new instance of . + /// The API key. + /// A new instance for mocking. + public static CredentialsApiKeyAuth CredentialsApiKeyAuth(string key = null) + { + return new CredentialsApiKeyAuth(key, serializedAdditionalRawData: null); + } + /// Initializes a new instance of . /// /// The role of the entity that is creating the message. Allowed values include: diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionProperties.Serialization.cs b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionProperties.Serialization.cs similarity index 63% rename from sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionProperties.Serialization.cs rename to sdk/ai/Azure.AI.Projects/src/Generated/ConnectionProperties.Serialization.cs index 80e3c7faf303f..6b84125aed624 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionProperties.Serialization.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionProperties.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.Projects { [PersistableModelProxy(typeof(UnknownInternalConnectionProperties))] - internal partial class InternalConnectionProperties : IUtf8JsonSerializable, IJsonModel + public partial class ConnectionProperties : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter writer, Model /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalConnectionProperties)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ConnectionProperties)} does not support writing '{format}' format."); } writer.WritePropertyName("authType"u8); @@ -57,19 +57,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - InternalConnectionProperties IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ConnectionProperties IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalConnectionProperties)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ConnectionProperties)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalConnectionProperties(document.RootElement, options); + return DeserializeConnectionProperties(document.RootElement, options); } - internal static InternalConnectionProperties DeserializeInternalConnectionProperties(JsonElement element, ModelReaderWriterOptions options = null) + internal static ConnectionProperties DeserializeConnectionProperties(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -82,50 +82,50 @@ internal static InternalConnectionProperties DeserializeInternalConnectionProper switch (discriminator.GetString()) { case "AAD": return InternalConnectionPropertiesAADAuth.DeserializeInternalConnectionPropertiesAADAuth(element, options); - case "ApiKey": return InternalConnectionPropertiesApiKeyAuth.DeserializeInternalConnectionPropertiesApiKeyAuth(element, options); + case "ApiKey": return ConnectionPropertiesApiKeyAuth.DeserializeConnectionPropertiesApiKeyAuth(element, options); case "SAS": return InternalConnectionPropertiesSASAuth.DeserializeInternalConnectionPropertiesSASAuth(element, options); } } return UnknownInternalConnectionProperties.DeserializeUnknownInternalConnectionProperties(element, options); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(InternalConnectionProperties)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ConnectionProperties)} does not support writing '{options.Format}' format."); } } - InternalConnectionProperties IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ConnectionProperties IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalConnectionProperties(document.RootElement, options); + return DeserializeConnectionProperties(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(InternalConnectionProperties)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ConnectionProperties)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static InternalConnectionProperties FromResponse(Response response) + internal static ConnectionProperties FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalConnectionProperties(document.RootElement); + return DeserializeConnectionProperties(document.RootElement); } /// Convert into a . diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionProperties.cs b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionProperties.cs similarity index 68% rename from sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionProperties.cs rename to sdk/ai/Azure.AI.Projects/src/Generated/ConnectionProperties.cs index 604c2bfb78fea..da25ba3389a74 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionProperties.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionProperties.cs @@ -12,10 +12,10 @@ namespace Azure.AI.Projects { /// /// Connection properties - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include . /// - internal abstract partial class InternalConnectionProperties + public abstract partial class ConnectionProperties { /// /// Keeps track of any properties unknown to the library. @@ -49,11 +49,11 @@ internal abstract partial class InternalConnectionProperties /// private protected IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . + /// Initializes a new instance of . /// Category of the connection. /// The connection URL to be used for this service. /// is null. - protected InternalConnectionProperties(ConnectionType category, string target) + protected ConnectionProperties(ConnectionType category, string target) { Argument.AssertNotNull(target, nameof(target)); @@ -61,12 +61,12 @@ protected InternalConnectionProperties(ConnectionType category, string target) Target = target; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// Authentication type of the connection target. /// Category of the connection. /// The connection URL to be used for this service. /// Keeps track of any properties unknown to the library. - internal InternalConnectionProperties(AuthenticationType authType, ConnectionType category, string target, IDictionary serializedAdditionalRawData) + internal ConnectionProperties(AuthenticationType authType, ConnectionType category, string target, IDictionary serializedAdditionalRawData) { AuthType = authType; Category = category; @@ -74,13 +74,10 @@ internal InternalConnectionProperties(AuthenticationType authType, ConnectionTyp _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal InternalConnectionProperties() + /// Initializes a new instance of for deserialization. + internal ConnectionProperties() { } - - /// Authentication type of the connection target. - internal AuthenticationType AuthType { get; set; } /// Category of the connection. public ConnectionType Category { get; } /// The connection URL to be used for this service. diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesApiKeyAuth.Serialization.cs b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionPropertiesApiKeyAuth.Serialization.cs similarity index 62% rename from sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesApiKeyAuth.Serialization.cs rename to sdk/ai/Azure.AI.Projects/src/Generated/ConnectionPropertiesApiKeyAuth.Serialization.cs index 52613fb243ccf..505814971c438 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesApiKeyAuth.Serialization.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionPropertiesApiKeyAuth.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.Projects { - internal partial class InternalConnectionPropertiesApiKeyAuth : IUtf8JsonSerializable, IJsonModel + public partial class ConnectionPropertiesApiKeyAuth : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter wri /// The client options for reading and writing models. protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalConnectionPropertiesApiKeyAuth)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ConnectionPropertiesApiKeyAuth)} does not support writing '{format}' format."); } base.JsonModelWriteCore(writer, options); @@ -39,19 +39,19 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri writer.WriteObjectValue(Credentials, options); } - InternalConnectionPropertiesApiKeyAuth IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ConnectionPropertiesApiKeyAuth IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalConnectionPropertiesApiKeyAuth)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ConnectionPropertiesApiKeyAuth)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalConnectionPropertiesApiKeyAuth(document.RootElement, options); + return DeserializeConnectionPropertiesApiKeyAuth(document.RootElement, options); } - internal static InternalConnectionPropertiesApiKeyAuth DeserializeInternalConnectionPropertiesApiKeyAuth(JsonElement element, ModelReaderWriterOptions options = null) + internal static ConnectionPropertiesApiKeyAuth DeserializeConnectionPropertiesApiKeyAuth(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -93,46 +93,46 @@ internal static InternalConnectionPropertiesApiKeyAuth DeserializeInternalConnec } } serializedAdditionalRawData = rawDataDictionary; - return new InternalConnectionPropertiesApiKeyAuth(authType, category, target, serializedAdditionalRawData, credentials); + return new ConnectionPropertiesApiKeyAuth(authType, category, target, serializedAdditionalRawData, credentials); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(InternalConnectionPropertiesApiKeyAuth)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ConnectionPropertiesApiKeyAuth)} does not support writing '{options.Format}' format."); } } - InternalConnectionPropertiesApiKeyAuth IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ConnectionPropertiesApiKeyAuth IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalConnectionPropertiesApiKeyAuth(document.RootElement, options); + return DeserializeConnectionPropertiesApiKeyAuth(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(InternalConnectionPropertiesApiKeyAuth)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ConnectionPropertiesApiKeyAuth)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static new InternalConnectionPropertiesApiKeyAuth FromResponse(Response response) + internal static new ConnectionPropertiesApiKeyAuth FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalConnectionPropertiesApiKeyAuth(document.RootElement); + return DeserializeConnectionPropertiesApiKeyAuth(document.RootElement); } /// Convert into a . diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesApiKeyAuth.cs b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionPropertiesApiKeyAuth.cs similarity index 63% rename from sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesApiKeyAuth.cs rename to sdk/ai/Azure.AI.Projects/src/Generated/ConnectionPropertiesApiKeyAuth.cs index d8c6fb29382d5..744b4576f2e10 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesApiKeyAuth.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionPropertiesApiKeyAuth.cs @@ -11,14 +11,14 @@ namespace Azure.AI.Projects { /// Connection properties for connections with API key authentication. - internal partial class InternalConnectionPropertiesApiKeyAuth : InternalConnectionProperties + public partial class ConnectionPropertiesApiKeyAuth : ConnectionProperties { - /// Initializes a new instance of . + /// Initializes a new instance of . /// Category of the connection. /// The connection URL to be used for this service. /// Credentials will only be present for authType=ApiKey. /// or is null. - internal InternalConnectionPropertiesApiKeyAuth(ConnectionType category, string target, CredentialsApiKeyAuth credentials) : base(category, target) + internal ConnectionPropertiesApiKeyAuth(ConnectionType category, string target, CredentialsApiKeyAuth credentials) : base(category, target) { Argument.AssertNotNull(target, nameof(target)); Argument.AssertNotNull(credentials, nameof(credentials)); @@ -27,19 +27,19 @@ internal InternalConnectionPropertiesApiKeyAuth(ConnectionType category, string Credentials = credentials; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// Authentication type of the connection target. /// Category of the connection. /// The connection URL to be used for this service. /// Keeps track of any properties unknown to the library. /// Credentials will only be present for authType=ApiKey. - internal InternalConnectionPropertiesApiKeyAuth(AuthenticationType authType, ConnectionType category, string target, IDictionary serializedAdditionalRawData, CredentialsApiKeyAuth credentials) : base(authType, category, target, serializedAdditionalRawData) + internal ConnectionPropertiesApiKeyAuth(AuthenticationType authType, ConnectionType category, string target, IDictionary serializedAdditionalRawData, CredentialsApiKeyAuth credentials) : base(authType, category, target, serializedAdditionalRawData) { Credentials = credentials; } - /// Initializes a new instance of for deserialization. - internal InternalConnectionPropertiesApiKeyAuth() + /// Initializes a new instance of for deserialization. + internal ConnectionPropertiesApiKeyAuth() { } diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/GetConnectionResponse.Serialization.cs b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionResponse.Serialization.cs similarity index 65% rename from sdk/ai/Azure.AI.Projects/src/Generated/GetConnectionResponse.Serialization.cs rename to sdk/ai/Azure.AI.Projects/src/Generated/ConnectionResponse.Serialization.cs index 693ffe477254e..0b803a55213b8 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/GetConnectionResponse.Serialization.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionResponse.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.Projects { - public partial class GetConnectionResponse : IUtf8JsonSerializable, IJsonModel + public partial class ConnectionResponse : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderW /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(GetConnectionResponse)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ConnectionResponse)} does not support writing '{format}' format."); } writer.WritePropertyName("id"u8); @@ -39,7 +39,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("name"u8); writer.WriteStringValue(Name); writer.WritePropertyName("properties"u8); - writer.WriteObjectValue(Properties, options); + writer.WriteObjectValue(Properties, options); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -57,19 +57,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - GetConnectionResponse IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ConnectionResponse IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(GetConnectionResponse)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ConnectionResponse)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeGetConnectionResponse(document.RootElement, options); + return DeserializeConnectionResponse(document.RootElement, options); } - internal static GetConnectionResponse DeserializeGetConnectionResponse(JsonElement element, ModelReaderWriterOptions options = null) + internal static ConnectionResponse DeserializeConnectionResponse(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -79,7 +79,7 @@ internal static GetConnectionResponse DeserializeGetConnectionResponse(JsonEleme } string id = default; string name = default; - InternalConnectionProperties properties = default; + ConnectionProperties properties = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -96,7 +96,7 @@ internal static GetConnectionResponse DeserializeGetConnectionResponse(JsonEleme } if (property.NameEquals("properties"u8)) { - properties = InternalConnectionProperties.DeserializeInternalConnectionProperties(property.Value, options); + properties = ConnectionProperties.DeserializeConnectionProperties(property.Value, options); continue; } if (options.Format != "W") @@ -105,46 +105,46 @@ internal static GetConnectionResponse DeserializeGetConnectionResponse(JsonEleme } } serializedAdditionalRawData = rawDataDictionary; - return new GetConnectionResponse(id, name, properties, serializedAdditionalRawData); + return new ConnectionResponse(id, name, properties, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(GetConnectionResponse)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ConnectionResponse)} does not support writing '{options.Format}' format."); } } - GetConnectionResponse IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ConnectionResponse IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeGetConnectionResponse(document.RootElement, options); + return DeserializeConnectionResponse(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(GetConnectionResponse)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ConnectionResponse)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static GetConnectionResponse FromResponse(Response response) + internal static ConnectionResponse FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeGetConnectionResponse(document.RootElement); + return DeserializeConnectionResponse(document.RootElement); } /// Convert into a . diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/GetConnectionResponse.cs b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionResponse.cs similarity index 63% rename from sdk/ai/Azure.AI.Projects/src/Generated/GetConnectionResponse.cs rename to sdk/ai/Azure.AI.Projects/src/Generated/ConnectionResponse.cs index 6f9c4c3454c72..0391fdfebd8af 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/GetConnectionResponse.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/ConnectionResponse.cs @@ -11,7 +11,7 @@ namespace Azure.AI.Projects { /// Response from the listSecrets operation. - public partial class GetConnectionResponse + public partial class ConnectionResponse { /// /// Keeps track of any properties unknown to the library. @@ -45,16 +45,16 @@ public partial class GetConnectionResponse /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . + /// Initializes a new instance of . /// A unique identifier for the connection. /// The name of the resource. /// /// The properties of the resource - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include . /// /// , or is null. - internal GetConnectionResponse(string id, string name, InternalConnectionProperties properties) + internal ConnectionResponse(string id, string name, ConnectionProperties properties) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(name, nameof(name)); @@ -65,16 +65,16 @@ internal GetConnectionResponse(string id, string name, InternalConnectionPropert Properties = properties; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// A unique identifier for the connection. /// The name of the resource. /// /// The properties of the resource - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include . /// /// Keeps track of any properties unknown to the library. - internal GetConnectionResponse(string id, string name, InternalConnectionProperties properties, IDictionary serializedAdditionalRawData) + internal ConnectionResponse(string id, string name, ConnectionProperties properties, IDictionary serializedAdditionalRawData) { Id = id; Name = name; @@ -82,8 +82,8 @@ internal GetConnectionResponse(string id, string name, InternalConnectionPropert _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal GetConnectionResponse() + /// Initializes a new instance of for deserialization. + internal ConnectionResponse() { } @@ -91,5 +91,11 @@ internal GetConnectionResponse() public string Id { get; } /// The name of the resource. public string Name { get; } + /// + /// The properties of the resource + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include . + /// + public ConnectionProperties Properties { get; } } } diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/CredentialsApiKeyAuth.Serialization.cs b/sdk/ai/Azure.AI.Projects/src/Generated/CredentialsApiKeyAuth.Serialization.cs index 68deac2736627..4be6577c2b04c 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/CredentialsApiKeyAuth.Serialization.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/CredentialsApiKeyAuth.Serialization.cs @@ -13,7 +13,7 @@ namespace Azure.AI.Projects { - internal partial class CredentialsApiKeyAuth : IUtf8JsonSerializable, IJsonModel + public partial class CredentialsApiKeyAuth : IUtf8JsonSerializable, IJsonModel { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/CredentialsApiKeyAuth.cs b/sdk/ai/Azure.AI.Projects/src/Generated/CredentialsApiKeyAuth.cs index b3fb288406253..97faa0c97097f 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/CredentialsApiKeyAuth.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/CredentialsApiKeyAuth.cs @@ -11,7 +11,7 @@ namespace Azure.AI.Projects { /// The credentials needed for API key authentication. - internal partial class CredentialsApiKeyAuth + public partial class CredentialsApiKeyAuth { /// /// Keeps track of any properties unknown to the library. diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesAADAuth.cs b/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesAADAuth.cs index 5c0e9da58ac72..8e5ae6c65b87e 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesAADAuth.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesAADAuth.cs @@ -11,7 +11,7 @@ namespace Azure.AI.Projects { /// Connection properties for connections with AAD authentication (aka `Entra ID passthrough`). - internal partial class InternalConnectionPropertiesAADAuth : InternalConnectionProperties + internal partial class InternalConnectionPropertiesAADAuth : ConnectionProperties { /// Initializes a new instance of . /// Category of the connection. diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesSASAuth.cs b/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesSASAuth.cs index d10ce5ed696f9..cf7a52fbbe22c 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesSASAuth.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/InternalConnectionPropertiesSASAuth.cs @@ -11,7 +11,7 @@ namespace Azure.AI.Projects { /// Connection properties for connections with SAS authentication. - internal partial class InternalConnectionPropertiesSASAuth : InternalConnectionProperties + internal partial class InternalConnectionPropertiesSASAuth : ConnectionProperties { /// Initializes a new instance of . /// Category of the connection. diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/ListConnectionsResponse.Serialization.cs b/sdk/ai/Azure.AI.Projects/src/Generated/ListConnectionsResponse.Serialization.cs index ee8f259f3388a..bafafaae4428d 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/ListConnectionsResponse.Serialization.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/ListConnectionsResponse.Serialization.cs @@ -78,17 +78,17 @@ internal static ListConnectionsResponse DeserializeListConnectionsResponse(JsonE { return null; } - IReadOnlyList value = default; + IReadOnlyList value = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("value"u8)) { - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(GetConnectionResponse.DeserializeGetConnectionResponse(item, options)); + array.Add(ConnectionResponse.DeserializeConnectionResponse(item, options)); } value = array; continue; diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/ListConnectionsResponse.cs b/sdk/ai/Azure.AI.Projects/src/Generated/ListConnectionsResponse.cs index d5a7901dcdde6..7dd047b9eb698 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/ListConnectionsResponse.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/ListConnectionsResponse.cs @@ -49,7 +49,7 @@ public partial class ListConnectionsResponse /// Initializes a new instance of . /// A list of connection list secrets. /// is null. - internal ListConnectionsResponse(IEnumerable value) + internal ListConnectionsResponse(IEnumerable value) { Argument.AssertNotNull(value, nameof(value)); @@ -59,7 +59,7 @@ internal ListConnectionsResponse(IEnumerable value) /// Initializes a new instance of . /// A list of connection list secrets. /// Keeps track of any properties unknown to the library. - internal ListConnectionsResponse(IReadOnlyList value, IDictionary serializedAdditionalRawData) + internal ListConnectionsResponse(IReadOnlyList value, IDictionary serializedAdditionalRawData) { Value = value; _serializedAdditionalRawData = serializedAdditionalRawData; @@ -71,6 +71,6 @@ internal ListConnectionsResponse() } /// A list of connection list secrets. - public IReadOnlyList Value { get; } + public IReadOnlyList Value { get; } } } diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/UnknownInternalConnectionProperties.Serialization.cs b/sdk/ai/Azure.AI.Projects/src/Generated/UnknownInternalConnectionProperties.Serialization.cs index e5fd33f0ae762..3c8dc0d67ce0f 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/UnknownInternalConnectionProperties.Serialization.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/UnknownInternalConnectionProperties.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.Projects { - internal partial class UnknownInternalConnectionProperties : IUtf8JsonSerializable, IJsonModel + internal partial class UnknownInternalConnectionProperties : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,25 +28,25 @@ void IJsonModel.Write(Utf8JsonWriter writer, Model /// The client options for reading and writing models. protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalConnectionProperties)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ConnectionProperties)} does not support writing '{format}' format."); } base.JsonModelWriteCore(writer, options); } - InternalConnectionProperties IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ConnectionProperties IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalConnectionProperties)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ConnectionProperties)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalConnectionProperties(document.RootElement, options); + return DeserializeConnectionProperties(document.RootElement, options); } internal static UnknownInternalConnectionProperties DeserializeUnknownInternalConnectionProperties(JsonElement element, ModelReaderWriterOptions options = null) @@ -88,36 +88,36 @@ internal static UnknownInternalConnectionProperties DeserializeUnknownInternalCo return new UnknownInternalConnectionProperties(authType, category, target, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(InternalConnectionProperties)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ConnectionProperties)} does not support writing '{options.Format}' format."); } } - InternalConnectionProperties IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ConnectionProperties IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalConnectionProperties(document.RootElement, options); + return DeserializeConnectionProperties(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(InternalConnectionProperties)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ConnectionProperties)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. @@ -131,7 +131,7 @@ InternalConnectionProperties IPersistableModel.Cre internal override RequestContent ToRequestContent() { var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); return content; } } diff --git a/sdk/ai/Azure.AI.Projects/src/Generated/UnknownInternalConnectionProperties.cs b/sdk/ai/Azure.AI.Projects/src/Generated/UnknownInternalConnectionProperties.cs index 83b4bbed4912b..a17524ba6e77f 100644 --- a/sdk/ai/Azure.AI.Projects/src/Generated/UnknownInternalConnectionProperties.cs +++ b/sdk/ai/Azure.AI.Projects/src/Generated/UnknownInternalConnectionProperties.cs @@ -11,7 +11,7 @@ namespace Azure.AI.Projects { /// Unknown version of InternalConnectionProperties. - internal partial class UnknownInternalConnectionProperties : InternalConnectionProperties + internal partial class UnknownInternalConnectionProperties : ConnectionProperties { /// Initializes a new instance of . /// Authentication type of the connection target. diff --git a/sdk/ai/Azure.AI.Projects/tests/Samples/Agent/Sample_Agent_Bing_Grounding.cs b/sdk/ai/Azure.AI.Projects/tests/Samples/Agent/Sample_Agent_Bing_Grounding.cs index 17921a2341957..f1d80e02f2620 100644 --- a/sdk/ai/Azure.AI.Projects/tests/Samples/Agent/Sample_Agent_Bing_Grounding.cs +++ b/sdk/ai/Azure.AI.Projects/tests/Samples/Agent/Sample_Agent_Bing_Grounding.cs @@ -25,7 +25,7 @@ public async Task BingGroundingExample() clientOptions.AddPolicy(new CustomHeadersPolicy(), HttpPipelinePosition.PerCall); var projectClient = new AIProjectClient(connectionString, new DefaultAzureCredential(), clientOptions); - GetConnectionResponse bingConnection = await projectClient.GetConnectionsClient().GetConnectionAsync(TestEnvironment.BINGCONNECTIONNAME); + ConnectionResponse bingConnection = await projectClient.GetConnectionsClient().GetConnectionAsync(TestEnvironment.BINGCONNECTIONNAME); var connectionId = bingConnection.Id; AgentsClient agentClient = projectClient.GetAgentsClient(); diff --git a/sdk/ai/Azure.AI.Projects/tests/Samples/Agent/Sample_Agents_Azure_AI_Search.cs b/sdk/ai/Azure.AI.Projects/tests/Samples/Agent/Sample_Agents_Azure_AI_Search.cs index a9312ad14b250..7a66b4b2741ca 100644 --- a/sdk/ai/Azure.AI.Projects/tests/Samples/Agent/Sample_Agents_Azure_AI_Search.cs +++ b/sdk/ai/Azure.AI.Projects/tests/Samples/Agent/Sample_Agents_Azure_AI_Search.cs @@ -32,7 +32,7 @@ public async Task AzureAISearchExample() throw new InvalidOperationException("No connections found for the Azure AI Search."); } - GetConnectionResponse connection = connections.Value[0]; + ConnectionResponse connection = connections.Value[0]; ToolResources searchResource = new ToolResources { diff --git a/sdk/ai/Azure.AI.Projects/tests/Samples/Connection/Sample_Connection.cs b/sdk/ai/Azure.AI.Projects/tests/Samples/Connection/Sample_Connection.cs new file mode 100644 index 0000000000000..38826772533c9 --- /dev/null +++ b/sdk/ai/Azure.AI.Projects/tests/Samples/Connection/Sample_Connection.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using System; +using Azure.AI.Inference; +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.AI.Projects.Tests; + +public class Sample_Connection : SamplesBase +{ + [Test] + public void ConnectionExample() + { + var connectionString = TestEnvironment.AzureAICONNECTIONSTRING; + var modelDeploymentName = TestEnvironment.MODELDEPLOYMENTNAME; + + AIProjectClient client = new AIProjectClient(connectionString, new DefaultAzureCredential()); + var connectionsClient = client.GetConnectionsClient(); + + ConnectionResponse connection = connectionsClient.GetDefaultConnection(ConnectionType.Serverless, true); + + if (connection.Properties.AuthType == AuthenticationType.ApiKey) + { + var apiKeyAuthProperties = connection.Properties as ConnectionPropertiesApiKeyAuth; + if (string.IsNullOrWhiteSpace(apiKeyAuthProperties.Target)) + { + throw new ArgumentException("The API key authentication target URI is missing or invalid."); + } + + if (!Uri.TryCreate(apiKeyAuthProperties.Target, UriKind.Absolute, out var endpoint)) + { + throw new UriFormatException("Invalid URI format in API key authentication target."); + } + + var credential = new AzureKeyCredential(apiKeyAuthProperties.Credentials.Key); + ChatCompletionsClient chatClient = new ChatCompletionsClient(endpoint, credential); + + var requestOptions = new ChatCompletionsOptions() + { + Messages = + { + new ChatRequestSystemMessage("You are a helpful assistant."), + new ChatRequestUserMessage("How many feet are in a mile?"), + }, + Model = modelDeploymentName + }; + + Response response = chatClient.Complete(requestOptions); + Console.WriteLine(response.Value.Content); + } + } +} diff --git a/sdk/ai/Azure.AI.Projects/tests/Samples/README.md b/sdk/ai/Azure.AI.Projects/tests/Samples/README.md new file mode 100644 index 0000000000000..7703812322969 --- /dev/null +++ b/sdk/ai/Azure.AI.Projects/tests/Samples/README.md @@ -0,0 +1 @@ +The source files in this directory are written as tests to ensure that our samples compile and function correctly. \ No newline at end of file diff --git a/sdk/ai/Azure.AI.Projects/tests/Readme.cs b/sdk/ai/Azure.AI.Projects/tests/Samples/Readme.cs similarity index 75% rename from sdk/ai/Azure.AI.Projects/tests/Readme.cs rename to sdk/ai/Azure.AI.Projects/tests/Samples/Readme.cs index e7acd3b05e7d9..d01da41c3230f 100644 --- a/sdk/ai/Azure.AI.Projects/tests/Readme.cs +++ b/sdk/ai/Azure.AI.Projects/tests/Samples/Readme.cs @@ -4,23 +4,30 @@ #nullable disable using System; -using Azure.Identity; +using Azure.Core.TestFramework; +using NUnit.Framework; namespace Azure.AI.Projects.Tests; -internal partial class Readme +public partial class Readme : SamplesBase { - public void CreateProjectClient() + [Test] + public void Authenticate() { #region Snippet:OverviewCreateClient +#if SNIPPET var connectionString = Environment.GetEnvironmentVariable("PROJECT_CONNECTION_STRING"); +#else + var connectionString = TestEnvironment.AzureAICONNECTIONSTRING; +#endif AIProjectClient projectClient = new AIProjectClient(connectionString, new DefaultAzureCredential()); #endregion } + [Test] public void Troubleshooting() { - var connectionString = Environment.GetEnvironmentVariable("PROJECT_CONNECTION_STRING"); + var connectionString = TestEnvironment.AzureAICONNECTIONSTRING; AgentsClient client = new AgentsClient(connectionString, new DefaultAzureCredential()); #region Snippet:Readme_Troubleshooting