microsoft / kernel-memory

RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.

Home Page:https://microsoft.github.io/kernel-memory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] how I can add ConfigureHttpClientDefaults for SK Retry logic?

KSemenenko opened this issue · comments

Context / Scenario

I need retry logic for embedding requests, becse for 500 pages pdf I deffenelty will reach TooManyRequest issue, for Azure ADA2 model.

Question

in SK I can do like this:

semanticKernalBuilder.Services.ConfigureHttpClientDefaults(c =>
{
    // Use a standard resiliency policy, augmented to retry on 401 Unauthorized for this example
    c.AddStandardResilienceHandler().Configure(o =>
    {
        o.Retry.ShouldHandle = args => ValueTask.FromResult(args.Outcome.Result?.StatusCode is HttpStatusCode.Unauthorized);
    });
});

how can I do this for KM?

I see I can pass httpClient

.WithAzureOpenAITextGeneration(new AzureOpenAIConfig()
{
    Endpoint = azureOpenAi.GPT3SummarizationModel.Endpoint,
    APIKey = azureOpenAi.GPT3SummarizationModel.ApiKey,
    Deployment = azureOpenAi.GPT3SummarizationModel.DeploymentOrModelId,
    Auth = AzureOpenAIConfig.AuthTypes.APIKey
}, 
httpClient: httpClient)

and it workds fine.

but any compibantion with passing IServiceCollection into Builder, or add services into build isn't work

 }).WithAzureOpenAITextGeneration(new AzureOpenAIConfig()
            {
                Endpoint = azureOpenAi.SummarizationModel.Endpoint,
                APIKey = azureOpenAi.SummarizationModel.ApiKey,
                Deployment = azureOpenAi.SummarizationModel.DeploymentOrModelId,
                Auth = AzureOpenAIConfig.AuthTypes.APIKey,

                MaxTokenTotal = 25000,

// is this retry logic?
                MaxRetries = 1230


            }, 
// custom http client with retry logic 
httpClient: httpClient)

i have same issues

@strikene adding configured http client works.