Files
semantic-kernel/samples/notebooks/python/00-getting-started.ipynb
T
7ed26eacaa Python: Update notebooks by pinning pip package and removing requirements.txt (#868)
### Motivation and Context

* Removing the requirements.txt and just pinning each notebook to a pip
package that should work.
Doing this allows users to run notebooks without error even if the code
in the core repo updates.
When a new pip package is released, we will bump the version number in
each notebook.
* Fix usage of context variables. Apps should avoid using anonymous
context variables and prefer using the context, to retain access to the
kernel internals during the orchestration.

---------

Co-authored-by: Alex Chao <[email protected]>
Co-authored-by: Devis Lucato <[email protected]>
2023-05-08 18:13:17 -07:00

3.2 KiB

Setup

Step 1: Import Semantic Kernel SDK from pypi.org

In [ ]:
!python -m pip install semantic-kernel==0.2.7.dev0
In [ ]:
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.connectors.ai.open_ai import OpenAITextCompletion

api_key, org_id = sk.openai_settings_from_dot_env()

kernel.add_text_completion_service("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.connectors.ai.open_ai import AzureTextCompletion

deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()

kernel.add_text_completion_service("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"))