sparksun / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps

Home Page:https://aka.ms/semantic-kernel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Semantic Kernel

Nuget package License: MIT dotnet Discord

ℹ️ 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.

image

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.

Samples ⚡

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.
Github repository Q&A Use embeddings and memory to store recent data and allow you to query against it.

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:
    1. Azure Functions Core Tools used for running the kernel as a local API, required by the web apps.
    2. Yarn used for installing web apps' dependencies.
    3. 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.

Get Started with Semantic Kernel ⚡

Here is a quick example of how to use Semantic Kernel from a C# console app.

  1. 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.

  2. Copy and paste the following code into your project, with your Azure OpenAI key in hand (you can create one here).

using Microsoft.SemanticKernel;

var kernel = Kernel.Builder.Build();

// For Azure Open AI details please see
// https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=rest-api
kernel.Config.AddAzureOpenAITextCompletionService(
    "davinci-azure",                     // 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 summarizePrompt = @"
{{$input}}

Give me the a TLDR in 5 words.";

string haikuPrompt = @"
{{$input}}

Write a futuristic haiku about it.";

var summarize = kernel.CreateSemanticFunction(summarizePrompt);
var haikuWriter = kernel.CreateSemanticFunction(haikuPrompt);

string inputText = @"
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 output = await kernel.RunAsync(inputText, summarize, haikuWriter);

Console.WriteLine(output);

// Output => Robots protect us all
//           No harm to humans they bring
//           Peaceful coexistence

Contributing and Community

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:

Python developers: Semantic Kernel is coming to Python soon! Check out the work-in-progress and contribute in the python-preview branch.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT license.

About

Integrate cutting-edge LLM technology quickly and easily into your apps

https://aka.ms/semantic-kernel

License:MIT License


Languages

Language:C# 100.0%Language:Shell 0.0%Language:Batchfile 0.0%