Files
semantic-kernel/samples/notebooks/python/00-getting-started.ipynb
T
d019485568 Python: Update notebooks and add samples for streaming and multiple responses (#1489)
### Motivation and Context
The python notebooks are pinned to 0.2.7.dev0 while the latest pip
package for python is 0.3.1.dev0. This PR updates the notebooks to pull
the 0.3.1.dev0 and adds 2 new notebooks demonstrating new features added
to SK between these versions.


### Description
- All notebooks depend on semantic-kernel==0.3.1.dev0
- Added a notebook demonstrating streaming completion responses
- Added a notebook demonstrating multiple responses per prompt
(including streaming them)


### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [ ] 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
- [ ] I didn't break anyone 😄

---------

Co-authored-by: Lee Miller <[email protected]>
Co-authored-by: Shawn Callegari <[email protected]>
2023-07-08 03:22:42 +00:00

3.3 KiB

Setup

Step 1: Import Semantic Kernel SDK from pypi.org

In [ ]:
!python -m pip install semantic-kernel==0.3.1.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"))