Giter Site home page Giter Site logo

instantiator / semantic-kernel-experiment Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 913 KB

A simple experimental project with sample code for using the Semantic Kernel and Planner to complete a task by invocation of a text completion LLM. Fully commented.

Home Page: https://instantiator.dev/post/you-too-can-llm/

License: MIT License

C# 100.00%
ai csharp dotnet gpt llm ml openai semantic-kernel text-completion

semantic-kernel-experiment's Introduction

semantic-kernel-experiment

The Semantic Kernel is a .NET SDK that simplifies a number of machine learning tasks.

This solution is fully commented, and illustrates a simple use of the Semantic Kernel:

  • Defines 1 or more skills, each with 1 or more functions
  • Creates a plan from an ask presented to the Kernel
  • Executes that plan, to get to a final result

Configuration

Config is stored in 2 files:

  • SKE/.env - configuration specifying serviceId and modelId
  • SKE/.secret.env - configuration specifying your secret apiKey

You'll need to create SKE/.secret.env file and provide your API key from OpenAI:

apiKey=<your-key-goes-here>

OpenAI vs. Azure OpenAI

NB. The solution is currently set up to use text completion services from OpenAI. Semantic Kernel can also access similar services through Azure OpenAI - you'll need to modify the code a little to do that... It's the difference between this:

kernel.Config.AddOpenAITextCompletionService(serviceId, modelId, apiKey, orgId);

and this:

kernel.Config.AddAzureOpenAITextCompletionService(serviceId, modelId, azureEndpoint, apiKey);

Getting started

  • Place an API key from your OpenAI subscription in .secret.env

  • Run the application:

    dotnet run --project SKE/SKE.csproj

Skills, Functions, and the Planner

You can define any number of semantic functions and native functions, and these are bundled into groups called skills.

Each skill is found in its own directory, and in this solution these are all grouped inside the Skills/ directory.

You can invoke functions directly through the Kernel, or use the Planner - a special skill that can determine which functions to use to fulfil an ask you make of it.

KernelSkillsExtensions.cs provides a number of helpful utility methods for importing skills, importing the planner, and then using it to create a plan and execute it.

Creating skills

To add a new semantic function, create the directory structure for it: Skills/<skill-name>/<function-name>

Then, add the skprompt.txt prompt file, and (optionally) a config.json file for the function itself:

  • Skills/<skill-name>/<function-name>/skprompt.txt
  • Skills/<skill-name>/<function-name>/config.json

NB. Ensure that your skprompt.txt and config.json files are copied alongside the compiled binary by setting their "copy to output directory" property.

To add native functions, create the skill directory, and then a C# class file inside that skill directory. Provide each method that you wish to import as a native function with the SKFunction attribute, and provide a description of the function as its parameter, eg.

public class CharacterManipulationSkill
{
    [SKFunction("Return the text in all uppercase (aka capitals)")]
    public string Uppercase(string input)
        => input.ToUpper();
}

NB. A skill can contain any combination of native or semantic functions.

The code in KernelSkillsExtensions.ImportAllSemanticSkills and KernelSkillsExtensions.ImportAllNativeSkills will locate and import all skills defined in the solution.

Microsoft.SemanticKernel NuGet package

NB. The Microsoft.SemanticKernel package is in preview right now, so you'll need to enable 'include prereleases' in your package selector to see it.

The NuGet package selector - it's showing the Microsoft.SemanticKernel package, and at the bottom of the window, the 'include prereleases' option is selected.

See also

semantic-kernel-experiment's People

Contributors

instantiator avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.