https://github.com/microsoft/semantic-kernel Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} microsoft / semantic-kernel Public * Notifications * Fork 2.2k * Star 14.9k Integrate cutting-edge LLM technology quickly and easily into your apps aka.ms/semantic-kernel License MIT license 14.9k stars 2.2k forks Activity Star Notifications * Code * Issues 340 * Pull requests 85 * Discussions * Actions * Projects 4 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Discussions * Actions * Projects * Security * Insights microsoft/semantic-kernel This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 64 branches 199 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/m] Use Git or checkout with SVN using the web URL. [gh repo clone micros] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @stephentoub @SergeyMenshykh stephentoub and SergeyMenshykh .Net: Replace SK's IAIServiceProvider with IServiceProvider (#3714) ... 73afd47 Nov 28, 2023 .Net: Replace SK's IAIServiceProvider with IServiceProvider (#3714) Closes #3694 Closes #3693 Closes #3659 Closes #3571 Closes #3191 Closes #2463 (This replaces #3676, including that as a first commit. That resiliency functionality is no longer necessary after this change, as developers can simply use libraries like Microsoft.Extensions.Http.Resilience to achieve the desired support.) SK has had a custom IAIServiceProvider interface that's represented a provider of AI related services. Kernel has then wrapped one of these, but also wrapped other individual non-AI services, like ILoggerFactory and HttpClient. This leads to a variety of problems, such as it being more complicated to construct a Kernel instance, it not integrating as nicely with a broader dependency injection system, and not being as future proof because there isn't a good way to flow additional non-AI-related services through the Kernel to anywhere that might want access. On the DI front, it's also more difficult to integrate because all of the KernelBuilder extension methods are specific to KernelBuilder, and even though they're creating services, the helpers aren't usable with IServiceCollection and thus with the rest of the DI system; a developer needs to go directly to the underlying types and register those directly. There are also a handful of features that are of little value and in some cases exposed but not actually implemented, such as setAsDefault and alsoAsTextCompletion. And other cases where there's something valuable but missing, such as the ability to create certain kinds of Azure-related service instances with an existing OpenAIClient. This PR attempts to address all of these issues and set up SK to evolve more easily: - Kernel now wraps an IServiceProvider, and all services (AI and non-AI) are retrieved from it. This has a variety of benefits, including future-proofing for wanting to flow more state around, better integration with other systems (e.g. Microsoft.Extensions.DependencyInjection), simpler construction, etc. - KernelBuilder still has dedicated WithXx methods for first-class features, but they're all layered on top of a new ConfigureServices method, which lets you add anything to an IServiceCollection. Because everything is based on IServiceCollection/IServiceProvider, dependencies are automatically satisfied from the container. For example, for services that accept an optional HttpClient, if one isn't specified to the WithXx method, the system will pull one out of the DI container if it can, which means all existing support for adding configured HttpClient instances to an IServiceCollection immediately apply to Kernel{Builder} as well. - KernelBuilder also exposes a ConfigurePlugins method, largely for parity with ConfigureServices, as fundmantally a Kernel is just the combination of a collection of services and a collection of plugins (plus some additional transient data, event handlers, etc.) This also integrates with IServiceProvider, with one passed into the callback, so that if the plugin itself needs access to something like logging, it can simply get it from the container. These ConfigureServices and ConfigurePlugins methods can be called any number of times. - KernelBuilder is now just a simplified, opinionated way to achieve something you can achieve in two other ways: construct the Kernel directly, or construct the Kernel via DI. For the latter, you can simply add Kernel as a DI resource, and it'll automatically be composed out of what's available. For example, if in ASP.NET you AddAzureOpenChatCompletion, AddLogging, AddHttp, etc., and then ask for a Kernel to be injected, that Kernel will be constructed from the IServiceProvider that contains all of those other resources, and thus anyone using the Kernel will get that logger, will get that HttpClient, etc.; the HttpClient will also be used by the Azure OpenAI chat completion. @matthewbolanos, @markwallace-microsoft, @SergeyMenshykh, please review from an SK perspective to let me know if you agree with the direction, whether there are specific things you'd like to see changed, etc. There are some straggling things we should still do after this (like add a few more extension methods for adding plugins to a plugin collection, adding more tests, revamping XML comments, cleaning up more code, etc.), but this is a sweeping change and I wanted to get it in. @eerhardt, @halter73, I'd appreciate it if you could review this from a DI perspective, e.g. are there variations in the patterns I should be following, any best-practices I'm violating, whether I'm using singleton when I should be using transient, etc. etc. Note that I ran into one issue as part of this: the Microsoft.Extensions.DependencyInjection support for keyed services doesn't let you enumerate all services for a particular T, regardless of key. That's something SK depends on. To workaround that, KernelBuilder tracks all of the type/keys and injects a dictionary as a service with that information; then places the Kernel needs it, it can query for that dictionary and use it. This means that a Kernel constructed with KernelBuilder will fully support keys, whereas a Kernel constructed with DI or directly won't work as nicely with named services. My hope is that M.E.DI can fix this asap (offline conversation) in a way that will allow SK to upgrade to a patched version, delete its hack, and have those broader scenarios "just work". In the meantime, though, KernelBuilder behaves as desired. I also stopped short of adding Add{Azure}OpenAIXx methods that resolve the OpenAIClient from the service provider. That'll be an important thing to do once there's an Aspire component for Azure.AI.OpenAI, but in the meantime, I didn't want there to be an attractive Add{Azure}OpenAIXx method that looked like you didn't need to supply the necessary information even though you do. --------- Co-authored-by: SergeyMenshykh 73afd47 Git stats * 1,681 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .devcontainer Add .NET 7.0 SDK feature to devcontainer configuration (#1424) June 14, 2023 00:56 .github .Net: Temporarily excluding planners and flow orchestrator (#3701) November 27, 2023 14:19 .vscode .Net: Deleting all deprecated samples. (#3260) November 7, 2023 18:09 docs ADR for JSON-serializable custom types (#3394) November 27, 2023 22:08 dotnet .Net: Replace SK's IAIServiceProvider with IServiceProvider (#3714) November 28, 2023 20:59 java Java: Fixed invalid links in documentation (#3397) November 6, 2023 21:22 python Python: extended notebook 06 to showcase Azure AI Search for semantic... November 27, 2023 17:18 samples .Net: Refactor PromptTemplateConfig (#3707) November 27, 2023 22:41 .editorconfig .Net: Some code enhancements (#2988) September 27, 2023 09:29 .gitattributes .Net: Fix build batch to align with Bash script (#2813) September 15, 2023 11:49 .gitignore Adds Intellij IDEA files to .gitignore (#3389) November 11, 2023 15:26 CODE_OF_CONDUCT.md First commit, let the journey begin! February 24, 2023 16:38 COMMUNITY.md Update COMMUNITY.md (#2680) September 1, 2023 22:13 CONTRIBUTING.md Update CONTRIBUTING.md (#2503) September 4, 2023 19:55 FEATURE_MATRIX.md Create pointers to learn.microsoft.com (#2159) July 25, 2023 22:41 LICENSE First commit, let the journey begin! February 24, 2023 16:38 README.md DOC ONLY: Added a contributor wall of fame to the README (#3381) November 17, 2023 10:16 SECURITY.md First commit, let the journey begin! February 24, 2023 16:38 View code [ ] Semantic Kernel Please star the repo to show your support for this project! Getting started with Semantic Kernel For C#: For Python: For Java: Learning how to use Semantic Kernel Chat Copilot: see what's possible with Semantic Kernel Visual Studio Code extension: design semantic functions with ease Check out our other repos! Join the community Contributor Wall of Fame Code of Conduct License README.md Semantic Kernel Python package Nuget package dotnet Docker dotnet Windows License: MIT Discord Semantic Kernel is an SDK that integrates Large Language Models (LLMs) like OpenAI, Azure OpenAI, and Hugging Face with conventional programming languages like C#, Python, and Java. Semantic Kernel achieves this by allowing you to define plugins that can be chained together in just a few lines of code. What makes Semantic Kernel special, however, is its ability to automatically orchestrate plugins with AI. With Semantic Kernel planners, you can ask an LLM to generate a plan that achieves a user's unique goal. Afterwards, Semantic Kernel will execute the plan for the user. Please star the repo to show your support for this project! Orchestrating plugins with planner Getting started with Semantic Kernel The Semantic Kernel SDK is available in C#, Python, and Java. To get started, choose your preferred language below. See the Feature Matrix to see a breakdown of feature parity between our currently supported languages. [230673] [python] Java logo Using Semantic Kernel Using Semantic Kernel Using Semantic Kernel in C# in Python in Java The quickest way to get started with the basics is to get an API key from either OpenAI or Azure OpenAI and to run one of the C#, Python, and Java console applications/scripts below. For C#: 1. Create a new console app. 2. Add the semantic kernel nuget Microsoft.SemanticKernel. 3. Copy the code from here into the app Program.cs file. 4. Replace the configuration placeholders for API key and other params with your key and settings. 5. Run with F5 or dotnet run For Python: 1. Install the pip package: python -m pip install semantic-kernel. 2. Create a new script e.g. hello-world.py. 3. Store your API key and settings in an .env file as described here . 4. Copy the code from here into the hello-world.py script. 5. Run the python script. For Java: 1. Clone the repository: git clone https://github.com/microsoft/ semantic-kernel.git 1. To access the latest Java code, clone and checkout the Java development branch: git clone -b java-development https:// github.com/microsoft/semantic-kernel.git 2. Follow the instructions here Learning how to use Semantic Kernel The fastest way to learn how to use Semantic Kernel is with our C# and Python Jupyter notebooks. These notebooks demonstrate how to use Semantic Kernel with code snippets that you can run with a push of a button. * Getting Started with C# notebook * Getting Started with Python notebook Once you've finished the getting started notebooks, you can then check out the main walkthroughs on our Learn site. Each sample comes with a completed C# and Python project that you can run locally. 1. Overview of the kernel 2. Understanding AI plugins 3. Creating semantic functions 4. Creating native functions 5. [?][?] Chaining functions together 6. Auto create plans with planner 7. Create and run a ChatGPT plugin Finally, refer to our API references for more details on the C# and Python APIs: * C# API reference * Python API reference (coming soon) Chat Copilot: see what's possible with Semantic Kernel If you're interested in seeing a full end-to-end example of how to use Semantic Kernel, check out our Chat Copilot reference application. Chat Copilot is a chatbot that demonstrates the power of Semantic Kernel. By combining plugins, planners, and personas, we demonstrate how you can build a chatbot that can maintain long-running conversations with users while also leveraging plugins to integrate with other services. Chat Copilot answering a question You can run the app yourself by downloading it from its GitHub repo. Visual Studio Code extension: design semantic functions with ease The Semantic Kernel extension for Visual Studio Code makes it easy to design and test semantic functions. The extension provides an interface for designing semantic functions and allows you to test them with a push of a button with your existing models and data. Semantic Kernel extension for Visual Studio Code In the above screenshot, you can see the extension in action: * Syntax highlighting for semantic functions * Code completion for semantic functions * LLM model picker * Run button to test the semantic function with your input data Check out our other repos! If you like Semantic Kernel, you may also be interested in other repos the Semantic Kernel team supports: Repo Description Chat Copilot A reference application that demonstrates how to build a chatbot with Semantic Kernel. Semantic Kernel The home for Semantic Kernel documentation that Docs appears on the Microsoft learn site. Semantic Kernel Starter projects for Semantic Kernel to make it Starters easier to get started. Kernel Memory A scalable Memory service to store information and ask questions using the RAG pattern. Join the 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: * Read the documentation * Learn how to contribute to the project * Join the Discord community * Attend regular office hours and SK community events * Follow the team on our blog Contributor Wall of Fame semantic-kernel contributors 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 aka.ms/semantic-kernel Topics sdk ai artificial-intelligence openai llm Resources Readme License MIT license Code of conduct Code of conduct Security policy Security policy Activity Stars 14.9k stars Watchers 201 watching Forks 2.2k forks Report repository Releases 52 python-0.3.15.dev Latest Nov 19, 2023 + 51 releases Packages 39 + 36 packages Contributors 194 * @shawncal * @dependabot[bot] * @dmytrostruk * @lemillermicrosoft * @dluc * @markwallace-microsoft * @adrianwyatt * @awharrison-28 * @stephentoub * @SergeyMenshykh * @RogerBarreto + 183 contributors Languages * C# 57.3% * Java 19.7% * Python 17.9% * Jupyter Notebook 5.0% * Handlebars 0.1% * Makefile 0.0% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact You can't perform that action at this time.