-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New nugets (Abstractions, Connectors.AI.OpenAI); add AAD auth, Azure …
…ChatGPT, text+chat streaming (#420) ### Motivation and Context New features: * AAD auth for Azure OpenAI * Azure ChatGPT * Completion streaming * Chat streaming * log probs ### Description * Split kernel core nuget in 3 nugets and add dependency on Azure OpenAI SDK: * MS.SK.Abstractions: interfaces and common classes, ideally no business logic * MS.SK: SK runtime, depends on SK.Abstractions * MS.SK.Connectors.AI.OpenAI: OpenAI/Azure OpenAI code, depends on SK.Abstractions and Azure OpenAI SDK * Rewrote TextCompletion, ChatCompletion, EmbeddingGeneration clients to use Azure OpenAI SDK * Deleted unused code. The old OpenAI client is still in use only for DALL-E2 Note: custom retry logic doesn't work with Azure OpenAI SDK. The SDK already retries internally, using a different approach. Nugets: * Microsoft.SemanticKernel.0.12.0.nupkg * **Microsoft.SemanticKernel.Abstractions.0.12.0.nupkg** * **Microsoft.SemanticKernel.Connectors.AI.OpenAI.0.12.0.nupkg** * Microsoft.SemanticKernel.Connectors.Memory.Qdrant.0.12.0.nupkg * Microsoft.SemanticKernel.Connectors.Memory.Sqlite.0.12.0.nupkg * Microsoft.SemanticKernel.Skills.MsGraph.0.12.0.nupkg * Microsoft.SemanticKernel.Skills.Document.0.12.0.nupkg * Microsoft.SemanticKernel.Skills.OpenAPI.0.12.0.nupkg * Microsoft.SemanticKernel.Skills.Web.0.12.0.nupkg
- Loading branch information
Showing
153 changed files
with
1,608 additions
and
1,728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,39 @@ | ||
{ | ||
"ignorePatterns": [ | ||
{ "pattern": "/github/" }, | ||
{ "pattern": "./actions" }, | ||
{ "pattern": "./blob" }, | ||
{ "pattern": "./issues" }, | ||
{ "pattern": "./discussions" }, | ||
{ "pattern": "./pulls" } | ||
{ | ||
"pattern": "/github/" | ||
}, | ||
{ | ||
"pattern": "./actions" | ||
}, | ||
{ | ||
"pattern": "./blob" | ||
}, | ||
{ | ||
"pattern": "./issues" | ||
}, | ||
{ | ||
"pattern": "./discussions" | ||
}, | ||
{ | ||
"pattern": "./pulls" | ||
}, | ||
{ | ||
"pattern": "^http://localhost" | ||
}, | ||
{ | ||
"pattern": "^https://localhost" | ||
} | ||
], | ||
"timeout": "20s", | ||
"retryOn429": true, | ||
"retryCount": 3, | ||
"fallbackRetryDelay": "30s", | ||
"aliveStatusCodes": [200, 206] | ||
} | ||
"aliveStatusCodes": [ | ||
200, | ||
206, | ||
429, | ||
500, | ||
503 | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
dotnet/src/Connectors/Connectors.AI.OpenAI/AzureSdk/AddHeaderRequestPolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Azure.Core; | ||
using Azure.Core.Pipeline; | ||
|
||
namespace Microsoft.SemanticKernel.Connectors.AI.OpenAI.AzureSdk; | ||
|
||
/// <summary> | ||
/// Helper class to inject headers into Azure SDK HTTP pipeline | ||
/// </summary> | ||
internal class AddHeaderRequestPolicy : HttpPipelineSynchronousPolicy | ||
{ | ||
private readonly string _headerName; | ||
private readonly string _headerValue; | ||
|
||
public AddHeaderRequestPolicy(string headerName, string headerValue) | ||
{ | ||
this._headerName = headerName; | ||
this._headerValue = headerValue; | ||
} | ||
|
||
public override void OnSendingRequest(HttpMessage message) | ||
{ | ||
message.Request.Headers.Add(this._headerName, this._headerValue); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
dotnet/src/Connectors/Connectors.AI.OpenAI/AzureSdk/AzureOpenAIClientBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using Azure; | ||
using Azure.AI.OpenAI; | ||
using Azure.Core; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.SemanticKernel.Diagnostics; | ||
using Microsoft.SemanticKernel.Reliability; | ||
|
||
namespace Microsoft.SemanticKernel.Connectors.AI.OpenAI.AzureSdk; | ||
|
||
public abstract class AzureOpenAIClientBase : ClientBase | ||
{ | ||
/// <summary> | ||
/// OpenAI / Azure OpenAI Client | ||
/// </summary> | ||
protected override OpenAIClient Client { get; } | ||
|
||
/// <summary> | ||
/// Creates a new AzureTextCompletion client instance using API Key auth | ||
/// </summary> | ||
/// <param name="modelId">Azure OpenAI model ID or deployment name, see https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource</param> | ||
/// <param name="endpoint">Azure OpenAI deployment URL, see https://learn.microsoft.com/azure/cognitive-services/openai/quickstart</param> | ||
/// <param name="apiKey">Azure OpenAI API key, see https://learn.microsoft.com/azure/cognitive-services/openai/quickstart</param> | ||
/// <param name="handlerFactory">Retry handler factory for HTTP requests.</param> | ||
/// <param name="log">Application logger</param> | ||
protected AzureOpenAIClientBase( | ||
string modelId, | ||
string endpoint, | ||
string apiKey, | ||
IDelegatingHandlerFactory? handlerFactory = null, | ||
ILogger? log = null) | ||
{ | ||
Verify.NotEmpty(modelId, "The Model Id/Deployment Name cannot be empty"); | ||
this.ModelId = modelId; | ||
|
||
var options = new OpenAIClientOptions(); | ||
|
||
// TODO: reimplement | ||
// Doesn't work | ||
// if (handlerFactory != null) | ||
// { | ||
// options.Transport = new HttpClientTransport(handlerFactory.Create(log)); | ||
// } | ||
|
||
Verify.NotEmpty(endpoint, "The Azure endpoint cannot be empty"); | ||
Verify.StartsWith(endpoint, "https://", "The Azure OpenAI endpoint must start with 'https://'"); | ||
Verify.NotEmpty(apiKey, "The Azure API key cannot be empty"); | ||
this.Client = new OpenAIClient(new Uri(endpoint), new AzureKeyCredential(apiKey), options); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new AzureTextCompletion client instance supporting AAD auth | ||
/// </summary> | ||
/// <param name="modelId">Azure OpenAI model ID or deployment name, see https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource</param> | ||
/// <param name="endpoint">Azure OpenAI deployment URL, see https://learn.microsoft.com/azure/cognitive-services/openai/quickstart</param> | ||
/// <param name="credentials">Token credentials, e.g. DefaultAzureCredential, ManagedIdentityCredential, EnvironmentCredential, etc.</param> | ||
/// <param name="handlerFactory">Retry handler factory for HTTP requests.</param> | ||
/// <param name="log">Application logger</param> | ||
protected AzureOpenAIClientBase( | ||
string modelId, | ||
string endpoint, | ||
TokenCredential credentials, | ||
IDelegatingHandlerFactory? handlerFactory = null, | ||
ILogger? log = null) | ||
{ | ||
Verify.NotEmpty(modelId, "The Model Id/Deployment Name cannot be empty"); | ||
this.ModelId = modelId; | ||
|
||
var options = new OpenAIClientOptions(); | ||
|
||
// TODO: reimplement | ||
// Doesn't work | ||
// if (handlerFactory != null) | ||
// { | ||
// options.Transport = new HttpClientTransport(handlerFactory.Create(log)); | ||
// } | ||
|
||
Verify.NotEmpty(endpoint, "The Azure endpoint cannot be empty"); | ||
Verify.StartsWith(endpoint, "https://", "The Azure OpenAI endpoint must start with 'https://'"); | ||
this.Client = new OpenAIClient(new Uri(endpoint), credentials, options); | ||
} | ||
} |
Oops, something went wrong.