workshop/dotnet/Lessons/Lesson6/Program.cs (22 lines of code) (raw):

using Core.Utilities.Config; // Add import for Plugins using Core.Utilities.Plugins; // Add import required for StockService using Core.Utilities.Services; using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Connectors.OpenAI; // Add ChatCompletion import using Microsoft.SemanticKernel.ChatCompletion; // Temporarily added to enable Semantic Kernel tracing using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; // TODO: Step 1 -- Add imports for Agents and Azure.Identity // Initialize the kernel with chat completion IKernelBuilder builder = KernelBuilderProvider.CreateKernelWithChatCompletion(); // Enable tracing builder.Services.AddLogging(services => services.AddConsole().SetMinimumLevel(LogLevel.Trace)); Kernel kernel = builder.Build(); // Initialize Time plugin and registration in the kernel kernel.Plugins.AddFromObject(new TimeInformationPlugin()); // TODO: Step 2 - Initialize connection to Grounding with Bing Search tool and agent // Initialize Stock Data Plugin and register it in the kernel HttpClient httpClient = new(); StockDataPlugin stockDataPlugin = new(new StocksService(httpClient)); kernel.Plugins.AddFromObject(stockDataPlugin); // Get chatCompletionService and initialize chatHistory with system prompt var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>(); ChatHistory chatHistory = new("You are a friendly financial advisor that only emits financial advice in a creative and funny tone"); // Remove the promptExecutionSettings and kernelArgs initialization code // Add system prompt OpenAIPromptExecutionSettings promptExecutionSettings = new() { // Add Auto invoke kernel functions as the tool call behavior ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions }; // Initialize kernel arguments KernelArguments kernelArgs = new(promptExecutionSettings); // TODO: Step 3 - Uncomment out all code after "Execute program" comment // Execute program. /* const string terminationPhrase = "quit"; string? userInput; do { Console.Write("User > "); userInput = Console.ReadLine(); if (userInput is not null and not terminationPhrase) { Console.Write("Assistant > "); // Initialize fullMessage variable and add user input to chat history string fullMessage = ""; chatHistory.AddUserMessage(userInput); // TODO: Step 4 - Invoke the agent Console.WriteLine(); } } while (userInput != terminationPhrase); */