From e2e5e2dad30976809763409fabccd2530fab5dc3 Mon Sep 17 00:00:00 2001 From: Devis Lucato Date: Thu, 13 Apr 2023 14:13:19 -0700 Subject: [PATCH] Python: docs update + ruff config + fix tests --- README.md | 35 ++++++----- dotnet/README.md | 17 ++++- python/.env.example | 4 +- python/DEV_SETUP.md | 11 +++- python/README.md | 16 ++--- python/pyproject.toml | 3 + .../orchestration/sk_context.py | 7 +++ .../test_prompt_template_e2e.py | 5 +- .../unit/core_skills/test_file_io_skill.py | 62 ++++++++++++------- .../Example14_Memory.cs | 6 +- samples/notebooks/dotnet/0-AI-settings.ipynb | 2 +- ...otebook.ipynb => 00-getting-started.ipynb} | 2 +- ...pynb => 01-basic-loading-the-kernel.ipynb} | 2 +- ...ynb => 02-running-prompts-from-file.ipynb} | 2 +- ...pynb => 03-semantic-function-inline.ipynb} | 3 +- ....ipynb => 04-context-variables-chat.ipynb} | 0 ...anner.ipynb => 05-using-the-planner.ipynb} | 0 ...s.ipynb => 06-memory-and-embeddings.ipynb} | 12 ++-- .../{7-DALL-E-2.ipynb => 07-DALL-E-2.ipynb} | 0 ...2.ipynb => 08-chatGPT-with-DALL-E-2.ipynb} | 0 samples/notebooks/dotnet/README.md | 20 +++--- .../python/01-basic-loading-the-kernel.ipynb | 11 ++-- .../python/02-running-prompts-from-file.ipynb | 3 +- .../python/03-semantic-function-inline.ipynb | 3 +- .../python/04-context-variables-chat.ipynb | 2 +- .../python/06-memory-and-embeddings.ipynb | 10 +-- 26 files changed, 145 insertions(+), 93 deletions(-) rename samples/notebooks/dotnet/{Getting-Started-Notebook.ipynb => 00-getting-started.ipynb} (99%) rename samples/notebooks/dotnet/{1-basic-loading-the-kernel.ipynb => 01-basic-loading-the-kernel.ipynb} (98%) rename samples/notebooks/dotnet/{2-running-prompts-from-file.ipynb => 02-running-prompts-from-file.ipynb} (99%) rename samples/notebooks/dotnet/{3-semantic-function-inline.ipynb => 03-semantic-function-inline.ipynb} (99%) rename samples/notebooks/dotnet/{4-context-variables-chat.ipynb => 04-context-variables-chat.ipynb} (100%) rename samples/notebooks/dotnet/{5-using-the-planner.ipynb => 05-using-the-planner.ipynb} (100%) rename samples/notebooks/dotnet/{6-memory-and-embeddings.ipynb => 06-memory-and-embeddings.ipynb} (97%) rename samples/notebooks/dotnet/{7-DALL-E-2.ipynb => 07-DALL-E-2.ipynb} (100%) rename samples/notebooks/dotnet/{8-chatGPT-with-DALL-E-2.ipynb => 08-chatGPT-with-DALL-E-2.ipynb} (100%) diff --git a/README.md b/README.md index b4bbd93cd726..a6e4f128ae19 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Semantic Kernel is available to explore AI and build apps with C# and Python: Using Semantic Kernel in Python. +
The quickest way to get started with the basics is to get an API key (OpenAI or Azure OpenAI) @@ -74,7 +75,7 @@ For Python: 5. Run the python script. -## Samples apps ⚡ +## Sample apps ⚡ The repository includes some sample applications, with a React frontend and a backend web service using Semantic Kernel. @@ -89,28 +90,28 @@ Follow the links for more information and instructions about running these apps. | [GitHub repository Q&A](samples/apps/github-qna-webapp-react/README.md) | Use embeddings and memory to store recent data and allow you to query against it. | | [Copilot Chat Sample App](samples/apps/copilot-chat-app/README.md) | Build your own chat experience based on Semantic Kernel. | -**Please note:** +**Requirements:** - You will need an [Open AI API Key](https://openai.com/api/) or [Azure Open AI service key](https://learn.microsoft.com/azure/cognitive-services/openai/quickstart?pivots=rest-api) to get started. -- There are a few software requirements you may need to satisfy before running examples and notebooks: - 1. [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local) - used for running the kernel as a local API, required by the web apps. - 2. [Yarn](https://yarnpkg.com/getting-started/install) used for installing - web apps' dependencies. - 3. Semantic Kernel supports .NET Standard 2.1 and it's recommended using .NET 6+. However, some of - the examples in the repository require [.NET 7](https://dotnet.microsoft.com/download) and the VS Code - [Polyglot extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode) - to run the notebooks. - -## Notebooks ⚡ - -For a more hands-on overview, you can also check out the Jupyter C# and Python notebooks, starting +- [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local) + are required to run the kernel as a local web service, used by the sample web apps. +- [.NET 6](https://dotnet.microsoft.com/download/dotnet/6.0). If you have .NET 7 installe, Azure Function + Tools will still require .NET 6, so we suggest installing both. +- [Yarn](https://yarnpkg.com/getting-started/install) is used for installing web apps' dependencies. + + +## Jupyter Notebooks ⚡ + +For a more hands-on overview, you can also check out the C# and Python Jupyter notebooks, starting from here: -* [Getting Started with C# notebook](samples/notebooks/dotnet/Getting-Started-Notebook.ipynb) -* [Getting Started with Python notebook](samples/notebooks/python/00-getting-started-notebook.ipynb) +* [Getting Started with C# notebook](samples/notebooks/dotnet/00-getting-started.ipynb) +* [Getting Started with Python notebook](samples/notebooks/python/00-getting-started.ipynb) + +**Requirements:** C# notebooks require [.NET 7](https://dotnet.microsoft.com/download) +and the VS Code [Polyglot extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode). ## Contributing and Community diff --git a/dotnet/README.md b/dotnet/README.md index c47b75722c87..dfc40b805671 100644 --- a/dotnet/README.md +++ b/dotnet/README.md @@ -10,7 +10,8 @@ Make sure you have an Here is a quick example of how to use Semantic Kernel from a C# console app. First, let's create a new project, targeting .NET 6 or newer, and add the -`Microsoft.SemanticKernel` nuget package: +`Microsoft.SemanticKernel` nuget package to your project from the command prompt +in Visual Studio: dotnet add package Microsoft.SemanticKernel --prerelease @@ -101,5 +102,15 @@ Console.WriteLine(output); The repository contains also a few C# Jupyter notebooks that demonstrates how to get started with the Semantic Kernel. -See [here](../samples/notebooks/dotnet/README.md) for the full list with setup -instructions. \ No newline at end of file +See [here](../samples/notebooks/dotnet/README.md) for the full list, with +requirements and setup instructions. + +1. [Getting started](00-getting-started.ipynb) +2. [Loading and configuring Semantic Kernel](01-basic-loading-the-kernel.ipynb) +3. [Running AI prompts from file](02-running-prompts-from-file.ipynb) +4. [Creating Semantic Functions at runtime (i.e. inline functions)](03-semantic-function-inline.ipynb) +5. [Using Context Variables to Build a Chat Experience](04-context-variables-chat.ipynb) +6. [Creating and Executing Plans](05-using-the-planner.ipynb) +7. [Building Memory with Embeddings](06-memory-and-embeddings.ipynb) +8. [Creating images with DALL-E 2](07-DALL-E-2.ipynb) +9. [Chatting with ChatGPT and Images](08-chatGPT-with-DALL-E-2.ipynb) \ No newline at end of file diff --git a/python/.env.example b/python/.env.example index 42551f638f3e..5be9659fd888 100644 --- a/python/.env.example +++ b/python/.env.example @@ -1,5 +1,5 @@ OPENAI_API_KEY="" OPENAI_ORG_ID="" -AZURE_OPENAI_API_KEY="" -AZURE_OPENAI_ENDPOINT="" AZURE_OPENAI_DEPLOYMENT_NAME="" +AZURE_OPENAI_ENDPOINT="" +AZURE_OPENAI_API_KEY="" diff --git a/python/DEV_SETUP.md b/python/DEV_SETUP.md index 91e3d548289b..323479a88825 100644 --- a/python/DEV_SETUP.md +++ b/python/DEV_SETUP.md @@ -13,8 +13,9 @@ Copy those keys into a `.env` file (see the `.env.example` file): ``` OPENAI_API_KEY="" OPENAI_ORG_ID="" -AZURE_OPENAI_API_KEY="" +AZURE_OPENAI_DEPLOYMENT_NAME="" AZURE_OPENAI_ENDPOINT="" +AZURE_OPENAI_API_KEY="" ``` We suggest adding a copy of the `.env` file under these folders: @@ -92,9 +93,15 @@ You should be able to run the example under the [tests](tests) folder. poetry install poetry run pytest tests -# Pipeline checks +# Tools and scripts + +## Pipeline checks To run the same checks that run during the GitHub Action build, you can use this command, from the [python](/python) folder: poetry run pre-commit run -c .conf/.pre-commit-config.yaml -a + +## Running ruff + + poetry run ruff check . diff --git a/python/README.md b/python/README.md index fee86d922f0d..954e39d8d9b2 100644 --- a/python/README.md +++ b/python/README.md @@ -18,9 +18,9 @@ Copy those keys into a `.env` file (see the `.env.example` file): ``` OPENAI_API_KEY="" OPENAI_ORG_ID="" -AZURE_OPENAI_API_KEY="" -AZURE_OPENAI_ENDPOINT="" AZURE_OPENAI_DEPLOYMENT_NAME="" +AZURE_OPENAI_ENDPOINT="" +AZURE_OPENAI_API_KEY="" ``` # Running a prompt @@ -92,12 +92,12 @@ get started with the Semantic Kernel. Python notebooks: -* [Getting started with Semantic Kernel](samples/notebooks/python/00-getting-started.ipynb) -* [Loading and configuring Semantic Kernel](samples/notebooks/python/01-basic-loading-the-kernel.ipynb) -* [Running AI prompts from file](samples/notebooks/python/02-running-prompts-from-file.ipynb) -* [Creating Semantic Functions at runtime (i.e. inline functions)](samples/notebooks/python/03-semantic-function-inline.ipynb) -* [Using Context Variables to Build a Chat Experience](samples/notebooks/python/04-context-variables-chat.ipynb) -* [Building Memory with Embeddings](samples/notebooks/python/06-memory-and-embeddings.ipynb) +* [Getting started with Semantic Kernel](../samples/notebooks/python/00-getting-started.ipynb) +* [Loading and configuring Semantic Kernel](../samples/notebooks/python/01-basic-loading-the-kernel.ipynb) +* [Running AI prompts from file](../samples/notebooks/python/02-running-prompts-from-file.ipynb) +* [Creating Semantic Functions at runtime (i.e. inline functions)](../samples/notebooks/python/03-semantic-function-inline.ipynb) +* [Using Context Variables to Build a Chat Experience](../samples/notebooks/python/04-context-variables-chat.ipynb) +* [Building Memory with Embeddings](../samples/notebooks/python/06-memory-and-embeddings.ipynb) # Frequently asked questions diff --git a/python/pyproject.toml b/python/pyproject.toml index 319a57f48a0b..2821438a67a6 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -24,6 +24,9 @@ pytest-asyncio = "^0.21.0" [tool.isort] profile = "black" +[tool.ruff] +line-length = 120 + [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" diff --git a/python/semantic_kernel/orchestration/sk_context.py b/python/semantic_kernel/orchestration/sk_context.py index f2cc0eae2a6b..8eaaa0cf9911 100644 --- a/python/semantic_kernel/orchestration/sk_context.py +++ b/python/semantic_kernel/orchestration/sk_context.py @@ -131,6 +131,13 @@ def skills(self) -> ReadOnlySkillCollectionBase: """ return self._skill_collection + @skills.setter + def skills(self, value: ReadOnlySkillCollectionBase) -> None: + """ + Set the value of skills collection + """ + self._skill_collection = value + @property def log(self) -> Logger: """ diff --git a/python/tests/integration/template_engine/test_prompt_template_e2e.py b/python/tests/integration/template_engine/test_prompt_template_e2e.py index 9505cf95ce8f..fd5d295d15af 100644 --- a/python/tests/integration/template_engine/test_prompt_template_e2e.py +++ b/python/tests/integration/template_engine/test_prompt_template_e2e.py @@ -1,5 +1,6 @@ # Copyright (c) Microsoft. All rights reserved. +import os from typing import List, Tuple from pytest import mark, raises @@ -11,9 +12,9 @@ def _get_template_language_tests() -> List[Tuple[str, str]]: path = __file__ - path = path[: path.rfind("/")] + path = os.path.dirname(path) - with open(f"{path}/tests.txt", "r") as file: + with open(os.path.join(path, "tests.txt"), "r") as file: content = file.readlines() key = "" diff --git a/python/tests/unit/core_skills/test_file_io_skill.py b/python/tests/unit/core_skills/test_file_io_skill.py index 47fd5c818aa2..1a7b902ab240 100644 --- a/python/tests/unit/core_skills/test_file_io_skill.py +++ b/python/tests/unit/core_skills/test_file_io_skill.py @@ -23,12 +23,17 @@ def test_can_be_imported(): @pytest.mark.asyncio async def test_can_read_async(): skill = FileIOSkill() - with tempfile.NamedTemporaryFile(mode="w", delete=True) as fp: - fp.write("Hello, world!") - fp.flush() + fp = None + try: + with tempfile.NamedTemporaryFile(mode="w", delete=False) as fp: + fp.write("Hello, world!") + fp.flush() - content = await skill.read_async(fp.name) - assert content == "Hello, world!" + content = await skill.read_async(fp.name) + assert content == "Hello, world!" + finally: + if fp is not None: + os.remove(fp.name) @pytest.mark.asyncio @@ -46,34 +51,45 @@ async def test_cannot_read_async(): @pytest.mark.asyncio async def test_can_write(): skill = FileIOSkill() - with tempfile.NamedTemporaryFile(mode="r", delete=True) as fp: - context_variables = ContextVariables() + fp = None + try: + with tempfile.NamedTemporaryFile(mode="r", delete=False) as fp: + context_variables = ContextVariables() - context_variables.set("path", fp.name) - context_variables.set("content", "Hello, world!") + context_variables.set("path", fp.name) + context_variables.set("content", "Hello, world!") - context = SKContext(context_variables, None, None, None) + context = SKContext(context_variables, None, None, None) - await skill.write_async(context) + await skill.write_async(context) - content = fp.read() + content = fp.read() - assert content == "Hello, world!" + assert content == "Hello, world!" + finally: + if fp is not None: + os.remove(fp.name) @pytest.mark.asyncio async def test_cannot_write(): - with tempfile.TemporaryDirectory() as temp_dir: - skill = FileIOSkill() - os.chmod(temp_dir, 0o500) + skill = FileIOSkill() + fp = None + try: + with tempfile.NamedTemporaryFile(mode="r", delete=False) as fp: + os.chmod(fp.name, 0o500) - temp_file = os.path.join(temp_dir, "test.txt") - context_variables = ContextVariables() + context_variables = ContextVariables() - context_variables.set("path", temp_file) - context_variables.set("content", "Hello, world!") + context_variables.set("path", fp.name) + context_variables.set("content", "Hello, world!") - context = SKContext(context_variables, None, None, None) + context = SKContext(context_variables, None, None, None) - with pytest.raises(PermissionError): - await skill.write_async(context) + with pytest.raises(PermissionError): + await skill.write_async(context) + + os.chmod(fp.name, 0o777) + finally: + if fp is not None: + os.remove(fp.name) diff --git a/samples/dotnet/kernel-syntax-examples/Example14_Memory.cs b/samples/dotnet/kernel-syntax-examples/Example14_Memory.cs index 4df195b41ccc..76eb69efa95c 100644 --- a/samples/dotnet/kernel-syntax-examples/Example14_Memory.cs +++ b/samples/dotnet/kernel-syntax-examples/Example14_Memory.cs @@ -18,9 +18,9 @@ public static async Task RunAsync() { ["https://github.com/microsoft/semantic-kernel/blob/main/README.md"] = "README: Installation, getting started, and how to contribute", - ["https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/2-running-prompts-from-file.ipynb"] + ["https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/02-running-prompts-from-file.ipynb"] = "Jupyter notebook describing how to pass prompts from a file to a semantic skill or function", - ["https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/Getting-Started-Notebook.ipynb"] + ["https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/00-getting-started.ipynb"] = "Jupyter notebook describing how to get started with the Semantic Kernel", ["https://github.com/microsoft/semantic-kernel/tree/main/samples/skills/ChatSkill/ChatGPT"] = "Sample demonstrating how to create a chat skill interfacing with ChatGPT", @@ -99,7 +99,7 @@ Files added. Relevance: 0.8233838875772925 Result 2: - URL: : https://github.com/microsoft/semantic-kernel/blob/main/samples/dotnet-jupyter-notebooks/Getting-Started-Notebook.ipynb + URL: : https://github.com/microsoft/semantic-kernel/blob/main/samples/dotnet-jupyter-notebooks/00-getting-started.ipynb Title : Jupyter notebook describing how to get started with the Semantic Kernel Relevance: 0.7920580994199448 diff --git a/samples/notebooks/dotnet/0-AI-settings.ipynb b/samples/notebooks/dotnet/0-AI-settings.ipynb index f36e7072206b..f6345fee19cd 100644 --- a/samples/notebooks/dotnet/0-AI-settings.ipynb +++ b/samples/notebooks/dotnet/0-AI-settings.ipynb @@ -113,7 +113,7 @@ "metadata": {}, "source": [ "Now that your environment is all set up, let's dive into\n", - "[how to do basic loading of the Semantic Kernel](1-basic-loading-the-kernel.ipynb)." + "[how to do basic loading of the Semantic Kernel](01-basic-loading-the-kernel.ipynb)." ] } ], diff --git a/samples/notebooks/dotnet/Getting-Started-Notebook.ipynb b/samples/notebooks/dotnet/00-getting-started.ipynb similarity index 99% rename from samples/notebooks/dotnet/Getting-Started-Notebook.ipynb rename to samples/notebooks/dotnet/00-getting-started.ipynb index e39aacf07ee0..c952ec3309b5 100644 --- a/samples/notebooks/dotnet/Getting-Started-Notebook.ipynb +++ b/samples/notebooks/dotnet/00-getting-started.ipynb @@ -159,7 +159,7 @@ "Sample app learning examples:\n", "- [Simple chat summary](../../apps/chat-summary-webapp-react/README.md) (**Recommended**) – learn how basic semantic functions can be added to an app\n", "- [Book creator](../../apps/book-creator-webapp-react/README.md) – learn how Planner and chaining of semantic functions can be used in your app\n", - "- [Authentication and APIs](../../dotnet/graph-api-skills/README.md) – learn how to connect to external API's with authentication while using Semantic Kernel" + "- [Authentication and APIs](../../dotnet/graph-api-skills/README.md) – learn how to connect to external API's with authentication while using Semantic Kernel", "- [Copilot Chat](../../apps/copilot-chat-app/d) – Build your own chatbot based on Semantic Kernel" ] } diff --git a/samples/notebooks/dotnet/1-basic-loading-the-kernel.ipynb b/samples/notebooks/dotnet/01-basic-loading-the-kernel.ipynb similarity index 98% rename from samples/notebooks/dotnet/1-basic-loading-the-kernel.ipynb rename to samples/notebooks/dotnet/01-basic-loading-the-kernel.ipynb index e464a6776128..18ced392a176 100644 --- a/samples/notebooks/dotnet/1-basic-loading-the-kernel.ipynb +++ b/samples/notebooks/dotnet/01-basic-loading-the-kernel.ipynb @@ -194,7 +194,7 @@ "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](2-running-prompts-from-file.ipynb)." + "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)." ] } ], diff --git a/samples/notebooks/dotnet/2-running-prompts-from-file.ipynb b/samples/notebooks/dotnet/02-running-prompts-from-file.ipynb similarity index 99% rename from samples/notebooks/dotnet/2-running-prompts-from-file.ipynb rename to samples/notebooks/dotnet/02-running-prompts-from-file.ipynb index d73b8c295fb3..284050ebe96b 100644 --- a/samples/notebooks/dotnet/2-running-prompts-from-file.ipynb +++ b/samples/notebooks/dotnet/02-running-prompts-from-file.ipynb @@ -185,7 +185,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Great, now that you know how to load a skill from disk, let's show how you can [create and run a semantic function inline.](./3-semantic-function-inline.ipynb)" + "Great, now that you know how to load a skill from disk, let's show how you can [create and run a semantic function inline.](./03-semantic-function-inline.ipynb)" ] } ], diff --git a/samples/notebooks/dotnet/3-semantic-function-inline.ipynb b/samples/notebooks/dotnet/03-semantic-function-inline.ipynb similarity index 99% rename from samples/notebooks/dotnet/3-semantic-function-inline.ipynb rename to samples/notebooks/dotnet/03-semantic-function-inline.ipynb index 97b7a1c0df56..bef36df4d4c2 100644 --- a/samples/notebooks/dotnet/3-semantic-function-inline.ipynb +++ b/samples/notebooks/dotnet/03-semantic-function-inline.ipynb @@ -8,10 +8,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "The [previous notebook](./2-running-prompts-from-file.ipynb)\n", + "The [previous notebook](./02-running-prompts-from-file.ipynb)\n", "showed how to define a semantic function using a prompt template stored on a file.\n", "\n", "In this notebook, we'll show how to use the Semantic Kernel to define functions inline with your C# code. This can be useful in a few scenarios:\n", diff --git a/samples/notebooks/dotnet/4-context-variables-chat.ipynb b/samples/notebooks/dotnet/04-context-variables-chat.ipynb similarity index 100% rename from samples/notebooks/dotnet/4-context-variables-chat.ipynb rename to samples/notebooks/dotnet/04-context-variables-chat.ipynb diff --git a/samples/notebooks/dotnet/5-using-the-planner.ipynb b/samples/notebooks/dotnet/05-using-the-planner.ipynb similarity index 100% rename from samples/notebooks/dotnet/5-using-the-planner.ipynb rename to samples/notebooks/dotnet/05-using-the-planner.ipynb diff --git a/samples/notebooks/dotnet/6-memory-and-embeddings.ipynb b/samples/notebooks/dotnet/06-memory-and-embeddings.ipynb similarity index 97% rename from samples/notebooks/dotnet/6-memory-and-embeddings.ipynb rename to samples/notebooks/dotnet/06-memory-and-embeddings.ipynb index 5c9080f92962..eeea79fc7850 100644 --- a/samples/notebooks/dotnet/6-memory-and-embeddings.ipynb +++ b/samples/notebooks/dotnet/06-memory-and-embeddings.ipynb @@ -10,7 +10,7 @@ "So far, we've mostly been treating the kernel as a stateless orchestration engine.\n", "We send text into a model API and receive text out. \n", "\n", - "In a [previous notebook](4-context-variables-chat.ipynb), we used `context variables` to pass in additional\n", + "In a [previous notebook](04-context-variables-chat.ipynb), we used `context variables` to pass in additional\n", "text into prompts to enrich them with more context. This allowed us to create a basic chat experience. \n", "\n", "However, if you solely relied on context variables, you would quickly realize that eventually your prompt\n", @@ -193,7 +193,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Let's now revisit the our chat sample from the [previous notebook](4-context-variables-chat.ipynb).\n", + "Let's now revisit the our chat sample from the [previous notebook](04-context-variables-chat.ipynb).\n", "If you remember, we used context variables to fill the prompt with a `history` that continuously got populated as we chatted with the bot. Let's add also memory to it!" ] }, @@ -433,9 +433,9 @@ "{\n", " [\"https://github.com/microsoft/semantic-kernel/blob/main/README.md\"]\n", " = \"README: Installation, getting started, and how to contribute\",\n", - " [\"https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/2-running-prompts-from-file.ipynb\"]\n", + " [\"https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/02-running-prompts-from-file.ipynb\"]\n", " = \"Jupyter notebook describing how to pass prompts from a file to a semantic skill or function\",\n", - " [\"https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/Getting-Started-Notebook.ipynb\"]\n", + " [\"https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/00-getting-started.ipynb\"]\n", " = \"Jupyter notebook describing how to get started with the Semantic Kernel\",\n", " [\"https://github.com/microsoft/semantic-kernel/tree/main/samples/skills/ChatSkill/ChatGPT\"]\n", " = \"Sample demonstrating how to create a chat skill interfacing with ChatGPT\",\n", @@ -558,12 +558,12 @@ "Query: I love Jupyter notebooks, how should I get started?\n", "\n", "Result 1:\n", - " URL: : https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/Getting-Started-Notebook.ipynb\n", + " URL: : https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/00-getting-started.ipynb\n", " Title : Jupyter notebook describing how to get started with the Semantic Kernel\n", " Relevance: 0.8677540204531753\n", "\n", "Result 2:\n", - " URL: : https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/2-running-prompts-from-file.ipynb\n", + " URL: : https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/02-running-prompts-from-file.ipynb\n", " Title : Jupyter notebook describing how to pass prompts from a file to a semantic skill or function\n", " Relevance: 0.8165638244387959\n", "\n", diff --git a/samples/notebooks/dotnet/7-DALL-E-2.ipynb b/samples/notebooks/dotnet/07-DALL-E-2.ipynb similarity index 100% rename from samples/notebooks/dotnet/7-DALL-E-2.ipynb rename to samples/notebooks/dotnet/07-DALL-E-2.ipynb diff --git a/samples/notebooks/dotnet/8-chatGPT-with-DALL-E-2.ipynb b/samples/notebooks/dotnet/08-chatGPT-with-DALL-E-2.ipynb similarity index 100% rename from samples/notebooks/dotnet/8-chatGPT-with-DALL-E-2.ipynb rename to samples/notebooks/dotnet/08-chatGPT-with-DALL-E-2.ipynb diff --git a/samples/notebooks/dotnet/README.md b/samples/notebooks/dotnet/README.md index fe8260cca127..61d910802029 100644 --- a/samples/notebooks/dotnet/README.md +++ b/samples/notebooks/dotnet/README.md @@ -52,16 +52,16 @@ If you need an OpenAI key, go [here](https://platform.openai.com/account/api-key Before starting, make sure you configured `config/settings.json`, see the previous section. -For a quick dive, look at the [getting started notebook](Getting-Started-Notebook.ipynb). - -1. [Loading and configuring Semantic Kernel](1-basic-loading-the-kernel.ipynb) -2. [Running AI prompts from file](2-running-prompts-from-file.ipynb) -3. [Creating Semantic Functions at runtime (i.e. inline functions)](3-semantic-function-inline.ipynb) -4. [Using Context Variables to Build a Chat Experience](4-context-variables-chat.ipynb) -5. [Creating and Executing Plans](5-using-the-planner.ipynb) -6. [Building Memory with Embeddings](6-memory-and-embeddings.ipynb) -7. [Creating images with DALL-E 2](7-DALL-E-2.ipynb) -8. [Chatting with ChatGPT and Images](8-chatGPT-with-DALL-E-2.ipynb) +For a quick dive, look at the [getting started notebook](00-getting-started.ipynb). + +1. [Loading and configuring Semantic Kernel](01-basic-loading-the-kernel.ipynb) +2. [Running AI prompts from file](02-running-prompts-from-file.ipynb) +3. [Creating Semantic Functions at runtime (i.e. inline functions)](03-semantic-function-inline.ipynb) +4. [Using Context Variables to Build a Chat Experience](04-context-variables-chat.ipynb) +5. [Creating and Executing Plans](05-using-the-planner.ipynb) +6. [Building Memory with Embeddings](06-memory-and-embeddings.ipynb) +7. [Creating images with DALL-E 2](07-DALL-E-2.ipynb) +8. [Chatting with ChatGPT and Images](08-chatGPT-with-DALL-E-2.ipynb) # Run notebooks in the browser with JupyterLab diff --git a/samples/notebooks/python/01-basic-loading-the-kernel.ipynb b/samples/notebooks/python/01-basic-loading-the-kernel.ipynb index 5532d9db8495..0ab1a2974e4b 100644 --- a/samples/notebooks/python/01-basic-loading-the-kernel.ipynb +++ b/samples/notebooks/python/01-basic-loading-the-kernel.ipynb @@ -34,7 +34,7 @@ "outputs": [], "source": [ "import semantic_kernel as sk\n", - "import semantic_kernel.ai.open_ai as sk_oai" + "from semantic_kernel.ai.open_ai import AzureTextCompletion, OpenAITextCompletion" ] }, { @@ -105,7 +105,7 @@ "\n", "kernel.config.add_text_backend( # We are adding a text backend\n", " \"Azure_curie\", # The alias we can use in prompt templates' config.json\n", - " sk_oai.AzureTextCompletion(\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", @@ -114,7 +114,7 @@ "\n", "kernel.config.add_text_backend( # We are adding a text backend\n", " \"OpenAI_davinci\", # The alias we can use in prompt templates' config.json\n", - " sk_oai.OpenAITextCompletion(\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", @@ -145,10 +145,11 @@ ] }, { + "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](2-running-prompts-from-file.ipynb)." + "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)." ] } ], @@ -168,7 +169,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.10.2" }, "polyglot_notebook": { "kernelInfo": { diff --git a/samples/notebooks/python/02-running-prompts-from-file.ipynb b/samples/notebooks/python/02-running-prompts-from-file.ipynb index 09a19e769c6e..617ef6329f41 100644 --- a/samples/notebooks/python/02-running-prompts-from-file.ipynb +++ b/samples/notebooks/python/02-running-prompts-from-file.ipynb @@ -157,11 +157,12 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "2281a1fc", "metadata": {}, "source": [ - "Great, now that you know how to load a skill from disk, let's show how you can [create and run a semantic function inline.](./3-semantic-function-inline.ipynb)" + "Great, now that you know how to load a skill from disk, let's show how you can [create and run a semantic function inline.](./03-semantic-function-inline.ipynb)" ] } ], diff --git a/samples/notebooks/python/03-semantic-function-inline.ipynb b/samples/notebooks/python/03-semantic-function-inline.ipynb index 4eab935383e4..a118b4cd6551 100644 --- a/samples/notebooks/python/03-semantic-function-inline.ipynb +++ b/samples/notebooks/python/03-semantic-function-inline.ipynb @@ -9,11 +9,12 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "40201641", "metadata": {}, "source": [ - "The [previous notebook](./2-running-prompts-from-file.ipynb)\n", + "The [previous notebook](./02-running-prompts-from-file.ipynb)\n", "showed how to define a semantic function using a prompt template stored on a file.\n", "\n", "In this notebook, we'll show how to use the Semantic Kernel to define functions inline with your C# code. This can be useful in a few scenarios:\n", diff --git a/samples/notebooks/python/04-context-variables-chat.ipynb b/samples/notebooks/python/04-context-variables-chat.ipynb index a21d76bda235..eef19c65406c 100644 --- a/samples/notebooks/python/04-context-variables-chat.ipynb +++ b/samples/notebooks/python/04-context-variables-chat.ipynb @@ -25,7 +25,7 @@ "metadata": {}, "outputs": [], "source": [ - "!python -m pip install ../../../python" + "!python -m pip install -r requirements.txt" ] }, { diff --git a/samples/notebooks/python/06-memory-and-embeddings.ipynb b/samples/notebooks/python/06-memory-and-embeddings.ipynb index be2dd0613a2d..fefe8863ebb3 100644 --- a/samples/notebooks/python/06-memory-and-embeddings.ipynb +++ b/samples/notebooks/python/06-memory-and-embeddings.ipynb @@ -1,6 +1,7 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "id": "68e1c158", "metadata": {}, @@ -10,7 +11,7 @@ "So far, we've mostly been treating the kernel as a stateless orchestration engine.\n", "We send text into a model API and receive text out. \n", "\n", - "In a [previous notebook](4-context-variables-chat.ipynb), we used `context variables` to pass in additional\n", + "In a [previous notebook](04-context-variables-chat.ipynb), we used `context variables` to pass in additional\n", "text into prompts to enrich them with more context. This allowed us to create a basic chat experience. \n", "\n", "However, if you solely relied on context variables, you would quickly realize that eventually your prompt\n", @@ -154,11 +155,12 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "e70c2b22", "metadata": {}, "source": [ - "Let's now revisit the our chat sample from the [previous notebook](4-context-variables-chat.ipynb).\n", + "Let's now revisit the our chat sample from the [previous notebook](04-context-variables-chat.ipynb).\n", "If you remember, we used context variables to fill the prompt with a `history` that continuously got populated as we chatted with the bot. Let's add also memory to it!" ] }, @@ -313,9 +315,9 @@ "\n", "github_files ={}\n", "github_files[\"https://github.com/microsoft/semantic-kernel/blob/main/README.md\"] = \"README: Installation, getting started, and how to contribute\"\n", - "github_files[\"https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/2-running-prompts-from-file.ipynb\"] = \\\n", + "github_files[\"https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/02-running-prompts-from-file.ipynb\"] = \\\n", " \"Jupyter notebook describing how to pass prompts from a file to a semantic skill or function\"\n", - "github_files[\"https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/Getting-Started-Notebook.ipynb\"] = \\\n", + "github_files[\"https://github.com/microsoft/semantic-kernel/blob/main/samples/notebooks/dotnet/00-getting-started.ipynb\"] = \\\n", " \"Jupyter notebook describing how to get started with the Semantic Kernel\"\n", "github_files[\"https://github.com/microsoft/semantic-kernel/tree/main/samples/skills/ChatSkill/ChatGPT\"] = \\\n", " \"Sample demonstrating how to create a chat skill interfacing with ChatGPT\"\n",