// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information. // using Microsoft.SemanticKernel; public class Program { public static async Task Main(string[] args) { var AZURE_OPENAI_SYSTEM_PROMPT = Environment.GetEnvironmentVariable("AZURE_OPENAI_SYSTEM_PROMPT") ?? "You are a helpful AI assistant."; // NOTE: Never deploy your API Key in client-side environments like browsers or mobile apps // SEE: https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety // Get the required environment variables var AZURE_OPENAI_API_KEY = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? ""; var AZURE_OPENAI_ENDPOINT = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? ""; var AZURE_OPENAI_CHAT_DEPLOYMENT = Environment.GetEnvironmentVariable("AZURE_OPENAI_CHAT_DEPLOYMENT") ?? ""; // Check if the required environment variables are set var azureOk = AZURE_OPENAI_API_KEY != null && !AZURE_OPENAI_API_KEY.StartsWith("(); var kernel = builder.Build(); // Create the streaming chat completions helper var chat = new SemanticKernelChatCompletionsFunctionsStreamingClass(AZURE_OPENAI_SYSTEM_PROMPT!, kernel); // Loop until the user types 'exit' while (true) { // Get user input Console.Write("User: "); var userPrompt = Console.ReadLine(); if (string.IsNullOrEmpty(userPrompt) || userPrompt == "exit") break; // Get the response Console.Write("\nAssistant: "); await chat.GetStreamingChatMessageContentsAsync(userPrompt, (content) => Console.Write(content.Content) ); Console.WriteLine("\n"); } return 0; } }