Skip to main content

No project description provided

Project description

Get Started with Semantic Kernel ⚡

Install the latest package:

python -m pip install --upgrade semantic-kernel

AI backends

OpenAI / Azure OpenAI API keys

Make sure you have an Open AI API Key or Azure Open AI service key

Copy those keys into a .env file (see the .env.example file):

OPENAI_API_KEY=""
OPENAI_ORG_ID=""
AZURE_OPENAI_DEPLOYMENT_NAME=""
AZURE_OPENAI_ENDPOINT=""
AZURE_OPENAI_API_KEY=""

Running a prompt

import semantic_kernel as sk
from semantic_kernel.ai.open_ai import OpenAITextCompletion, AzureTextCompletion

kernel = sk.Kernel()

# Prepare OpenAI backend using credentials stored in the `.env` file
api_key, org_id = sk.openai_settings_from_dot_env()
kernel.config.add_text_backend("dv", OpenAITextCompletion("text-davinci-003", api_key, org_id))

# Alternative using Azure:
# deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()
# kernel.config.add_text_backend("dv", AzureTextCompletion(deployment, endpoint, api_key))

# Wrap your prompt in a function
prompt = kernel.create_semantic_function("""
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.

Give me the TLDR in exactly 5 words.""")

# Run your prompt
print(prompt()) # => Robots must not harm humans.

Prompts are semantic functions with input parameters

# Create a reusable function with one input parameter
summarize = kernel.create_semantic_function("{{$input}}\n\nOne line TLDR with the fewest words.")

# Summarize the laws of thermodynamics
print(summarize("""
1st Law of Thermodynamics - Energy cannot be created or destroyed.
2nd Law of Thermodynamics - For a spontaneous process, the entropy of the universe increases.
3rd Law of Thermodynamics - A perfect crystal at zero Kelvin has zero entropy."""))

# Summarize the laws of motion
print(summarize("""
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.
2. The acceleration of an object depends on the mass of the object and the amount of force applied.
3. Whenever one object exerts a force on another object, the second object exerts an equal and opposite on the first."""))

# Summarize the law of universal gravitation
print(summarize("""
Every point mass attracts every single other point mass by a force acting along the line intersecting both points.
The force is proportional to the product of the two masses and inversely proportional to the square of the distance between them."""))

# Output:
# > Energy conserved, entropy increases, zero entropy at 0K.
# > Objects move in response to forces.
# > Gravitational force between two point masses is inversely proportional to the square of the distance between them.

Semantic Kernel Notebooks

The repository contains a few Python and C# notebooks that demonstrates how to get started with the Semantic Kernel.

Python notebooks:

Frequently asked questions

  • How does Python SK compare to the C# version of Semantic Kernel?

    The two SDKs are compatible and at the core they follow the same design principles. Some features are still available only in the C# version, and being ported Refer to the FEATURE PARITY doc to see where things stand in matching the features and functionality of the main SK branch. Over time there will be some features available only in the Python version, and others only in the C# version, for example adapters to external services, scientific libraries, etc.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semantic_kernel-0.2.3.dev0.tar.gz (41.3 kB view details)

Uploaded Source

Built Distribution

semantic_kernel-0.2.3.dev0-py3-none-any.whl (76.7 kB view details)

Uploaded Python 3

File details

Details for the file semantic_kernel-0.2.3.dev0.tar.gz.

File metadata

  • Download URL: semantic_kernel-0.2.3.dev0.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.5

File hashes

Hashes for semantic_kernel-0.2.3.dev0.tar.gz
Algorithm Hash digest
SHA256 2924dc6903816d42ff13df3118e4ce8c51b70e2ba07b65881e83fcb4a737ca30
MD5 5b32d4d41ea61bcb2906c63d9df2036f
BLAKE2b-256 b4debd80eab274c73572912471dfb578b21410fedf3cbacc3686e429e4d5dc09

See more details on using hashes here.

File details

Details for the file semantic_kernel-0.2.3.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for semantic_kernel-0.2.3.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ba84f1e8082686c51ccbedfbd6542f0bdd439b2db8ac6c521ca47482bda2a88
MD5 27aaa20616771678be6f49914acc5a7f
BLAKE2b-256 3b825398a14a37af53e10e885dfc6e345dfff2401b7c3708c1c4a42ace6d8814

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page