Files
semantic-kernel/python/notebooks/01-basic-loading-the-kernel.ipynb
T
Adarsh AcharyaandDmytro Struk 53758dc9bc Python: fixed doc error in 01-basic-loading-the-kernel.ipynb (#3101)
### Description

This PR fixes issue #2934 

### Contribution Checklist

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄

Co-authored-by: Dmytro Struk <[email protected]>
2023-10-10 17:15:45 +00:00

175 lines
4.6 KiB
Plaintext

{
"cells": [
{
"attachments": {},
"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 semantic-kernel==0.3.10.dev0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import semantic_kernel as sk\n",
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion"
]
},
{
"attachments": {},
"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)"
]
},
{
"attachments": {},
"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_chat_service( # We are adding a text service\n",
" \"Azure_curie\", # The alias we can use in prompt templates' config.json\n",
" AzureChatCompletion(\n",
" \"my-finetuned-Curie\", # Azure OpenAI *Deployment name*\n",
" \"https://contoso.openai.azure.com/\", # Azure OpenAI *Endpoint*\n",
" \"...your Azure OpenAI Key...\" # Azure OpenAI *Key*\n",
" )\n",
")\n",
"\n",
"kernel.add_chat_service( # We are adding a text service\n",
" \"OpenAI_chat_gpt\", # The alias we can use in prompt templates' config.json\n",
" OpenAIChatCompletion(\n",
" \"gpt-3.5-turbo\", # 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 (ipykernel)",
"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
}