Artificial Intelligence (AI) is transforming the way businesses interact with their customers, and AI-driven virtual assistants or receptionists are becoming increasingly popular. These AI receptionists can handle routine inquiries, manage appointments, and provide essential information, all while delivering a seamless user experience. In this article, we will explore how to build an AI receptionist using Microsoft Semantic Kernel and Azure OpenAI.
Introduction
Microsoft Semantic Kernel is a powerful framework that leverages AI models to perform complex tasks such as language understanding, text generation, and more. By integrating Semantic Kernel with OpenAI's models, developers can create sophisticated AI-driven applications. In this article, we will guide you through building an AI receptionist capable of handling customer interactions in a software house.
Prerequisites
Before diving into the implementation, ensure that you have the following prerequisites.
- Azure Subscription: To access OpenAI services.
- .NET SDK: Installed on your development environment.
- Microsoft.SemanticKernel NuGet Package: For integrating Semantic Kernel.
- Basic Knowledge of C#: Familiarity with C# programming and asynchronous programming patterns.
Project Setup
Start by creating a new console application in your preferred development environment, such as Visual Studio or Visual Studio Code.
dotnet new console -n LearnSemanticKernel.AIReceptionist
Once your project is created, install the necessary NuGet package by running.
dotnet add package Microsoft.SemanticKernel
dotnet add package Microsoft.SemanticKernel.Connectors.OpenAI
These packages provide the required classes and methods to integrate Semantic Kernel with OpenAI.
Code Implementation
Below is the complete code for building an AI receptionist using Microsoft Semantic Kernel and OpenAI.
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
namespace LearnSemanticKernel.AIReceptionist
{
internal class Program
{
static async Task Main(string[] args)
{
// Create a kernel with Azure OpenAI chat completion
var builder = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion("modelid", "endpoint", "apiKey");
// Build the kernel
Kernel kernel = builder.Build();
var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();
// Enable planning
OpenAIPromptExecutionSettings openAIPromptExecutionSettings = new()
{
ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions
};
var businessInfoText = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(),"Data/BusinessInfo.txt"));
// Create a history store for the conversation
var history = new ChatHistory(businessInfoText);
// Initiate a back-and-forth chat
string? userInput;
do
{
// Collect user input
Console.Write("User > ");
userInput = Console.ReadLine();
// Add user input
history.AddUserMessage(userInput);
// Get the response from the AI
var result = await chatCompletionService.GetChatMessageContentAsync(
history,
executionSettings: openAIPromptExecutionSettings,
kernel: kernel);
// Print the results
Console.WriteLine("Assistant > " + result);
// Add the message from the agent to the chat history
history.AddMessage(result.Role, result.Content ?? string.Empty);
} while (userInput is not null);
}
}
}


Join the conversation! Your thoughts help the community grow.