ℹ️ NOTE: This project is in early alpha and, just like AI, will evolve quickly. We invite you to join us in developing the Semantic Kernel together! Please contribute by using GitHub Discussions, opening GitHub Issues, sending us PRs.
Semantic Kernel (SK) is a lightweight SDK enabling integration of AI Large Language Models (LLMs) with conventional programming languages. The SK extensible programming model combines natural language semantic functions, traditional code native functions, and embeddings-based memory unlocking new potential and adding value to applications with AI.
SK supports prompt templating, function chaining, vectorized memory, and intelligent planning capabilities out of the box.
Semantic Kernel is designed to support and encapsulate several design patterns from the latest in AI research, such that developers can infuse their applications with complex skills like prompt chaining, recursive reasoning, summarization, zero/few-shot learning, contextual memory, long-term memory, embeddings, semantic indexing, planning, and accessing external knowledge stores as well as your own data.
By joining the SK community, you can build AI-first apps faster and have a front-row peek at how the SDK is being built. SK has been released as open-source so that more pioneering developers can join us in crafting the future of this landmark moment in the history of computing.
If you would like a quick overview about how Semantic Kernel can integrate with your app, start by cloning the repository:
git clone https://github.com/microsoft/semantic-kernel.git
and try these examples:
Simple chat summary | Use ready-to-use skills and get those skills into your app easily. |
Book creator | Use planner to deconstruct a complex goal and envision using the planner in your app. |
Authentication and APIs | Use a basic connector pattern to authenticate and connect to an API and imagine integrating external data into your app's LLM AI. |
For a more hands-on overview, you can also run the Getting Started notebook, looking into the syntax, creating Semantic Functions, working with Memory, and see how the kernel works.
Please note:
- You will need an Open AI API Key or Azure Open AI service key to get started.
- There are a few software requirements you may need to satisfy before running examples and notebooks:
- Azure Functions Core Tools used for running the kernel as a local API, required by the web apps.
- Yarn used for installing web apps' dependencies.
- Semantic Kernel supports .NET Standard 2.1 and it's recommended using .NET 6+. However, some of the examples in the repository require .NET 7 and the VS Code Polyglot extension to run the notebooks.
Here is a quick example of how to use Semantic Kernel from a C# console app.
-
Create a new project, targeting .NET 6 or newer, and add the
Microsoft.SemanticKernel
nuget package:dotnet add package Microsoft.SemanticKernel --prerelease
See nuget.org for the latest version and more instructions.
-
Copy and paste the following code into your project, with your Azure OpenAI key in hand (you can create one here).
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.KernelExtensions;
var kernel = Kernel.Builder.Build();
// For Azure Open AI service endpoint and keys please see
// https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=rest-api
kernel.Config.AddAzureOpenAICompletionBackend(
"davinci-backend", // Alias used by the kernel
"text-davinci-003", // Azure OpenAI *Deployment ID*
"https://contoso.openai.azure.com/", // Azure OpenAI *Endpoint*
"...your Azure OpenAI Key..." // Azure OpenAI *Key*
);
string skPrompt = @"
{{$input}}
Give me the TLDR in 5 words.
";
string textToSummarize = @"
1) A robot may not injure a human being or, through inaction,
allow a human being to come to harm.
2) A robot must obey orders given it by human beings except where
such orders would conflict with the First Law.
3) A robot must protect its own existence as long as such protection
does not conflict with the First or Second Law.
";
var tldrFunction = kernel.CreateSemanticFunction(skPrompt);
var summary = await kernel.RunAsync(textToSummarize, tldrFunction);
Console.WriteLine(summary);
// Output => Protect humans, follow orders, survive.
We welcome your contributions and suggestions to SK community! One of the easiest ways to participate is to engage in discussions in the GitHub repository. Bug reports and fixes are welcome!
For new features, components, or extensions, please open an issue and discuss with us before sending a PR. This is to avoid rejection as we might be taking the core in a different direction, but also to consider the impact on the larger ecosystem.
To learn more and get started:
- Read the documentation
- Learn how to contribute to the project
- Join the Discord community
- Follow the team on our blog
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT license.