question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow Custom httpClientHandler

See original GitHub issue

Context

I deployed my own LLM models on Azure OpenAI, the endpoint is a self-signed.

Issues Description

When I sent complete request to my self-signed endpoint, semantic kernel will return an error message:

Error: The SSL connection could not be established, see inner exception.

I tried to trace the inner exception at debugging mode, got:

The remote certificate is invalid because of errors in the certificate chain: RevocationStatusUnKnown"

Related Code

In OpenAIClientAbstract.cs:

    internal OpenAIClientAbstract(ILogger? log = null, IDelegatingHandlerFactory? handlerFactory = null)
    {
        this.Log = log ?? this.Log;
        this._handlerFactory = handlerFactory ?? new DefaultHttpRetryHandlerFactory();

        this._httpClientHandler = new() { CheckCertificateRevocationList = true };
        this._retryHandler = this._handlerFactory.Create(this.Log);
        this._retryHandler.InnerHandler = this._httpClientHandler;

        this.HTTPClient = new HttpClient(this._retryHandler);
        this.HTTPClient.DefaultRequestHeaders.Add("User-Agent", HTTPUseragent);
    }

this._httpClientHandler = new() { CheckCertificateRevocationList = true }; The default httpClientHandler is set to always check certificate RevocationList.

Feature Request

Allow pass customized httpClientHandler either from _handlerFactory or from kernelBuilder.

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lemillermicrosoftcommented, Mar 22, 2023

I don’t think there is a workaround right now. I believe @SergeyMenshykh was looking at enabling similar with https://github.com/microsoft/semantic-kernel/pull/73 and could address this as part of that change potentially.

0reactions
shawncalcommented, May 9, 2023

This is now possible – you can specify your own httpClient when instantiating adding the AI Connectors:

https://github.com/microsoft/semantic-kernel/blob/main/dotnet/src/Connectors/Connectors.AI.OpenAI/KernelConfigOpenAIExtensions.cs

For instance:

`IKernel kernel = Kernel.Builder .AddAzureTextCompletionService(“deploymentName”, “endpoint”, “apikey”, httpClient: myCustomHttpClient) .Build();

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Custom HTTPClient Handlers
This class expedites the development process in accessing data from a Web API, and allows for customizing the client handlers when the need ......
Read more >
HttpClientHandler Class (System.Net.Http)
Gets a writable dictionary (that is, a map) of custom properties for the HttpClient requests. The dictionary is initialized empty; you can insert...
Read more >
c# - Adding handler to default http client in ASP.NET Core
Documentation states that you can only add handlers or configure the inner most handler to named or typed clients.
Read more >
Fun with the HttpClient pipeline - Thomas Levesque's .NET Blog
See, HTTP message handlers can be used to add custom behavior to how requests and responses are processed. I'll give a few examples....
Read more >
Mocking an HttpClient using an HttpClientHandler
It's very easy to test a class that has an HttpClient using a custom HttpClientHandler . This way you don't need to change...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found