Files
semantic-kernel/samples/notebooks/python/00-getting-started.ipynb
T
Shukri eea509e235 Fix typo in docs (#669)
### Motivation and Context

Fix some typos in the python sample notebooks
2023-04-27 00:15:03 -07:00

3.7 KiB

Setup

Step 1: Import Semantic Kernel SDK from pypi.org

In [ ]:
!python -m pip install -r requirements.txt

# Alternatively, you can install from the local workspace using this command
#!python -m pip install ../../../python

import semantic_kernel as sk

kernel = sk.Kernel()

Option 1: using OpenAI

Step 2: Add your Open AI Key key to a .env file in the same folder (org Id only if you have multiple orgs):

OPENAI_API_KEY="sk-..."
OPENAI_ORG_ID=""

and add OpenAI Text Completion to the kernel:

In [ ]:
from semantic_kernel.ai.open_ai import OpenAITextCompletion

api_key, org_id = sk.openai_settings_from_dot_env()

kernel.config.add_text_backend("dv", OpenAITextCompletion("text-davinci-003", api_key, org_id))

Option 2: using Azure OpenAI

Step 2: Add your Azure Open AI Service key settings to a .env file in the same folder:

AZURE_OPENAI_API_KEY="..."
AZURE_OPENAI_ENDPOINT="https://..."
AZURE_OPENAI_DEPLOYMENT_NAME="..."

and add Azure OpenAI Text Completion to the kernel:

In [ ]:
from semantic_kernel.ai.open_ai import AzureTextCompletion

deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()

kernel.config.add_text_backend("dv", AzureTextCompletion(deployment, endpoint, api_key))

Run a Semantic Function

Step 3: Load a Skill and run a semantic function:

In [ ]:
skill = kernel.import_semantic_skill_from_directory("../../skills", "FunSkill")
joke_function = skill["Joke"]

print(joke_function("time travel to dinosaur age"))