|
| 1 | +// Copyright (c) Microsoft. All rights reserved. |
| 2 | + |
| 3 | +using Microsoft.KernelMemory.AI.AzureOpenAI; |
| 4 | +using Microsoft.KM.TestHelpers; |
| 5 | +using Xunit; |
| 6 | +using Xunit.Abstractions; |
| 7 | + |
| 8 | +namespace Microsoft.AzureOpenAI.FunctionalTests; |
| 9 | + |
| 10 | +/// <summary> |
| 11 | +/// References: |
| 12 | +/// - https://github.com/Azure/azure-sdk-for-net/issues/46109 |
| 13 | +/// - https://github.com/microsoft/semantic-kernel/issues/8929 |
| 14 | +/// - https://github.com/microsoft/kernel-memory/issues/855 |
| 15 | +/// </summary> |
| 16 | +public class Issue855Test : BaseFunctionalTestCase |
| 17 | +{ |
| 18 | + private readonly AzureOpenAITextEmbeddingGenerator _target; |
| 19 | + |
| 20 | + public Issue855Test(IConfiguration cfg, ITestOutputHelper output) : base(cfg, output) |
| 21 | + { |
| 22 | + this._target = new AzureOpenAITextEmbeddingGenerator(this.AzureOpenAIEmbeddingConfiguration); |
| 23 | + } |
| 24 | + |
| 25 | + [Fact(Skip = "Enable and run manually")] |
| 26 | + [Trait("Category", "Manual")] |
| 27 | + [Trait("Category", "BugFix")] |
| 28 | + public async Task ItDoesntWhenThrottling() |
| 29 | + { |
| 30 | + for (int i = 0; i < 50; i++) |
| 31 | + { |
| 32 | + Console.WriteLine($"## {i}"); |
| 33 | + await this._target.GenerateEmbeddingBatchAsync( |
| 34 | + [RndStr(), RndStr(), RndStr(), RndStr(), RndStr(), RndStr(), RndStr(), RndStr(), RndStr(), RndStr()]); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | +#pragma warning disable CA5394 |
| 39 | + private static string RndStr() |
| 40 | + { |
| 41 | + var random = new Random(); |
| 42 | + return new(Enumerable.Repeat(" ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 ", 8000) |
| 43 | + .Select(s => s[random.Next(s.Length)]).ToArray()); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +#pragma warning disable IDE0055 |
| 48 | +/* When the test fails: after pausing and trying to restart, an exception occurs. |
| 49 | +
|
| 50 | +Microsoft.SemanticKernel.HttpOperationException: Service request failed. |
| 51 | +
|
| 52 | +Microsoft.SemanticKernel.HttpOperationException |
| 53 | +Service request failed. |
| 54 | +Status: 401 (Unauthorized) <===== ******* Caused by https://github.com/Azure/azure-sdk-for-net/issues/46109 |
| 55 | +
|
| 56 | + at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.RunRequestAsync[T](Func`1 request) |
| 57 | + at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.GetEmbeddingsAsync(String targetModel, IList`1 data, Kernel kernel, Nullable`1 dimensions, CancellationToken cancellationToken) |
| 58 | + at Microsoft.KernelMemory.AI.AzureOpenAI.AzureOpenAITextEmbeddingGenerator.GenerateEmbeddingBatchAsync(IEnumerable`1 textList, CancellationToken cancellationToken) in extensions/AzureOpenAI/AzureOpenAI/AzureOpenAITextEmbeddingGenerator.cs:line 132 |
| 59 | + at Microsoft.AzureOpenAI.FunctionalTests.Issue855Test.ItDoesntFailWith401() in extensions/AzureOpenAI/AzureOpenAI.FunctionalTests/Bug46109Test.cs:line 43 |
| 60 | + at Xunit.DependencyInjection.DependencyInjectionTestInvoker.AsyncStack(Task task, Activity activity) in S:\GitHub\Xunit.DependencyInjection\src\Xunit.DependencyInjection\DependencyInjectionTestInvoker.cs:line 174 |
| 61 | +
|
| 62 | +System.ClientModel.ClientResultException |
| 63 | +Service request failed. |
| 64 | +Status: 401 (Unauthorized) |
| 65 | +
|
| 66 | + at Azure.AI.OpenAI.ClientPipelineExtensions.ProcessMessageAsync(ClientPipeline pipeline, PipelineMessage message, RequestOptions options) |
| 67 | + at Azure.AI.OpenAI.Embeddings.AzureEmbeddingClient.GenerateEmbeddingsAsync(BinaryContent content, RequestOptions options) |
| 68 | + at OpenAI.Embeddings.EmbeddingClient.GenerateEmbeddingsAsync(IEnumerable`1 inputs, EmbeddingGenerationOptions options, CancellationToken cancellationToken) |
| 69 | + at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.RunRequestAsync[T](Func`1 request) |
| 70 | +
|
| 71 | +
|
| 72 | +
|
| 73 | +warn: Microsoft.KernelMemory.AI.AzureOpenAI.AzureOpenAITextEmbeddingGenerator[0] |
| 74 | + Tokenizer not specified, will use GPT4oTokenizer. The token count might be incorrect, causing unexpected errors |
| 75 | +
|
| 76 | +## 0 |
| 77 | +## 1 |
| 78 | +## 2 |
| 79 | +## 3 |
| 80 | +... |
| 81 | +... |
| 82 | +warn: Microsoft.KernelMemory.AI.AzureOpenAI.Internals.ClientSequentialRetryPolicy[0] |
| 83 | + Header Retry-After found, value 21 |
| 84 | +
|
| 85 | +warn: Microsoft.KernelMemory.AI.AzureOpenAI.Internals.ClientSequentialRetryPolicy[0] |
| 86 | + Delay extracted from HTTP response: 21000 msecs |
| 87 | +*/ |
0 commit comments