Skip to content

Commit 5fc05b2

Browse files
committed
* Update notebooks to use pip package
* Add python getting started notebook * Fix notebooks usage of Azure text completion * Fix bug with skills definition * Update READMEs * New release version 0.2.2
1 parent a11ab63 commit 5fc05b2

17 files changed

Lines changed: 386 additions & 137 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,6 @@ env/
456456
venv/
457457
myvenv/
458458
ENV/
459+
460+
# Python dist
461+
dist/

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ DO's:
4545

4646
- **DO** follow the standard
4747
[.NET coding style](https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
48+
and [Python code style](https://pypi.org/project/black/)
4849
- **DO** give priority to the current style of the project or file you're changing
4950
if it diverges from the general guidelines.
5051
- **DO** include tests when adding new features. When fixing bugs, start with

README.md

Lines changed: 46 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# Semantic Kernel
22

3+
[![Python package](https://img.shields.io/pypi/v/semantic-kernel)](https://pypi.org/project/semantic-kernel/)
34
[![Nuget package](https://img.shields.io/nuget/vpre/Microsoft.SemanticKernel)](https://www.nuget.org/packages/Microsoft.SemanticKernel/)
4-
[![License: MIT](https://img.shields.io/github/license/microsoft/semantic-kernel)](https://github.com/microsoft/semantic-kernel/blob/main/LICENSE)
55
[![dotnet](https://github.com/microsoft/semantic-kernel/actions/workflows/dotnet-ci.yml/badge.svg?branch=main)](https://github.com/microsoft/semantic-kernel/actions/workflows/dotnet-ci.yml)
6+
[![License: MIT](https://img.shields.io/github/license/microsoft/semantic-kernel)](https://github.com/microsoft/semantic-kernel/blob/main/LICENSE)
67
[![Discord](https://img.shields.io/discord/1063152441819942922)](https://aka.ms/SKDiscord)
78

89
> ℹ️ **NOTE**: This project is in early alpha and, just like AI, will evolve quickly.
910
> We invite you to join us in developing the Semantic Kernel together!
1011
> Please contribute by
1112
> using GitHub [Discussions](https://github.com/microsoft/semantic-kernel/discussions),
1213
> opening GitHub [Issues](https://github.com/microsoft/semantic-kernel/issues/new/choose),
13-
> sending us [PRs](https://github.com/microsoft/semantic-kernel/pulls).
14+
> sending us [PRs](https://github.com/microsoft/semantic-kernel/pulls),
15+
> joining our [Discord community](https://aka.ms/SKDiscord).
1416
1517
**Semantic Kernel (SK)** is a lightweight SDK enabling integration of AI Large
1618
Language Models (LLMs) with conventional programming languages. The SK extensible
@@ -39,31 +41,54 @@ peek at how the SDK is being built. SK has been released as open-source so that
3941
pioneering developers can join us in crafting the future of this landmark moment
4042
in the history of computing.
4143

42-
## Samples ⚡
44+
## Get Started with Semantic Kernel ⚡
45+
46+
Semantic Kernel is available to explore AI and build apps with C# and Python:
47+
48+
<div style="display:flex;height:30px;padding:5px 0 5px 10px;">
49+
<img src="https://user-images.githubusercontent.com/371009/230673036-fad1e8e6-5d48-49b1-a9c1-6f9834e0d165.png" style="margin-right:12px" height="30"/>
50+
<a href="dotnet/README.md">Using Semantic Kernel in C#</a>.
51+
</div>
52+
53+
<div style="display:flex;height:30px;padding:5px 0 5px 10px;">
54+
<img src="https://user-images.githubusercontent.com/371009/230673733-7a447d30-b48e-46e1-bd84-2b321c90649e.png" style="margin-right:12px" height="30"/>
55+
<a href="python/README.md">Using Semantic Kernel in Python</a>.
56+
</div>
57+
58+
The quickest way to get started with the basics is to get an API key
59+
(OpenAI or Azure OpenAI)
60+
and to run one of the C# or Python console applications/scripts:
61+
62+
For C#:
63+
1. Create a new console app.
64+
2. Add the semantic kernel nuget `Microsoft.SemanticKernel`.
65+
3. Copy the code from [here](dotnet/README.md) into the app `Program.cs` file.
66+
4. Replace the configuration placeholders for API key and other params with your key and settings.
67+
5. Run with `F5` or `dotnet run`
4368

44-
If you would like a quick overview about how Semantic Kernel can integrate with your
45-
app, start by cloning the repository:
69+
For Python:
70+
1. Install the pip package: `python -m pip install semantic-kernel`.
71+
2. Create a new script e.g. `hello-world.py`.
72+
3. Store your API key and settings in an `.env` file as described [here](python/README.md).
73+
4. Copy the code from [here](python/README.md) into the `hello-world.py` script.
74+
5. Run the python script.
4675

47-
```shell
48-
git clone https://github.com/microsoft/semantic-kernel.git
49-
```
5076

51-
and try these examples:
77+
## Samples apps ⚡
78+
79+
The repository includes some sample applications, with a React frontend and
80+
a backend web service using Semantic Kernel.
81+
82+
Follow the links for more information and instructions about running these apps.
5283

5384
| | |
5485
| ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
5586
| [Simple chat summary](samples/apps/chat-summary-webapp-react/README.md) | Use ready-to-use skills and get those skills into your app easily. |
5687
| [Book creator](samples/apps/book-creator-webapp-react/README.md) | Use planner to deconstruct a complex goal and envision using the planner in your app. |
5788
| [Authentication and APIs](samples/apps/auth-api-webapp-react/README.md) | Use a basic connector pattern to authenticate and connect to an API and imagine integrating external data into your app's LLM AI. |
58-
| [Github repository Q&A](samples/apps/github-qna-webapp-react/README.md) | Use embeddings and memory to store recent data and allow you to query against it. |
89+
| [GitHub repository Q&A](samples/apps/github-qna-webapp-react/README.md) | Use embeddings and memory to store recent data and allow you to query against it. |
5990
| [Copilot Chat Sample App](samples/apps/copilot-chat-app/README.md) | Build your own chat experience based on Semantic Kernel. |
6091

61-
For a more hands-on overview, you can also run the
62-
[Getting Started notebook](samples/notebooks/dotnet/Getting-Started-Notebook.ipynb),
63-
looking into the syntax, creating
64-
[Semantic Functions](docs/GLOSSARY.md),
65-
working with Memory, and see how the kernel works.
66-
6792
**Please note:**
6893

6994
- You will need an
@@ -80,59 +105,12 @@ working with Memory, and see how the kernel works.
80105
[Polyglot extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode)
81106
to run the notebooks.
82107

83-
## Get Started with Semantic Kernel ⚡
84-
85-
Here is a quick example of how to use Semantic Kernel from a C# console app.
86-
87-
1. Create a new project, targeting .NET 6 or newer, and add the
88-
`Microsoft.SemanticKernel` nuget package:
89-
90-
dotnet add package Microsoft.SemanticKernel --prerelease
108+
## Notebooks ⚡
91109

92-
See [nuget.org](https://www.nuget.org/packages/Microsoft.SemanticKernel/) for
93-
the latest version and more instructions.
94-
95-
2. Copy and paste the following code into your project, with your Azure OpenAI
96-
key in hand (you can create one
97-
[here](https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=rest-api)).
98-
99-
```csharp
100-
using Microsoft.SemanticKernel;
101-
102-
var kernel = Kernel.Builder.Build();
103-
104-
// For Azure Open AI details please see
105-
// https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=rest-api
106-
kernel.Config.AddAzureOpenAITextCompletionService(
107-
"davinci-azure", // Alias used by the kernel
108-
"text-davinci-003", // Azure OpenAI *Deployment ID*
109-
"https://contoso.openai.azure.com/", // Azure OpenAI *Endpoint*
110-
"...your Azure OpenAI Key..." // Azure OpenAI *Key*
111-
);
112-
113-
string summarizePrompt = @"{{$input}}
114-
115-
Give me a TLDR with the fewest words.";
116-
117-
string jokePrompt = @"{{$input}}
118-
119-
Write a G rated joke about it, only two lines, with rhyme.";
120-
121-
var summarize = kernel.CreateSemanticFunction(summarizePrompt);
122-
var joker = kernel.CreateSemanticFunction(jokePrompt);
123-
124-
string inputText = @"
125-
1st Law of Thermodynamics - Energy cannot be created or destroyed.
126-
2nd Law of Thermodynamics - For a spontaneous process, the entropy of the universe increases.
127-
3rd Law of Thermodynamics - A perfect crystal at zero Kelvin has zero entropy.";
128-
129-
var output = await kernel.RunAsync(inputText, summarize, joker);
130-
131-
Console.WriteLine(output);
132-
133-
// Output => Entropy is a funny thing,
134-
// It's always increasing, no matter what we bring!
135-
```
110+
For a more hands-on overview, you can also check out the Jupyter C# and Python notebooks, starting
111+
from here:
112+
* [Getting Started with C# notebook](samples/notebooks/dotnet/Getting-Started-Notebook.ipynb)
113+
* [Getting Started with Python notebook](samples/notebooks/python/00-getting-started-notebook.ipynb)
136114

137115
## Contributing and Community
138116

@@ -151,10 +129,6 @@ To learn more and get started:
151129
- Join the [Discord community](https://aka.ms/SKDiscord)
152130
- Follow the team on our [blog](https://aka.ms/sk/blog)
153131

154-
<img src="https://user-images.githubusercontent.com/36091529/225807182-22ad65e9-82c6-4727-bb77-d1c256736045.png" align="left" width="40px"/>
155-
<b>Python developers:</b> Semantic Kernel is coming to Python soon! Check out the work-in-progress and contribute in the <a href="https://github.com/microsoft/semantic-kernel/tree/python-preview"><b>python-preview</b></a> branch.
156-
<br clear="left"/>
157-
158132
## Code of Conduct
159133

160134
This project has adopted the

dotnet/README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Get Started with Semantic Kernel ⚡
2+
3+
## OpenAI / Azure OpenAI API keys
4+
5+
Make sure you have an
6+
[Open AI API Key](https://openai.com/api/) or
7+
[Azure Open AI service key](https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=rest-api)
8+
9+
## Nuget package
10+
11+
Here is a quick example of how to use Semantic Kernel from a C# console app.
12+
First, let's create a new project, targeting .NET 6 or newer, and add the
13+
`Microsoft.SemanticKernel` nuget package:
14+
15+
dotnet add package Microsoft.SemanticKernel --prerelease
16+
17+
# Running prompts with input parameters
18+
19+
Copy and paste the following code into your project, with your Azure OpenAI key in hand:
20+
21+
```csharp
22+
using Microsoft.SemanticKernel;
23+
24+
var kernel = Kernel.Builder.Build();
25+
26+
// Azure OpenAI
27+
kernel.Config.AddAzureOpenAITextCompletionService(
28+
"davinci-azure", // Alias used by the kernel
29+
"text-davinci-003", // Azure OpenAI Deployment Name
30+
"https://contoso.openai.azure.com/", // Azure OpenAI Endpoint
31+
"...your Azure OpenAI Key..." // Azure OpenAI Key
32+
);
33+
34+
// Alternative using OpenAI
35+
// kernel.Config.AddOpenAITextCompletionService("davinci-openai",
36+
// "text-davinci-003", // OpenAI Model name
37+
// "...your OpenAI API Key..." // OpenAI API Key
38+
// );
39+
40+
var prompt = @"{{$input}}
41+
42+
One line TLDR with the fewest words.";
43+
44+
var summarize = kernel.CreateSemanticFunction(prompt);
45+
46+
string text1 = @"
47+
1st Law of Thermodynamics - Energy cannot be created or destroyed.
48+
2nd Law of Thermodynamics - For a spontaneous process, the entropy of the universe increases.
49+
3rd Law of Thermodynamics - A perfect crystal at zero Kelvin has zero entropy.";
50+
51+
string text2 = @"
52+
1. An object at rest remains at rest, and an object in motion remains in motion at constant speed and in a straight line unless acted on by an unbalanced force.
53+
2. The acceleration of an object depends on the mass of the object and the amount of force applied.
54+
3. Whenever one object exerts a force on another object, the second object exerts an equal and opposite on the first.";
55+
56+
Console.WriteLine(await summarize.InvokeAsync(text1));
57+
58+
Console.WriteLine(await summarize.InvokeAsync(text2));
59+
60+
// Output:
61+
// Energy conserved, entropy increases, zero entropy at 0K.
62+
// Objects move in response to forces.
63+
```
64+
65+
# Prompt chaining
66+
67+
The previous code shows how to invoke individual semantic functions, but you can
68+
also chain functions (aka prompt chaining) to process the initial input with multiple
69+
operations.
70+
71+
The following code for example, translates an initial text to math symbols and
72+
then generates a summary:
73+
74+
```csharp
75+
string translationPrompt = @"{{$input}}
76+
77+
Translate the text to math.";
78+
79+
string summarizePrompt = @"{{$input}}
80+
81+
Give me a TLDR with the fewest words.";
82+
83+
var translator = kernel.CreateSemanticFunction(translationPrompt);
84+
var summarize = kernel.CreateSemanticFunction(summarizePrompt);
85+
86+
string inputText = @"
87+
1st Law of Thermodynamics - Energy cannot be created or destroyed.
88+
2nd Law of Thermodynamics - For a spontaneous process, the entropy of the universe increases.
89+
3rd Law of Thermodynamics - A perfect crystal at zero Kelvin has zero entropy.";
90+
91+
// Run two prompts in sequence (prompt chaining)
92+
var output = await kernel.RunAsync(inputText, translator, summarize);
93+
94+
Console.WriteLine(output);
95+
96+
// Output: ΔE = 0, ΔSuniv > 0, S = 0 at 0K.
97+
```
98+
99+
# Semantic Kernel Notebooks
100+
101+
The repository contains also a few C# Jupyter notebooks that demonstrates
102+
how to get started with the Semantic Kernel.
103+
104+
See [here](../samples/notebooks/dotnet/README.md) for the full list with setup
105+
instructions.

python/.conf/flake8.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
2-
max-line-length = 88
2+
max-line-length = 120
33
extend-ignore = E203

0 commit comments

Comments
 (0)