Skip to content

microsoft/semantic-kernel

main
Switch branches/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?
Code

Latest commit

### Motivation and Context
This pull request adds two new skills for the Semantic Kernel project,
using the NCalc library to evaluate mathematical expressions. The
LanguageCalculatorSkill allows users to input natural language math
problems and get the corresponding expression and result, while the
SimpleCalculatorSkill evaluates simple arithmetic expressions. The
skills use semantic functions to generate the expressions and evaluate
them using the NCalc library. The skills also handle errors and edge
cases gracefully.

### Description
- Add a new project NCalcSkills to the samples/dotnet folder, with a
reference to the SemanticKernel project and the CoreCLR-NCalc package
- Add a new class LanguageCalculatorSkill, which implements the ISkill
interface and defines a Calculate function that takes a text input and
returns a numerical output
- The LanguageCalculatorSkill class uses a semantic function called
_mathTranslator, which is initialized with a MathTranslatorPrompt
constant that defines the task of translating a math problem into a
NCalc expression, and some examples of input-output pairs
- The Calculate function uses the _mathTranslator function to generate a
NCalc expression from the text input, and then evaluates the expression
using the NCalc.Evaluate method, which handles parameters and errors
- Add a new class SimpleCalculatorSkill, which also implements the
ISkill interface and defines a Calculate function that takes a simple
arithmetic expression as input and returns a numerical output
- The SimpleCalculatorSkill class uses a semantic function called
_simpleCalculator, which evaluates the input expression using NCalc,
without variables or advanced functions
- Add some examples and documentation to the LanguageCalculatorSkill and
SimpleCalculatorSkill classes, using the SKFunction, SKFunctionName, and
SKFunctionInput attributes
- Add the NCalcSkills project and the LanguageCalculatorSkill and
SimpleCalculatorSkill classes to the SK-dotnet.sln solution file, and
update the project GUIDs and dependencies accordingly

### Related
- A piece taken from work from @kaza in #992 
- In support of resolving #1472

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [ ] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Almir Kazazic <[email protected]>

---------

Co-authored-by: Lee Miller <[email protected]>
74d5f8c

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Semantic Kernel

Python package Nuget package dotnet License: MIT Discord

ℹ️ NOTE:This project is just like AI and 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, joining our Discord community.

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 supports and encapsulates several design patterns from the latest in AI research, such that developers can infuse their applications with plugins like prompt chaining, recursive reasoning, summarization, zero/few-shot learning, contextual memory, long-term memory, embeddings, semantic indexing, planning, retrieval-augmented generation 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.

Get Started with Semantic Kernel

Semantic Kernel is available to explore AI and build apps with C# and Python:


See the Feature Matrix to see a breakdown of feature parity between C# and Python.

The quickest way to get started with the basics is to get an API key (OpenAI or Azure OpenAI) and to run one of the C# or Python console applications/scripts:

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.

Sample apps

The repository includes some sample applications, with a React frontend and a backend web service using Semantic Kernel.

Follow the links for more information and instructions about running these apps.

Simple chat summary Use ready-to-use plugins and get plugins 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.
Copilot Chat Sample App Build your own chat experience based on Semantic Kernel.

Requirements:

Deploy Semantic Kernel to Azure in a web app service ☁️

Getting Semantic Kernel deployed to Azure as web app service is easy with one-click deployments. Click here to learn more on how to deploy to Azure.

Jupyter Notebooks

For a more hands-on overview, you can also check out the C# and Python Jupyter notebooks, starting from here:

Requirements: C# notebooks require .NET 7 and the VS Code Polyglot extension.

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:

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 [email protected] with any additional questions or comments.

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT license.