mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation and Context Bump python project version for release. Update notebooks. <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description Bump python project version for release. Update notebooks. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [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 😄
167 lines
4.3 KiB
Plaintext
167 lines
4.3 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.5.1.dev0"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import semantic_kernel as sk\n",
|
|
"from semantic_kernel.connectors.ai.open_ai import (\n",
|
|
" AzureChatCompletion,\n",
|
|
" OpenAIChatCompletion,\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"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": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Simple instance\n",
|
|
"kernel_1 = sk.Kernel()"
|
|
]
|
|
},
|
|
{
|
|
"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",
|
|
" deployment_name=\"my-finetuned-Curie\", # Azure OpenAI *Deployment name*\n",
|
|
" endpoint=\"https://contoso.openai.azure.com/\", # Azure OpenAI *Endpoint*\n",
|
|
" api_key=\"...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",
|
|
" ai_model_id=\"gpt-3.5-turbo\", # OpenAI Model Name\n",
|
|
" api_key=\"...your OpenAI API Key...\", # OpenAI API key\n",
|
|
" org_id=\"...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.12"
|
|
},
|
|
"polyglot_notebook": {
|
|
"kernelInfo": {
|
|
"items": [
|
|
{
|
|
"aliases": [
|
|
"frontend"
|
|
],
|
|
"name": "vscode"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|