Skip to content

Commit

Permalink
Upgrade SK (incl. Azure OpenAI throttling fix) and OllamaSharp (#874)
Browse files Browse the repository at this point in the history
## Motivation and Context (Why the change? What's the scenario?)

Temporary workaround for Azure OpenAI SDK bug - service throttling
handled incorrectly and causing incorrect HTTP status error

See:
* Azure/azure-sdk-for-net#46109
* microsoft/semantic-kernel#8929
* #855
  • Loading branch information
dluc authored Oct 31, 2024
1 parent 67472d5 commit 689cace
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<!-- Central version prefix - applies to all nuget packages. -->
<Version>0.90.0</Version>
<Version>0.91.0</Version>

<!-- C# lang version, https://learn.microsoft.com/dotnet/csharp/whats-new -->
<LangVersion>12</LangVersion>
Expand Down
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AWSSDK.S3" Version="3.7.405.6" />
<PackageVersion Include="AWSSDK.S3" Version="3.7.405.7" />
<PackageVersion Include="Azure.AI.ContentSafety" Version="1.0.0" />
<PackageVersion Include="Azure.AI.FormRecognizer" Version="4.1.0" />
<PackageVersion Include="Azure.Identity" Version="1.13.1" />
Expand All @@ -28,7 +28,7 @@
<PackageVersion Include="MongoDB.Driver.GridFS" Version="2.30.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="OllamaSharp" Version="4.0.2" />
<PackageVersion Include="OllamaSharp" Version="4.0.3" />
<PackageVersion Include="PdfPig" Version="0.1.9" />
<PackageVersion Include="Polly.Core" Version="8.4.2" />
<PackageVersion Include="RabbitMQ.Client" Version="6.8.1" />
Expand Down Expand Up @@ -56,10 +56,10 @@
</ItemGroup>
<!-- Semantic Kernel -->
<ItemGroup>
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.25.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.25.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.25.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.AzureOpenAI" Version="1.25.0" />
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.26.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.26.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.26.0" />
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.AzureOpenAI" Version="1.26.0" />
</ItemGroup>
<!-- Documentation -->
<ItemGroup>
Expand Down Expand Up @@ -103,7 +103,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Xunit.DependencyInjection" Version="9.5.0" />
<PackageVersion Include="Xunit.DependencyInjection" Version="9.6.0" />
<PackageVersion Include="Xunit.DependencyInjection.Logging" Version="9.0.0" />
</ItemGroup>
</Project>
47 changes: 47 additions & 0 deletions extensions/AzureOpenAI/Internals/AzureOpenAIClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,50 @@ internal static AzureOpenAIClient Build(
}
}
}

// Use only for local debugging - Usage:
//
// 1. Add this code in the builder above:
//
// options.Transport = new HttpClientPipelineTransport(new HttpClient(new DebuggingHandler(new HttpClientHandler())));
//
// 2. Add these at the top:
//
// using System.Threading;
// using System.Threading.Tasks;
//
// 3. Uncomment this class:
//
// #pragma warning disable CA1303
// internal class DebuggingHandler : DelegatingHandler
// {
// public DebuggingHandler(HttpMessageHandler innerHandler) : base(innerHandler)
// {
// }
//
// protected override async Task<HttpResponseMessage> SendAsync(
// HttpRequestMessage request, CancellationToken cancellationToken)
// {
// // Log request URI
// Console.WriteLine("#### Request URI: " + request.RequestUri);
//
// // Log request headers
// Console.WriteLine("#### Request Headers:");
// foreach (var header in request.Headers)
// {
// Console.WriteLine($"#### {header.Key}: {string.Join(", ", header.Value)}");
// }
//
// // Send the request to the inner handler
// var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
//
// // Optionally, log response headers here
// Console.WriteLine("#### Response Headers:");
// foreach (var header in response.Headers)
// {
// Console.WriteLine($"#### {header.Key}: {string.Join(", ", header.Value)}");
// }
//
// return response;
// }
// }
8 changes: 8 additions & 0 deletions extensions/OpenAI/OpenAI/OpenAITextGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ public async IAsyncEnumerable<string> GenerateTextAsync(
IAsyncEnumerable<StreamingTextContent> result = this._client.GetStreamingTextContentsAsync(prompt, skOptions, cancellationToken: cancellationToken);
await foreach (StreamingTextContent x in result)
{
// TODO: try catch
// if (x.Metadata?["Usage"] is not null)
// {
// var usage = x.Metadata["Usage"] as ChatTokenUsage;
// this._log.LogTrace("Usage report: input tokens {0}, output tokens {1}, output reasoning tokens {2}",
// usage?.InputTokenCount, usage?.OutputTokenCount, usage?.OutputTokenDetails.ReasoningTokenCount);
// }

if (x.Text == null) { continue; }

yield return x.Text;
Expand Down

0 comments on commit 689cace

Please sign in to comment.