Closed antpass79 closed 1 year ago
Hi @antpass79
the problem seems to be the default code we have to create a HttpClient
instance.
You can create the HttpClient and pass it to the kernel
I created a Blazor WebAssembly App and added the following component. Can you try this out and let me know if it works for you. We will look at adding a sample for this.
@page "/promptChaining"
<PageTitle>Prompt Chaining</PageTitle>
<h1>Prompt Chaining</h1>
<p role="status">Response: @response</p>
@code {
private string response = "Loading...";
protected override async Task OnInitializedAsync()
{
IKernel kernel = new KernelBuilder()
.WithAzureTextCompletionService(
deploymentName: "text-davinci-003",
endpoint: "https://<your endpoint>.openai.azure.com/",
apiKey: "<your API key>",
httpClient: new HttpClient()
)
.Build();
string translationPrompt = @"{{$input}}
Translate the text to math.";
string summarizePrompt = @"{{$input}}
Give me a TLDR with the fewest words.";
var translator = kernel.CreateSemanticFunction(translationPrompt);
var summarize = kernel.CreateSemanticFunction(summarizePrompt);
translator.SetAIService(() => kernel.GetService<ITextCompletion>());
summarize.SetAIService(() => kernel.GetService<ITextCompletion>());
string inputText = @"
1st Law of Thermodynamics - Energy cannot be created or destroyed.
2nd Law of Thermodynamics - For a spontaneous process, the entropy of the universe increases.
3rd Law of Thermodynamics - A perfect crystal at zero Kelvin has zero entropy.";
// Run two prompts in sequence (prompt chaining)
var output = await kernel.RunAsync(inputText, translator, summarize);
if (output.ErrorOccurred)
{
response = output.LastErrorDescription;
Console.Error.WriteLine(output.LastException?.ToString());
}
else
{
response = output.Result;
}
}
}
Hi @markwallace-microsoft it works perfectly!
Sorry, I didn't see the httpClient parameter to use.
Thank you, Antonio
Hi @markwallace-microsoft
I had the same issue, and after using your suggestion, I'm getting another exception:
Unhandled exception rendering component: Invalid URI: The format of the URI could not be determined. System.UriFormatException: Invalid URI: The format of the URI could not be determined.
Do you have any suggestion?
Describe the bug Using SK and Azure Open AI in Blazor WebAssembly, a PlatformNotSupportException is logged in DevTools.
To Reproduce Steps to reproduce the behavior:
Error: The type initializer for 'NonDisposableHttpClientHandler' threw an exception. System.TypeInitializationException: The type initializer for 'NonDisposableHttpClientHandler' threw an exception. ---> System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Net.Http.BrowserHttpHandler.get_SslOptions() at .........
Expected behavior As a mantion in the tutorial:
ΔE = 0, ΔSuniv > 0, S = 0 at 0K.
Web:
Additional context I tried to change the HttpHandler using WithRetryHandlerFactory before the Build call. I tried also Configure and SetHttpRetryHandlerFactory before the Build call. But the stack was the same. Investigating the code I found here https://github.com/microsoft/semantic-kernel/blob/main/dotnet/src/InternalUtilities/src/Http/HttpClientProvider.cs#L30 that the GetHttpClient uses correctly the HttpHandler that I defined by the Factory function, but the InnerHandler is set with "NonDisposableHttpClientHandler.Instance" and I cannot change it. Based on the stack, I think that the issue could be related to it.