#r "nuget: Microsoft.SemanticKernel, 1.23.0" #!import config/Settings.cs #!import config/Utils.cs using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Connectors.OpenAI; using Kernel = Microsoft.SemanticKernel.Kernel; var builder = Kernel.CreateBuilder(); // Configure AI backend used by the kernel var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile(); if (useAzureOpenAI) builder.AddAzureOpenAIChatCompletion(model, azureEndpoint, apiKey); else builder.AddOpenAIChatCompletion(model, apiKey, orgId); var kernel = builder.Build(); #pragma warning disable SKEXP0001 OpenAIPromptExecutionSettings openAIPromptExecutionSettings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }; var pluginsDirectory = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "..", "..", "prompt_template_samples"); kernel.ImportPluginFromPromptDirectory(Path.Combine(pluginsDirectory, "SummarizePlugin")); kernel.ImportPluginFromPromptDirectory(Path.Combine(pluginsDirectory, "WriterPlugin")); var ask = "Tomorrow is Valentine's day. I need to come up with a few date ideas. My significant other likes poems so write them in the form of a poem."; var result = await kernel.InvokePromptAsync(ask, new(openAIPromptExecutionSettings)); Console.WriteLine(result); using Microsoft.SemanticKernel.ChatCompletion; var chatCompletionService = kernel.GetRequiredService(); var chatHistory = new ChatHistory(); chatHistory.AddUserMessage(ask); var chatCompletionResult = await chatCompletionService.GetChatMessageContentAsync(chatHistory, openAIPromptExecutionSettings, kernel); Console.WriteLine($"Result: {chatCompletionResult}\n"); Console.WriteLine($"Chat history: {JsonSerializer.Serialize(chatHistory)}\n");