If you found value in this post, consider following me on X @davidpuplava for more valuable information about Game Dev, OrchardCore, C#/.NET and other topics.
This is Part 1 of a multi-part review of Microsoft's Semantic Kernel SDK.
You can read Part 2 - Planning, Memory & Embeddings here.
Semantic Kernel is an open source software development kit (SDK) from Microsoft for building Artificial Intelligence (AI) agents.
As of July 2024, programming languages supported are C#, Python and Java.
I prefer C# and am fascinated by the world of AI and these so-called AI agents. So Semantic Kernel is a natural choice for exploring this niche of AI.
I have a rudimentary working knowledge about AI and Large Language Models (LLMs), but otherwise, I am currently a complete beginner.
I like solving problems and am excited about the kinds of problems that AI might help me to solve.
My review of Semantic Kernel is less an authoritative opinion about it's efficacy, and more of an exploration into whether I can use it to solve certain problems I encounter on a regular basis.
This review is me getting started with Semantic Kernel's step-by-step walk through.
I am using Visual Studio Code and Git to clone the open source repository: https://github.com/microsoft/semantic-kernel.
The GitHub repository has a folder with several Polyglot notebooks, which this is my exposure to and think they are quite nice.
If you've never used a Polyglot notebook before, it's a cross between a Wiki page and a REPL app. You can read along with written documentation and then execute blocks of code inline with the documentation.
Very nice.
The Semantic Kernel SDK comes with support for loading LLMs from Microsoft Azure and OpenAI. All you need to provide is a handful of configuration settings like and API key and LLM model name.
For my walk through I used an OpenAI key to get started quickly. Long term, I hope to use Semantic Kernel with a local LLM but that will have to wait.
Programmatically, the SDK the latest dotnet prescribed builder patter to construct an Semantic Kernal type application.
With just a few lines of code, you're up and running with a Semantic Kernel specific application that is configured to use an Azure or OpenAI ChatCompletion service.
Semantic Kernel essentially is providing a so-called "Kernel" application that allows you as the developer to orchestrate interaction with various services, both AI in nature and your own home grown services.
There are a few terms you need to familiarize yourself with like Semantic Plugins and Semantic Functions, which I call Plugins and Functions moving forward.
The objective is to compose together the right plugins and functions to solve your specific problem.
The first Kernel Plugin you use is the "Fun Plugin" which essentiallys asks for a family friendly joke.
A core idea with Semantic Kernel is to construct an AI chat "prompt", which is specific instruction text you give to a LLM to describe the output you want it provide you.
Semantic Kernel prompts can exist in individual files on disk, or constructed in code also known as "inline".
Now for more interesting stuff, which is a chat like experience that you'd expect from something like ChatGPT.
The key idea here is that these Kernel prompts have a special syntax where you as the developer can specify parameters that your user can pass in as arguments to the Kernel.
Semantic Kernel describes these as "Kernel Arguments" which is probably a misuses of the term "argument" but that is not important here.
What's important is that you can inject dynamic information into your Kernal's prompt. For example, see the following here where you have two Kernal Arguments. A $history
for injecting your chat history information, and a $userInput
for the next user message for the chat bot.
The rest of this notebook, you construct your Kernel Arguments object which is essentially a key/value dictionary and pass it to your constructed chat bot prompt to get a book suggestion.
This is surprisingly very little code to achieve exceptional results that, with a little effort, could rival the user experience for these large LLM services.
The rest of the notebook tutorial demonstrates how you can write a singular function to generate a chat response, store it in the history argument value and keep entering user input to get context aware, converstational output.
Again, with very little code, this is a very cool experience.
This is only my first look at the Semantic Kernel SDK.
I have a lot more of their step-by-step Polyglot Notebooks to get through, but overall I'm happy what you can achieve with very little code running Semantic Kernel.
Check back for future parts where I continue working through how Semantic Kernel can solve everyday problems.
If you found value in this post, consider following me on X @davidpuplava for more valuable information about Game Dev, OrchardCore, C#/.NET and other topics.