Files
semantic-kernel/samples/notebooks/python/01-basic-loading-the-kernel.ipynb
T
Mark KarleandShawn Callegari 3e1d13e945 Merge KernelConfig with Kernel (#731)
### Motivation and Context
KernelConfig isn't needed as it's less pythonic and is not used
independently from Kernel. This moves all its methods and members into
Kernel.

### Description
- Removed KernelConfig
- Put KernelConfig's methods and variables into Kernel
- Ran unit and end-to-end tests
- Did not run notebooks because they are out of date with the current
repo.

---------
Co-authored-by: Shawn Callegari <[email protected]>
2023-05-05 22:27:49 -07:00

172 lines
5.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Basic Loading of the Kernel"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"To run the notebooks we recommend using Poetry and starting a shell with a virtual environment\n",
"prepared to use SK. \n",
"\n",
"See [DEV_SETUP.md](../../../python/DEV_SETUP.md) for more information."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!python -m pip install -r requirements.txt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import semantic_kernel as sk\n",
"from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion, OpenAITextCompletion"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can instantiate the kernel in a few ways, depending on your use case."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Simple instance\n",
"kernel_1 = sk.Kernel()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Instance with a custom logger\n",
"my_logger = sk.NullLogger()\n",
"kernel_2 = sk.Kernel(log=my_logger)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When using the kernel for AI requests, the kernel needs some settings like URL and credentials to the AI models.\n",
"\n",
"The SDK currently supports OpenAI and Azure OpenAI, other services will be added over time.\n",
"\n",
"If you need an Azure OpenAI key, go [here](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quickstart?pivots=rest-api)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"kernel = sk.Kernel()\n",
"\n",
"kernel.add_text_completion_service( # We are adding a text service\n",
" \"Azure_curie\", # The alias we can use in prompt templates' config.json\n",
" AzureTextCompletion(\n",
" \"my-finetuned-Curie\", # Azure OpenAI *Deployment ID*\n",
" \"https://contoso.openai.azure.com/\", # Azure OpenAI *Endpoint*\n",
" \"...your Azure OpenAI Key...\" # Azure OpenAI *Key*\n",
" )\n",
")\n",
"\n",
"kernel.add_text_completion_service( # We are adding a text service\n",
" \"OpenAI_davinci\", # The alias we can use in prompt templates' config.json\n",
" OpenAITextCompletion(\n",
" \"text-davinci-003\", # OpenAI Model Name\n",
" \"...your OpenAI API Key...\", # OpenAI API key\n",
" \"...your OpenAI Org ID...\" # *optional* OpenAI Organization ID\n",
" )\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"When working with multiple services and multiple models, the **first service** defined\n",
"is also the \"**default**\" used in these scenarios:\n",
"\n",
"* a prompt configuration doesn't specify which AI service to use\n",
"* a prompt configuration requires a service unknown to the kernel\n",
"\n",
"The default can be set and changed programmatically:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"kernel.set_default_text_completion_service(\"Azure_curie\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Great, now that you're familiar with setting up the Semantic Kernel, let's see [how we can use it to run prompts](02-running-prompts-from-file.ipynb)."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
},
"polyglot_notebook": {
"kernelInfo": {
"items": [
{
"aliases": [
"frontend"
],
"name": "vscode"
}
]
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}