diff --git a/samples/apps/copilot-chat-app/webapi/CopilotChat/Controllers/ChatController.cs b/samples/apps/copilot-chat-app/webapi/CopilotChat/Controllers/ChatController.cs index 55767805d2ed..52582051d9e0 100644 --- a/samples/apps/copilot-chat-app/webapi/CopilotChat/Controllers/ChatController.cs +++ b/samples/apps/copilot-chat-app/webapi/CopilotChat/Controllers/ChatController.cs @@ -142,13 +142,13 @@ await planner.Kernel.ImportOpenApiSkillFromFileAsync( { this._logger.LogInformation("Registering Jira Skill"); var authenticationProvider = new BasicAuthenticationProvider(() => { return Task.FromResult(openApiSkillsAuthHeaders.JiraAuthentication); }); - var hasServerUrlOverride = variables.Get("jira-server-url", out string serverUrlOverride); + var hasServerUrlOverride = variables.TryGetValue("jira-server-url", out string? serverUrlOverride); await planner.Kernel.ImportOpenApiSkillFromFileAsync( skillName: "JiraSkill", filePath: Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "CopilotChat", "Skills", "OpenApiSkills/JiraSkill/openapi.json"), authCallback: authenticationProvider.AuthenticateRequestAsync, - serverUrlOverride: hasServerUrlOverride ? new Uri(serverUrlOverride) : null); + serverUrlOverride: hasServerUrlOverride ? new Uri(serverUrlOverride!) : null); } // Microsoft Graph diff --git a/samples/apps/copilot-chat-app/webapi/CopilotChat/Extensions/SemanticKernelExtensions.cs b/samples/apps/copilot-chat-app/webapi/CopilotChat/Extensions/SemanticKernelExtensions.cs index a8db2d5ad529..15078838ad95 100644 --- a/samples/apps/copilot-chat-app/webapi/CopilotChat/Extensions/SemanticKernelExtensions.cs +++ b/samples/apps/copilot-chat-app/webapi/CopilotChat/Extensions/SemanticKernelExtensions.cs @@ -24,10 +24,7 @@ public static IServiceCollection AddCopilotChatPlannerServices(this IServiceColl { services.AddScoped(sp => new CopilotChatPlanner(Kernel.Builder .WithLogger(sp.GetRequiredService>()) - .WithConfiguration( - new KernelConfig().AddPlannerBackend( - sp.GetRequiredService>().Value) - ) // TODO verify planner has AI service configured + .WithPlannerBackend(sp.GetRequiredService>().Value)// TODO verify planner has AI service configured .Build())); // Register Planner skills (AI plugins) here. @@ -58,12 +55,12 @@ public static IKernel RegisterCopilotChatSkills(this IKernel kernel, IServicePro /// /// Add the completion backend to the kernel config for the planner. /// - private static KernelConfig AddPlannerBackend(this KernelConfig kernelConfig, AIServiceOptions options) + private static KernelBuilder WithPlannerBackend(this KernelBuilder kernelBuilder, AIServiceOptions options) { return options.Type switch { - AIServiceOptions.AIServiceType.AzureOpenAI => kernelConfig.AddAzureChatCompletionService(options.Models.Planner, options.Endpoint, options.Key), - AIServiceOptions.AIServiceType.OpenAI => kernelConfig.AddOpenAIChatCompletionService(options.Models.Planner, options.Key), + AIServiceOptions.AIServiceType.AzureOpenAI => kernelBuilder.WithAzureChatCompletionService(options.Models.Planner, options.Endpoint, options.Key), + AIServiceOptions.AIServiceType.OpenAI => kernelBuilder.WithOpenAIChatCompletionService(options.Models.Planner, options.Key), _ => throw new ArgumentException($"Invalid {nameof(options.Type)} value in '{AIServiceOptions.PropertyName}' settings."), }; } diff --git a/samples/apps/copilot-chat-app/webapi/CopilotChat/Skills/ChatSkills/ChatSkill.cs b/samples/apps/copilot-chat-app/webapi/CopilotChat/Skills/ChatSkills/ChatSkill.cs index c5dbd28a1c27..2ccadf1f3703 100644 --- a/samples/apps/copilot-chat-app/webapi/CopilotChat/Skills/ChatSkills/ChatSkill.cs +++ b/samples/apps/copilot-chat-app/webapi/CopilotChat/Skills/ChatSkills/ChatSkill.cs @@ -352,7 +352,7 @@ private async Task GetChatResponseAsync(SKContext chatContext) /// private async Task GetUserIntentAsync(SKContext context) { - if (!context.Variables.Get("planUserIntent", out string? userIntent)) + if (!context.Variables.TryGetValue("planUserIntent", out string? userIntent)) { var contextVariables = new ContextVariables(); contextVariables.Set("chatId", context["chatId"]); @@ -471,7 +471,7 @@ private Task AcquireExternalInformationAsync(SKContext context, string u { var contextVariables = context.Variables.Clone(); contextVariables.Set("tokenLimit", tokenLimit.ToString(new NumberFormatInfo())); - if (context.Variables.Get("proposedPlan", out string? proposedPlan)) + if (context.Variables.TryGetValue("proposedPlan", out string? proposedPlan)) { contextVariables.Set("proposedPlan", proposedPlan); } diff --git a/samples/apps/copilot-chat-app/webapi/CopilotChat/Skills/ChatSkills/ExternalInformationSkill.cs b/samples/apps/copilot-chat-app/webapi/CopilotChat/Skills/ChatSkills/ExternalInformationSkill.cs index 348ccf93505b..614bc0f5cfbc 100644 --- a/samples/apps/copilot-chat-app/webapi/CopilotChat/Skills/ChatSkills/ExternalInformationSkill.cs +++ b/samples/apps/copilot-chat-app/webapi/CopilotChat/Skills/ChatSkills/ExternalInformationSkill.cs @@ -78,7 +78,7 @@ public async Task AcquireExternalInformationAsync(string userIntent, SKC // Check if plan exists in ask's context variables. // If plan was returned at this point, that means it was approved and should be run - var planApproved = context.Variables.Get("proposedPlan", out var planJson); + var planApproved = context.Variables.TryGetValue("proposedPlan", out string? planJson); if (planApproved && !string.IsNullOrWhiteSpace(planJson)) { @@ -133,7 +133,7 @@ public async Task AcquireExternalInformationAsync(string userIntent, SKC continue; } - if (variables.Get(param.Key, out var value)) + if (variables.TryGetValue(param.Key, out string? value)) { plan.State.Set(param.Key, value); } diff --git a/samples/apps/copilot-chat-app/webapi/CopilotChatWebApi.csproj b/samples/apps/copilot-chat-app/webapi/CopilotChatWebApi.csproj index 5e0081044a28..97a6f3f8057a 100644 --- a/samples/apps/copilot-chat-app/webapi/CopilotChatWebApi.csproj +++ b/samples/apps/copilot-chat-app/webapi/CopilotChatWebApi.csproj @@ -11,13 +11,13 @@ - - - - - - - + + + + + + + diff --git a/samples/apps/copilot-chat-app/webapi/SemanticKernelExtensions.cs b/samples/apps/copilot-chat-app/webapi/SemanticKernelExtensions.cs index ba9d64e749db..b4bb661b2f00 100644 --- a/samples/apps/copilot-chat-app/webapi/SemanticKernelExtensions.cs +++ b/samples/apps/copilot-chat-app/webapi/SemanticKernelExtensions.cs @@ -42,7 +42,8 @@ internal static IServiceCollection AddSemanticKernelServices(this IServiceCollec IKernel kernel = Kernel.Builder .WithLogger(sp.GetRequiredService>()) .WithMemory(sp.GetRequiredService()) - .WithConfiguration(sp.GetRequiredService()) + .WithCompletionBackend(sp.GetRequiredService>().Value) + .WithEmbeddingBackend(sp.GetRequiredService>().Value) .Build(); sp.GetRequiredService()(sp, kernel); @@ -52,11 +53,6 @@ internal static IServiceCollection AddSemanticKernelServices(this IServiceCollec // Semantic memory services.AddSemanticTextMemory(); - // AI backends - services.AddScoped(serviceProvider => new KernelConfig() - .AddCompletionBackend(serviceProvider.GetRequiredService>().Value) - .AddEmbeddingBackend(serviceProvider.GetRequiredService>().Value)); - // Register skills services.AddScoped(sp => RegisterSkillsAsync); @@ -156,14 +152,14 @@ private static void AddSemanticTextMemory(this IServiceCollection services) /// /// Add the completion backend to the kernel config /// - private static KernelConfig AddCompletionBackend(this KernelConfig kernelConfig, AIServiceOptions options) + private static KernelBuilder WithCompletionBackend(this KernelBuilder kernelBuilder, AIServiceOptions options) { return options.Type switch { AIServiceOptions.AIServiceType.AzureOpenAI - => kernelConfig.AddAzureChatCompletionService(options.Models.Completion, options.Endpoint, options.Key), + => kernelBuilder.WithAzureChatCompletionService(options.Models.Completion, options.Endpoint, options.Key), AIServiceOptions.AIServiceType.OpenAI - => kernelConfig.AddOpenAIChatCompletionService(options.Models.Completion, options.Key), + => kernelBuilder.WithOpenAIChatCompletionService(options.Models.Completion, options.Key), _ => throw new ArgumentException($"Invalid {nameof(options.Type)} value in '{AIServiceOptions.PropertyName}' settings."), }; @@ -172,14 +168,14 @@ private static KernelConfig AddCompletionBackend(this KernelConfig kernelConfig, /// /// Add the embedding backend to the kernel config /// - private static KernelConfig AddEmbeddingBackend(this KernelConfig kernelConfig, AIServiceOptions options) + private static KernelBuilder WithEmbeddingBackend(this KernelBuilder kernelBuilder, AIServiceOptions options) { return options.Type switch { AIServiceOptions.AIServiceType.AzureOpenAI - => kernelConfig.AddAzureTextEmbeddingGenerationService(options.Models.Embedding, options.Endpoint, options.Key), + => kernelBuilder.WithAzureTextEmbeddingGenerationService(options.Models.Embedding, options.Endpoint, options.Key), AIServiceOptions.AIServiceType.OpenAI - => kernelConfig.AddOpenAITextEmbeddingGenerationService(options.Models.Embedding, options.Key), + => kernelBuilder.WithOpenAITextEmbeddingGenerationService(options.Models.Embedding, options.Key), _ => throw new ArgumentException($"Invalid {nameof(options.Type)} value in '{AIServiceOptions.PropertyName}' settings."), }; @@ -191,7 +187,7 @@ private static KernelConfig AddEmbeddingBackend(this KernelConfig kernelConfig, /// The service configuration /// Custom for HTTP requests. /// Application logger - private static IEmbeddingGeneration ToTextEmbeddingsService(this AIServiceOptions options, + private static ITextEmbeddingGeneration ToTextEmbeddingsService(this AIServiceOptions options, HttpClient? httpClient = null, ILogger? logger = null) {