kinfey / SemanticKernelCookBook

Semantic Kernel's cook book
108 stars 18 forks source link

System.UriFormatException on InvokeAsync #2

Closed mrochon closed 10 months ago

mrochon commented 10 months ago

I am trying to implement your [ #LearnSK sample] (https://github.com/kinfey/SemanticKernelCookBook/blob/main/notebooks/dotNET/02/LearnSK.ipynb) but getting System.UriFormatexception when executing:

    var transalteContent = await kernel.InvokeAsync(plugin["Basic"], new() { ["input"] = "你好,我是你的 AI 编排助手 - Semantic Kernel" });

(Using 1.0.1 version of SK nugets)

Exception detail: System.UriFormatException HResult=0x80131537 Message=Invalid URI: The format of the URI could not be determined. Source=System.Private.Uri StackTrace: at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions) at System.Uri..ctor(String uriString) at Microsoft.SemanticKernel.OpenAIServiceCollectionExtensions.CreateAzureOpenAIClient(String endpoint, AzureKeyCredential credentials, HttpClient httpClient) at Microsoft.SemanticKernel.OpenAIServiceCollectionExtensions.<>cDisplayClass20_0.b_0(IServiceProvider serviceProvider, Object ) at Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryCallSite.<>cDisplayClass4_0.<.ctor>b0(IServiceProvider sp) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetKeyedService(Type serviceType, Object serviceKey, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetRequiredKeyedService(Type serviceType, Object serviceKey, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetRequiredKeyedService(Type serviceType, Object serviceKey) at Microsoft.Extensions.DependencyInjection.ServiceProviderKeyedServiceExtensions.GetRequiredKeyedService(IServiceProvider provider, Type serviceType, Object serviceKey) at Microsoft.Extensions.DependencyInjection.ServiceProviderKeyedServiceExtensions.GetRequiredKeyedService[T](IServiceProvider provider, Object serviceKey) at Microsoft.Extensions.DependencyInjection.ServiceProviderKeyedServiceExtensions.GetKeyedServices[T](IServiceProvider provider, Object serviceKey) at Microsoft.SemanticKernel.Kernel.b34_0[T](Object key) at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext() at System.Linq.Enumerable.TryGetLast[TSource](IEnumerable1 source, Boolean& found) at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable1 source) at Microsoft.SemanticKernel.Services.OrderedAIServiceSelector.<TrySelectAIService>g__GetAnyService|3_0[T](Kernel kernel) at Microsoft.SemanticKernel.Services.OrderedAIServiceSelector.TrySelectAIService[T](Kernel kernel, KernelFunction function, KernelArguments arguments, T& service, PromptExecutionSettings& serviceSettings) at Microsoft.SemanticKernel.KernelFunctionFromPrompt.<RenderPromptAsync>d__16.MoveNext() at Microsoft.SemanticKernel.KernelFunctionFromPrompt.<InvokeCoreAsync>d__3.MoveNext() at System.Threading.Tasks.ValueTask1.get_Result() at Microsoft.SemanticKernel.KernelFunction.d18.MoveNext() at Program.<

$>d0.MoveNext() in C:\Users\mrochon\source\repos\ai-samples\SemKernel\SK1\Program.cs:line 48

kinfey commented 10 months ago

I think this problem has no correct endpoint for aoai ,you need to set the azure openai service endpoint

mrochon commented 10 months ago

Ah, yes - the earlier version of AddAzureOpenAICompletion had a different sequence of string parameters. Thanks.