DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Zero to AI Hero, Part 3: Unleashing the Power of Agents in Semantic Kernel
  • Zero to AI Hero, Part 2: Understanding Plugins in Semantic Kernel, A Deep Dive With Examples
  • Feature Flags in .NET 8 and Azure
  • Azure AI and GPT-4: Real-World Applications and Best Practices

Trending

  • How To Replicate Oracle Data to BigQuery With Google Cloud Datastream
  • Why We Still Struggle With Manual Test Execution in 2025
  • Stateless vs Stateful Stream Processing With Kafka Streams and Apache Flink
  • Beyond Microservices: The Emerging Post-Monolith Architecture for 2025
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. From Zero to AI Hero, Part 1: Jumpstart Your Journey With Semantic Kernel

From Zero to AI Hero, Part 1: Jumpstart Your Journey With Semantic Kernel

Follow the steps outlined in this multi-part series to start with Semantic Kernel and integrate intelligent, context-aware functionalities into your projects.

By 
Aneesh Gopalakrishnan user avatar
Aneesh Gopalakrishnan
·
Sep. 03, 24 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
7.0K Views

Join the DZone community and get the full member experience.

Join For Free

GenAI and Coding: A Short Story

When I first heard about the Semantic Kernel, I was confused by the term. As a former C++ guy who has worked with Operating Systems, I thought it had something to do with it. Though I have followed the Generative AI landscape, I felt most of it was the initial hype (Garner's hype curve). Predicting tokens was lovely, but I never thought it would influence and create usable bots that could integrate with existing applications.

Then, there comes LangChain, which immediately became one of the fastest-growing open-source projects of 2023. LangChain is an AI orchestrator that helps developers sprinkle the magic of AI into their new and existing applications. LangChain came in Python, Java, and JavaScript, and there was a void for C# folks. Semantic Kernel filled this gap: although it differs from LangChain in principle and style, it was essentially built to make the .NET folks happy. Icing on the cake? It also supports Java and Python.

Semantic Kernel

What Is Semantic Kernel?

In the evolving landscape of AI, integrating intelligent, context-aware functionalities into applications has become more crucial than ever. Microsoft’s Semantic Kernel (SK) is a robust framework that allows developers to embed AI capabilities, such as natural language processing, into .NET applications. Whether you’re looking to build chatbots, automate workflows, or enhance decision-making processes, Semantic Kernel provides a robust foundation. 

Semantic Kernel is an extensible framework that leverages AI models like OpenAI's GPT to enable natural language understanding and generation within .NET applications. It provides a set of APIs and tools that allow developers to create AI-driven agents capable of processing text, generating content, and meaningfully interacting with users.

At its heart, Semantic Kernel focuses on "plugins" — modular, reusable components that encapsulate specific capabilities such as understanding user intent, summarizing content, or generating responses. These can be combined and orchestrated to build sophisticated AI-driven applications.

Why Semantic Kernel?

LangChain is excellent, and Semantic Kernel is equally fabulous. Choosing one over the other should depend on your style, programming languages, or specific use cases. For example, if you need to integrate Gen AI capabilities into a browser-based solution such as ReactJS/Angular/Vue or vanilla web application, I would use LangChain, as it supports JavaScript.

Are We Only Going to Talk About Sematic Kernel?

No: in this multi-part series, though the primary focus would be on Semantic Kernel, we will still explore use cases of LangChain and use it as a cousin to Semantic Kernel for specific scenarios and use cases.

Enough talk! Let's build something with SK!

Prerequisites

Before diving into the code, ensure you have the following prerequisites:

  1. .NET 7.0 SDK or later: Download it from the .NET website.
  2. Visual Studio 2022: Ensure the ASP.NET Core workload is installed.
  3. Azure AI Model: It is possible to use OpenAI or Other models directly, but for this series, I will stick to AI models that are deployed in Azure as I have enough Azure credits as an MS MVP (P.S.: If you plan to use OpenAI’s models, you’ll need an API key, which you can obtain from the OpenAI website.)

Setting Up Your Project

The first step in integrating Semantic Kernel into your application is to set up the environment. Let’s start with a simple console application and then walk through adding Semantic Kernel to the mix.

1. Create a New Console Project

It's fine if you prefer to create a new console application using Visual Studio or VS Code.

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


2. Add the Semantic Kernel NuGet Package

Add Semantic Kernel NuGet package using the following command:

Shell
 
dotnet add package Microsoft.SemanticKernel


3. Setup Semantic Kernel

Open your Program.cs file and configure the Semantic Kernel service. This service will handle interactions with the AI model. Please take a look at the function AddAzureOpenAIChatCompletion(). As the name suggests, this function helps us integrate Open AI chat completion using the Open AI model hosted in Azure onto our Semantic Kernel Builder. The parameters' values are from my already deployed gtp-4o model on Azure AI Studio. I will write a separate article on deploying AI models using Azure AI Studio and link it here later.

C#
 
var builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatCompletion(
    deploymentName: "<Your_Deployment_Name>",
    endpoint: "<Azure-Deployment-Endpoint-Ends-In:openai.azure.com>",
    apiKey: "<Your_API_Key>"
);
var kernel = builder.Build();


Think of this KernelBuilder as similar to the ASP.NET Core HostBuilder. Before the Build() call, you would need to supply all of your plugin information(more on plugins later), so that SK would be aware of it.

4. Ask the First Question

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


5. Running the Application

With everything configured, you’re ready to run your application. Run the below command in the terminal.

Shell
 
dotnet run


6. We Did It!

All is well. Our Semantic Kernel configuration used the Deployed Azure Open AI model to answer our question. Hooray!

Semantic Kernel configuration used the Deployed Azure Open AI model to answer our question

I know, I know, this isn't much. But I still published the source code on GitHub here. This is the starting point, and we will build from here.

Conclusion

Semantic Kernel is a powerful tool for bringing advanced AI capabilities to your .NET applications. Following the steps outlined in this multi-part series, you can quickly get started with Semantic Kernel and integrate intelligent, context-aware functionalities into your projects. The possibilities are vast, from simple chatbots to complex, AI-driven workflows.

As we dive deeper, remember that the key to effectively leveraging the Semantic Kernel is in how you define and orchestrate your skills. With a solid understanding of these basics, you're well on your way to building the next generation of intelligent applications.

What's Next?

Are we done? No. Now that we know how to add Semantic Kernel in a .NET Application, it is time to take this flight off the ground. We will dig deeper and deeper as we go along with this multi-part series. In "Part 2: Understanding Plugins in Semantic Kernel, A Deep Dive," we will dive deeper into plugins in the semantic kernel. We wouldn't stop there, in the following parts, we will discuss agents, local SLMs and Ollama, Semantic Kernel on ASP.NET Core applications, mixing SK with AutoGen and LangChain, and more.

AI azure .NET C# (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Zero to AI Hero, Part 3: Unleashing the Power of Agents in Semantic Kernel
  • Zero to AI Hero, Part 2: Understanding Plugins in Semantic Kernel, A Deep Dive With Examples
  • Feature Flags in .NET 8 and Azure
  • Azure AI and GPT-4: Real-World Applications and Best Practices

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: