Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
495 changes: 495 additions & 0 deletions .dotnet.azure/CHANGELOG.md

Large diffs are not rendered by default.

536 changes: 536 additions & 0 deletions .dotnet.azure/README.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .dotnet.azure/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/openai/Azure.AI.OpenAI",
"Tag": "net/openai/Azure.AI.OpenAI_23ae923738"
}
3 changes: 2 additions & 1 deletion .dotnet.azure/src/Azure.AI.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
Azure OpenAI's official extension package for using OpenAI's .NET library with the Azure OpenAI Service.
</Description>
<AssemblyTitle>Azure.AI.OpenAI Client Library</AssemblyTitle>
<Version>2.0.0-beta.3</Version>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionSuffix>beta.3</VersionSuffix>
<PackageTags>Microsoft Azure OpenAI</PackageTags>
<DisableEnhancedAnalysis>true</DisableEnhancedAnalysis>
<!-- <TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks> -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public override ClientResult CreateMessage(string threadId, BinaryContent conten
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}

/// <inheritdoc cref="InternalAssistantMessageClient.GetMessagesAsync"/>
/// <inheritdoc />
public override IAsyncEnumerable<ClientResult> GetMessagesAsync(string threadId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
Expand All @@ -116,7 +116,6 @@ public override IAsyncEnumerable<ClientResult> GetMessagesAsync(string threadId,
return PageCollectionHelpers.CreateAsync(enumerator);
}

/// <inheritdoc cref="InternalAssistantMessageClient.GetMessages"/>
public override IEnumerable<ClientResult> GetMessages(string threadId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
Expand Down Expand Up @@ -259,7 +258,6 @@ public override ClientResult CreateRun(string threadId, BinaryContent content, R
}
}

/// <inheritdoc cref="InternalAssistantRunClient.GetRunsAsync"/>
public override IAsyncEnumerable<ClientResult> GetRunsAsync(string threadId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
Expand All @@ -268,7 +266,6 @@ public override IAsyncEnumerable<ClientResult> GetRunsAsync(string threadId, int
return PageCollectionHelpers.CreateAsync(enumerator);
}

/// <inheritdoc cref="InternalAssistantRunClient.GetRuns"/>
public override IEnumerable<ClientResult> GetRuns(string threadId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
Expand Down Expand Up @@ -379,7 +376,6 @@ public override ClientResult SubmitToolOutputsToRun(string threadId, string runI
}
}

/// <inheritdoc cref="InternalAssistantRunClient.GetRunStepsAsync"/>
public override IAsyncEnumerable<ClientResult> GetRunStepsAsync(string threadId, string runId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
Expand All @@ -389,7 +385,6 @@ public override IAsyncEnumerable<ClientResult> GetRunStepsAsync(string threadId,
return PageCollectionHelpers.CreateAsync(enumerator);
}

/// <inheritdoc cref="InternalAssistantRunClient.GetRunSteps"/>
public override IEnumerable<ClientResult> GetRunSteps(string threadId, string runId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
Expand Down
4 changes: 1 addition & 3 deletions .dotnet.azure/src/Custom/Assistants/AzureAssistantClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using OpenAI.Assistants;
using System.ClientModel.Primitives;

namespace Azure.AI.OpenAI.Assistants;
Expand Down Expand Up @@ -29,6 +28,5 @@ internal AzureAssistantClient(ClientPipeline pipeline, Uri endpoint, AzureOpenAI
}

protected AzureAssistantClient()
{
}
{ }
}
23 changes: 0 additions & 23 deletions .dotnet.azure/src/Custom/Assistants/AzureRunStepDetailsUpdate.cs

This file was deleted.

12 changes: 0 additions & 12 deletions .dotnet.azure/src/Custom/Assistants/Internal/GeneratorStubs.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel;
using System.ClientModel.Primitives;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel;
using System.ClientModel.Primitives;

Expand All @@ -11,7 +14,7 @@ internal partial class AzureMessagesPageEnumerator : MessagesPageEnumerator
public AzureMessagesPageEnumerator(
ClientPipeline pipeline,
Uri endpoint,
string threadId,
string threadId,
int? limit, string order, string after, string before,
string apiVersion,
RequestOptions options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel;
using System.ClientModel.Primitives;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel;
using System.ClientModel.Primitives;

Expand All @@ -20,7 +23,6 @@ public AzureRunsPageEnumerator(
_apiVersion = apiVersion;
}


internal override async Task<ClientResult> GetRunsAsync(string threadId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
Expand Down
3 changes: 1 addition & 2 deletions .dotnet.azure/src/Custom/Audio/AzureAudioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ internal AzureAudioClient(ClientPipeline pipeline, string deploymentName, Uri en
}

protected AzureAudioClient()
{
}
{ }
}
69 changes: 69 additions & 0 deletions .dotnet.azure/src/Custom/AzureOpenAIAudience.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ComponentModel;

namespace Azure.AI.OpenAI;

/// <summary>
/// Represents cloud authentication audiences available for Azure OpenAI.
/// These audiences correspond to authorization token authentication scopes.
/// </summary>
public readonly partial struct AzureOpenAIAudience : IEquatable<AzureOpenAIAudience>
{
private readonly string _value;

/// <summary>
/// Initializes a new instance of the <see cref="AzureOpenAIAudience"/> object.
/// </summary>
/// <remarks>
/// Please consider using one of the known, valid values like <see cref="AzurePublicCloud"/> or <see cref="AzureGovernment"/>.
/// </remarks>
/// <param name="value">
/// The Microsoft Entra audience to use when forming authorization scopes.
/// For Azure OpenAI, this value corresponds to a URL that identifies the Azure cloud where the resource is located.
/// For more information: <see href="https://learn.microsoft.com/azure/azure-government/documentation-government-cognitiveservices" />.
/// </param>
/// <exception cref="ArgumentNullException"> <paramref name="value"/> is null. </exception>
public AzureOpenAIAudience(string value)
{
Argument.AssertNotNullOrEmpty(value, nameof(value));
_value = value;
}

private const string AzurePublicCloudValue = "https://cognitiveservices.azure.com/.default";
private const string AzureGovernmentValue = "https://cognitiveservices.azure.us/.default";

/// <summary>
/// The authorization audience used to connect to the public Azure cloud. Default if not otherwise specified.
/// </summary>
public static AzureOpenAIAudience AzurePublicCloud { get; } = new AzureOpenAIAudience(AzurePublicCloudValue);

/// <summary>
/// The authorization audience used to authenticate with the Azure Government cloud.
/// </summary>
/// <remarks>
/// For more information, please refer to
/// <see href="https://learn.microsoft.com/azure/azure-government/documentation-government-cognitiveservices" />.
/// </remarks>
public static AzureOpenAIAudience AzureGovernment { get; } = new AzureOpenAIAudience(AzureGovernmentValue);

/// <summary> Determines if two <see cref="AzureOpenAIAudience"/> values are the same. </summary>
public static bool operator ==(AzureOpenAIAudience left, AzureOpenAIAudience right) => left.Equals(right);
/// <summary> Determines if two <see cref="AzureOpenAIAudience"/> values are not the same. </summary>
public static bool operator !=(AzureOpenAIAudience left, AzureOpenAIAudience right) => !left.Equals(right);
/// <summary> Converts a string to a <see cref="AzureOpenAIAudience"/>. </summary>
public static implicit operator AzureOpenAIAudience(string value) => new AzureOpenAIAudience(value);

/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is AzureOpenAIAudience other && Equals(other);
/// <inheritdoc />
public bool Equals(AzureOpenAIAudience other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);

/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0;
/// <inheritdoc />
public override string ToString() => _value;
}
44 changes: 30 additions & 14 deletions .dotnet.azure/src/Custom/AzureOpenAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public partial class AzureOpenAIClient : OpenAIClient
/// </remarks>
/// <param name="endpoint"> The Azure OpenAI resource endpoint to use. This should not include model deployment or operation information. For example: <c>https://my-resource.openai.azure.com</c>. </param>
/// <param name="credential"> The API key to authenticate with the service. </param>
/// <param name="options"> The options to configure the client. </param>
public AzureOpenAIClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, new AzureOpenAIClientOptions())
{
}
Expand Down Expand Up @@ -143,7 +142,7 @@ public AzureOpenAIClient(Uri endpoint, AzureKeyCredential credential, AzureOpenA
/// Example: <c>https://my-resource.openai.azure.com</c>
/// </para>
/// </param>
/// <param name="credential"> The API key to use when authenticating with the provided endpoint. </para>
/// <param name="credential"> The API key to use when authenticating with the provided endpoint. </param>
/// <param name="options"> The scenario-independent options to use. </param>
public AzureOpenAIClient(Uri endpoint, TokenCredential credential, AzureOpenAIClientOptions options = null)
: this(CreatePipeline(credential, options), endpoint, options)
Expand Down Expand Up @@ -268,18 +267,18 @@ public override VectorStoreClient GetVectorStoreClient()
=> new AzureVectorStoreClient(Pipeline, _endpoint, _options);

private static ClientPipeline CreatePipeline(PipelinePolicy authenticationPolicy, AzureOpenAIClientOptions options)
{
return ClientPipeline.Create(
=> ClientPipeline.Create(
options ?? new(),
perCallPolicies: [
perCallPolicies:
[
CreateAddUserAgentHeaderPolicy(options),
CreateAddClientRequestIdHeaderPolicy(),
],
perTryPolicies: [
perTryPolicies:
[
authenticationPolicy,
CreateAddUserAgentHeaderPolicy(options),
],
beforeTransportPolicies: [
]);
}
beforeTransportPolicies: []);

internal static ClientPipeline CreatePipeline(ApiKeyCredential credential, AzureOpenAIClientOptions options = null)
{
Expand All @@ -290,12 +289,14 @@ internal static ClientPipeline CreatePipeline(ApiKeyCredential credential, Azure
internal static ClientPipeline CreatePipeline(TokenCredential credential, AzureOpenAIClientOptions options = null)
{
Argument.AssertNotNull(credential, nameof(credential));
return CreatePipeline(new AzureTokenAuthenticationPolicy(credential), options);
string authorizationScope = options?.Audience?.ToString()
?? AzureOpenAIAudience.AzurePublicCloud.ToString();
return CreatePipeline(new AzureTokenAuthenticationPolicy(credential, [authorizationScope]), options);
}

private static PipelinePolicy CreateAddUserAgentHeaderPolicy(AzureOpenAIClientOptions options = null)
{
Core.TelemetryDetails telemetryDetails = new(typeof(AzureOpenAIClient).Assembly);
Core.TelemetryDetails telemetryDetails = new(typeof(AzureOpenAIClient).Assembly, options?.ApplicationId);
return new GenericActionPipelinePolicy(
requestAction: request =>
{
Expand All @@ -306,8 +307,23 @@ private static PipelinePolicy CreateAddUserAgentHeaderPolicy(AzureOpenAIClientOp
});
}

private static PipelinePolicy CreateAddClientRequestIdHeaderPolicy()
{
return new GenericActionPipelinePolicy(request =>
{
if (request?.Headers is not null)
{
string requestId = request.Headers.TryGetValue(s_clientRequestIdHeaderKey, out string existingHeader) == true
? existingHeader
: Guid.NewGuid().ToString().ToLowerInvariant();
request.Headers.Set(s_clientRequestIdHeaderKey, requestId);
}
});
}

private static readonly string s_userAgentHeaderKey = "User-Agent";
private static PipelineMessageClassifier _pipelineMessageClassifier;
private static readonly string s_clientRequestIdHeaderKey = "x-ms-client-request-id";
private static PipelineMessageClassifier s_pipelineMessageClassifier;
internal static PipelineMessageClassifier PipelineMessageClassifier
=> _pipelineMessageClassifier ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200, 201 });
=> s_pipelineMessageClassifier ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200, 201 });
}
Loading