From Zero To AI Hero, Half 1: Semantic Kernel – DZone – Uplaza

GenAI and Coding: A Quick Story

After I first heard in regards to the Semantic Kernel, I used to be confused by the time period. As a former C++ man who has labored with Working Programs, I believed it had one thing to do with it. Although I’ve adopted the Generative AI panorama, I felt most of it was the preliminary hype (Garner’s hype curve). Predicting tokens was beautiful, however I by no means thought it could affect and create usable bots that would combine with current functions.

Then, there comes LangChain, which instantly grew to become one of many fastest-growing open-source tasks of 2023. LangChain is an AI orchestrator that helps builders sprinkle the magic of AI into their new and current functions. LangChain got here in Python, Java, and JavaScript, and there was a void for C# of us. Semantic Kernel stuffed this hole: though it differs from LangChain in precept and elegance, it was primarily constructed to make the .NET of us completely happy. Icing on the cake? It additionally helps Java and Python.

Semantic Kernel

What Is Semantic Kernel?

Within the evolving panorama of AI, integrating clever, context-aware functionalities into functions has turn out to be extra essential than ever. Microsoft’s Semantic Kernel (SK) is a strong framework that permits builders to embed AI capabilities, reminiscent of pure language processing, into .NET functions. Whether or not you’re seeking to construct chatbots, automate workflows, or improve decision-making processes, Semantic Kernel gives a strong basis. 

Semantic Kernel is an extensible framework that leverages AI fashions like OpenAI’s GPT to allow pure language understanding and era inside .NET functions. It gives a set of APIs and instruments that enable builders to create AI-driven brokers able to processing textual content, producing content material, and meaningfully interacting with customers.

At its coronary heart, Semantic Kernel focuses on “plugins” — modular, reusable elements that encapsulate particular capabilities reminiscent of understanding consumer intent, summarizing content material, or producing responses. These may be mixed and orchestrated to construct refined AI-driven functions.

Why Semantic Kernel?

LangChain is superb, and Semantic Kernel is equally fabulous. Selecting one over the opposite ought to rely in your type, programming languages, or particular use circumstances. For instance, if that you must combine Gen AI capabilities right into a browser-based answer reminiscent of ReactJS/Angular/Vue or vanilla net utility, I’d use LangChain, because it helps JavaScript.

Are We Solely Going To Speak About Sematic Kernel?

No: on this multi-part sequence, although the first focus could be on Semantic Kernel, we are going to nonetheless discover use circumstances of LangChain and use it as a cousin to Semantic Kernel for particular eventualities and use circumstances.

Sufficient speak! Let’s construct one thing with SK!

Stipulations

Earlier than diving into the code, guarantee you could have the next stipulations:

  1. .NET 7.0 SDK or later: Obtain it from the .NET web site.
  2. Visible Studio 2022: Make sure the ASP.NET Core workload is put in.
  3. Azure AI Mannequin: It’s potential to make use of OpenAI or Different fashions straight, however for this sequence, I’ll keep on with AI fashions which might be deployed in Azure as I’ve sufficient Azure credit as an MS MVP (P.S.: In case you plan to make use of OpenAI’s fashions, you’ll want an API key, which you’ll be able to acquire from the OpenAI web site.)

Setting Up Your Undertaking

Step one in integrating Semantic Kernel into your utility is to arrange the atmosphere. Let’s begin with a easy console utility after which stroll via including Semantic Kernel to the combo.

1. Create a New Console Undertaking

It is nice when you favor to create a brand new console utility utilizing Visible Studio or VS Code.

dotnet new console -n sk-console 
cd sk-console 

2. Add the Semantic Kernel NuGet Package deal

Add Semantic Kernel NuGet bundle utilizing the next command:

dotnet add bundle Microsoft.SemanticKernel

3. Setup Semantic Kernel

Open your Program.cs file and configure the Semantic Kernel service. This service will deal with interactions with the AI mannequin. Please check out the operate AddAzureOpenAIChatCompletion(). Because the identify suggests, this operate helps us combine Open AI chat completion utilizing the Open AI mannequin hosted in Azure onto our Semantic Kernel Builder. The parameters’ values are from my already deployed gtp-4o mannequin on Azure AI Studio. I’ll write a separate article on deploying AI fashions utilizing Azure AI Studio and hyperlink it right here later.

var builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatCompletion(
    deploymentName: "",
    endpoint: "",
    apiKey: ""
);
var kernel = builder.Construct();

Consider this KernelBuilder as just like the ASP.NET Core HostBuilder. Earlier than the Construct() name, you would want to provide your entire plugin info(extra on plugins later), in order that SK would pay attention to it.

4. Ask the First Query

Console.WriteLine(await kernel.InvokePromptAsync("What is Gen AI?"));

5. Operating the Utility

With every little thing configured, you’re able to run your utility. Run the beneath command within the terminal.

6. We Did It!

All is nicely. Our Semantic Kernel configuration used the Deployed Azure Open AI mannequin to reply our query. Hooray!

I do know, I do know, this is not a lot. However I nonetheless printed the supply code on GitHub right here. That is the place to begin, and we are going to construct from right here.

Conclusion

Semantic Kernel is a robust device for bringing superior AI capabilities to your .NET functions. Following the steps outlined on this multi-part sequence, you may rapidly get began with Semantic Kernel and combine clever, context-aware functionalities into your tasks. The chances are huge, from easy chatbots to complicated, AI-driven workflows.

As we dive deeper, keep in mind that the important thing to successfully leveraging the Semantic Kernel is in the way you outline and orchestrate your abilities. With a strong understanding of those fundamentals, you are nicely in your method to constructing the subsequent era of clever functions.

What’s Subsequent?

Are we executed? No. Now that we all know add Semantic Kernel in a .NET Utility, it’s time to take this flight off the bottom. We are going to dig deeper and deeper as we go together with this multi-part sequence. We are going to talk about plugins and brokers, native SLMs and Ollama, Semantic Kernel on ASP.NET Core functions, mixing SK with AutoGen and LangChain, and extra.

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version