### Install Semantic Kernel Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/03/PluginWithSK.ipynb Installs the latest version of the semantic-kernel library using pip. ```python ! pip install semantic-kernel -U ``` -------------------------------- ### Install Semantic Kernel NuGet Packages Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/05/EmbeddingsWithSK.ipynb Installs the necessary Semantic Kernel and Qdrant connector packages using `#r` directives. ```csharp #r "nuget: Microsoft.SemanticKernel, *-*" #r "nuget: Microsoft.SemanticKernel.Connectors.Qdrant, *-*" ``` -------------------------------- ### Python: Basic Prompt Execution Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop2/genppt_notebook.ipynb Demonstrates how to create a kernel, load a prompt, and execute it. This is a fundamental example for getting started with Semantic Kernel in Python. ```Python from semantic_kernel import Kernel kernel = Kernel() # Load a prompt from a file or string prompt = """ Write a short poem about a {subject}. """ # Create a semantic function poem_function = kernel.create_semantic_function(prompt) # Invoke the function result = poem_function(subject="a rainy day") print(result) ``` -------------------------------- ### Install Semantic Kernel Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/02/LearnSK.ipynb Installs the latest version of the semantic-kernel library using pip. This is the first step to using the library. ```python ! pip install semantic-kernel -U ``` -------------------------------- ### Install Semantic Kernel and Qdrant Client Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Installs the necessary Python packages for Semantic Kernel and Qdrant client. This is a prerequisite for using these libraries. ```python ! pip install semantic-kernel -U ! pip install qdrant_client -U ``` -------------------------------- ### Python Setup for Machine Learning Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/data/notes/01-introduction.md Instructions for setting up a Python environment for machine learning development, including installing Python and a text editor. ```APIDOC Python Installation: - Download and install Python from the official website. - Recommended text editor: Visual Studio Code. Dependencies: - Python 3.x ``` -------------------------------- ### Python Setup for Machine Learning Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/data/notes/01-introduction.md Instructions for setting up a Python environment for machine learning development, including installing Python and a text editor. ```APIDOC Python Installation: - Download and install Python from the official website. - Recommended text editor: Visual Studio Code. Dependencies: - Python 3.x ``` -------------------------------- ### Install Semantic Kernel Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/03/FunctionCallWithSK.ipynb Installs the latest version of the Semantic Kernel library using pip. ```python ! pip install semantic-kernel -U ``` -------------------------------- ### Install Semantic Kernel and Qdrant Client Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/notebook.ipynb Installs the necessary Python packages for Semantic Kernel and Qdrant client. This is a prerequisite for using these libraries. ```python ! pip install semantic-kernel -U ! pip install qdrant_client -U ``` -------------------------------- ### Python Setup for Machine Learning Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notes/01-introduction.md Instructions for setting up a Python environment for machine learning development, including installing Python and a text editor. ```APIDOC Python Installation: - Download and install Python from the official website. - Recommended text editor: Visual Studio Code. Dependencies: - Python 3.x ``` -------------------------------- ### Semantic Kernel NuGet Packages Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/notebook.ipynb Installs necessary Semantic Kernel NuGet packages for core functionality and Qdrant integration. ```csharp #r "nuget: Microsoft.SemanticKernel, *-*" #r "nuget: Microsoft.SemanticKernel.Connectors.Qdrant, *-*" ``` -------------------------------- ### Install Semantic Kernel and Qdrant Client Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/05/EmbeddingsWithSK.ipynb Installs the necessary Python packages for Semantic Kernel and Qdrant client. This is a prerequisite for using these libraries. ```python ! pip install semantic-kernel -U ! pip install qdrant_client -U ``` -------------------------------- ### Install Semantic Kernel and Qdrant Client Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop2/genppt_notebook.ipynb Installs the latest version of the semantic-kernel and qdrant-client Python packages. These are essential for using Semantic Kernel and its related functionalities. ```python ! pip install semantic-kernel -U ! pip install qdrant_client -U ``` -------------------------------- ### Initialize Sequential Planner Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/java/04/PlannerWithSK.ipynb Initializes a SequentialPlanner with a given kernel and maximum token count. This is a common setup step before creating plans. ```csharp SequentialPlanner planner = initPlanner(kernel, 1024); ``` -------------------------------- ### Semantic Kernel Chat Completion Service Setup Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/notebook.ipynb Configures the ChatCompletionService using the initialized OpenAI client and specifies the model deployment name for chat completions. ```java import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.Kernel.Builder; import com.microsoft.semantickernel.exceptions.ConfigurationException; import com.microsoft.semantickernel.orchestration.FunctionResult; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.plugin.KernelPluginFactory; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion; import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; ChatCompletionService chatGenerationService = OpenAIChatCompletion.builder() .withOpenAIAsyncClient(client) .withModelId("Your Azure OpenAI Service gpt-3.5-turbo-instruct deployment name") .build(); ``` -------------------------------- ### Semantic Kernel C# Setup with Azure OpenAI Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/03/PluginWithSK.ipynb Demonstrates how to initialize the Semantic Kernel with Azure OpenAI chat completion services. It requires specifying the deployment name, endpoint, and API key for the Azure OpenAI service. ```csharp #r "nuget: Microsoft.SemanticKernel, *-*" using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Memory; using Microsoft.SemanticKernel.Connectors.OpenAI; Kernel kernel = Kernel.CreateBuilder() .AddAzureOpenAIChatCompletion("Your Azure OpenAI Service gpt-4 Deployment Name" , "Your Azure OpenAI Service Endpoint", "Your Azure OpenAI Service API Key") .Build(); ``` -------------------------------- ### Install PyPDF2 Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop2/genppt_notebook.ipynb Installs the PyPDF2 package, which is used for reading and manipulating PDF files. ```python ! pip install PyPDF2 -U ``` -------------------------------- ### Semantic Kernel NuGet Packages Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop3/dotNETAgent/SKAIAgent.ipynb Installs necessary Semantic Kernel NuGet packages for .NET development, including core functionalities and experimental agent features. ```C# #r "nuget: Microsoft.SemanticKernel, *-*" #r "nuget: Microsoft.SemanticKernel.Experimental.Agents, *-*" ``` -------------------------------- ### Install Semantic Kernel - .NET Source: https://github.com/microsoft/semantickernelcookbook/blob/main/docs/cn/02.IntroduceSemanticKernel.md Installs the latest version of the Semantic Kernel library for .NET using NuGet. ```csharp #r "nuget: Microsoft.SemanticKernel, *-*" ``` -------------------------------- ### Node.js and JavaScript Setup for Web Apps Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/data/notes/01-introduction.md Guidance on setting up Node.js and npm for JavaScript development, particularly for building web applications. ```APIDOC Node.js and npm Installation: - Download and install Node.js and npm from the official website. - Recommended IDE: Visual Studio Code. Usage: - Used for building web applications alongside Python in ML courses. ``` -------------------------------- ### Node.js and JavaScript Setup for Web Apps Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notes/01-introduction.md Guidance on setting up Node.js and npm for JavaScript development, particularly for building web applications. ```APIDOC Node.js and npm Installation: - Download and install Node.js and npm from the official website. - Recommended IDE: Visual Studio Code. Usage: - Used for building web applications alongside Python in ML courses. ``` -------------------------------- ### Node.js and JavaScript Setup for Web Apps Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/data/notes/01-introduction.md Guidance on setting up Node.js and npm for JavaScript development, particularly for building web applications. ```APIDOC Node.js and npm Installation: - Download and install Node.js and npm from the official website. - Recommended IDE: Visual Studio Code. Usage: - Used for building web applications alongside Python in ML courses. ``` -------------------------------- ### Create Plugins from Directory Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/notebook.ipynb Loads plugins (FilePlugin and AnswerPlugin) from specified directories. ```csharp var filePlugin = kernel.CreatePluginFromPromptDirectory(Path.Combine(pluginDirectory, "FilePlugin")); var answerPlugin = kernel.CreatePluginFromPromptDirectory(Path.Combine(pluginDirectory, "AnswerPlugin")); ``` -------------------------------- ### Semantic Kernel: Prompt Engineering (C#) Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/plugins/AnswerPlugin/Summary/skprompt.txt Demonstrates prompt engineering best practices in C# for Semantic Kernel. This example shows how to structure prompts with examples and variables for better AI responses. ```csharp using Microsoft.SemanticKernel; var kernel = Kernel.CreateBuilder().Build(); var prompt = """ Translate the following English text to French: English: Hello world French: Bonjour le monde English: How are you? French: Comment ça va? English: {english_text} French: """; var translateFunction = kernel.CreateFunctionFromPrompt(prompt); var result = await kernel.InvokeAsync(translateFunction, new() { { "english_text", "I love Semantic Kernel." } }); Console.WriteLine(result); ``` -------------------------------- ### Install Semantic Kernel NuGet Package Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/03/FunctionCallWithSK.ipynb This snippet shows how to reference the Semantic Kernel NuGet package using the '#r' directive in a C# environment, typically within a .NET interactive context. ```csharp #r "nuget: Microsoft.SemanticKernel, *-*" ``` -------------------------------- ### Initialize and Create Qdrant Collection Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Initializes the QdrantMemoryStore with a specified vector size and connection details, then creates a new collection asynchronously. ```python qdrant_store = QdrantMemoryStore(vector_size=1536, url="http://localhost",port=6333) await qdrant_store.create_collection_async(base_vectordb) ``` -------------------------------- ### Install Semantic Kernel - Python Source: https://github.com/microsoft/semantickernelcookbook/blob/main/docs/cn/02.IntroduceSemanticKernel.md Installs the latest version of the Semantic Kernel library for Python using pip. ```python ! pip install semantic-kernel -U ``` -------------------------------- ### Semantic Kernel Initialization Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/notebook.ipynb Builds a Semantic Kernel instance and configures it with the ChatCompletionService for text generation. ```java import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.Kernel.Builder; import com.microsoft.semantickernel.exceptions.ConfigurationException; import com.microsoft.semantickernel.orchestration.FunctionResult; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.plugin.KernelPluginFactory; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion; import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; Kernel kernel = Kernel.builder() .withAIService(ChatCompletionService.class, chatGenerationService) .build(); ``` -------------------------------- ### Get Notes Files Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/notebook.ipynb Retrieves all files from the './data/notes' directory. ```csharp DirectoryInfo notesFolder = new DirectoryInfo(@"./data/notes"); FileInfo[] notesFiles = notesFolder.GetFiles(); ``` -------------------------------- ### Import Semantic Kernel Library Source: https://github.com/microsoft/semantickernelcookbook/blob/main/docs/en/02.IntroduceSemanticKernel.md Installs the latest Semantic Kernel library for .NET and Python projects. For .NET, it uses NuGet package management. For Python, it uses pip for installation. ```.NET #r "nuget: Microsoft.SemanticKernel, *-*" ``` ```Python ! pip install semantic-kernel -U ``` -------------------------------- ### Add Azure OpenAI Text Completion Service (Commented Out) Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/02/LearnSK.ipynb A commented-out example showing how to add an Azure OpenAI text completion service. It requires deployment name, endpoint, and API key. ```python # kernel.add_text_completion_service("azure_text_competion_service", skaoai.AzureTextCompletion(deployment,endpoint,api_key=api_key)) ``` -------------------------------- ### Getting Plan as String Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/04/PlannerWithSK.ipynb Converts the created plan object into its string representation. ```C# originalPlan.ToString() ``` -------------------------------- ### Initialize Qdrant Client Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/notebook.ipynb Initializes a Qdrant client instance connecting to a local Qdrant service on the default gRPC port. ```java QdrantClient qdrantClient = new QdrantClient(QdrantGrpcClient.newBuilder("localhost",6334,false).build()); ``` -------------------------------- ### Install OpenAI SDK for .NET Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/01/dotNETSDKAOAIDemo.ipynb Installs the necessary Azure OpenAI and Azure Identity NuGet packages for .NET development. These packages are essential for authenticating and interacting with Azure OpenAI services. ```C# #r "nuget: Azure.AI.OpenAI, *-*" #r "nuget: Azure.Identity,*-*" #r "nuget: Azure.Core,*-*" ``` -------------------------------- ### Import Qdrant Memory Store Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Imports the QdrantMemoryStore class for interacting with a Qdrant vector database. ```python from semantic_kernel.connectors.memory.qdrant import QdrantMemoryStore ``` -------------------------------- ### Semantic Kernel C# Prompt Template Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/03/PluginWithSK.ipynb Defines a system prompt template for a C# function within Semantic Kernel. This template guides the AI's behavior and includes a placeholder for user input. ```csharp string promptTemplate = @"System: You are a python developer 。 User:{{$input}}"; ``` -------------------------------- ### Semantic Kernel Usings Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/notebook.ipynb Imports essential namespaces for Semantic Kernel, Qdrant, and OpenAI connectors. ```csharp using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Embeddings; using Microsoft.SemanticKernel.Memory; using Microsoft.SemanticKernel.Connectors.Qdrant; using Microsoft.SemanticKernel.Connectors.OpenAI; ``` -------------------------------- ### Initialize Semantic Kernel and Azure OpenAI Settings Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Initializes the Semantic Kernel instance and retrieves Azure OpenAI deployment details, API key, and endpoint from environment variables. ```python kernel = sk.Kernel() deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env() ``` -------------------------------- ### Get Dressing Tips and Translate Source: https://github.com/microsoft/semantickernelcookbook/blob/main/plugins/WriterPlugin/Tips/skprompt.txt This C# code snippet shows how to use Semantic Kernel to generate dressing tips based on an input topic and then translate those tips into a target language. It utilizes prompt engineering to define the desired output format and language. ```C# using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Connectors.OpenAI; var kernel = Kernel.CreateBuilder() .AddOpenAIChatCompletion( modelId: "gpt-3.5-turbo", apiKey: "YOUR_API_KEY") .Build(); string inputTopic = "casual summer"; string targetLanguage = "French"; var prompt = $"Get dressing tips for {inputTopic} and translate them into {targetLanguage}."; var result = await kernel.InvokePromptAsync(prompt); Console.WriteLine(result); ``` -------------------------------- ### Displaying the Created Plan Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/04/PlannerWithSK.ipynb Prints the string representation of the created plan to the console. ```C# Console.WriteLine(originalPlan); ``` -------------------------------- ### Semantic Kernel Initialization with Azure OpenAI Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/04/PlannerWithSK.ipynb Initializes the Semantic Kernel with Azure OpenAI chat completion service. Requires deployment name, endpoint, and API key. ```C# Kernel kernel = Kernel.CreateBuilder() .AddAzureOpenAIChatCompletion("Your Azure OpenAI Service gpt-35-turbo-16k Deployment Name", "Your Azure OpenAI Service Endpoint", "Your Azure OpenAI Service API Key") .Build(); ``` -------------------------------- ### Create Prompt Template Configuration Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/03/PluginWithSK.ipynb Configures the prompt template with its name, format, input variables, and execution settings. ```python prompt_template_config = PromptTemplateConfig( template=prompt, name="summarize", template_format="semantic-kernel", input_variables=[ InputVariable(name="input", description="The user input", is_required=True), ], execution_settings=execution_settings, ) ``` -------------------------------- ### Creating a Plan with Handlebars Planner Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/04/PlannerWithSK.ipynb Creates a plan asynchronously using the HandlebarsPlanner based on the defined goal and the initialized kernel. Suppresses a specific SKEXP0060 warning. ```C# #pragma warning disable SKEXP0060 var originalPlan = await planner.CreatePlanAsync(kernel, goal); ``` -------------------------------- ### Import Answer Plugin Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Imports the 'AnswerPlugin' from the specified directory into the Semantic Kernel. ```python answer_plugin = kernel.import_semantic_skill_from_directory(base_plugin , "AnswerPlugin") ``` -------------------------------- ### Setup New .NET Console Project Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop3/dotNETAgent/plugins/CodePlugin/dotNET/skprompt.txt Generates a new .NET console application project in a specified directory. This command initializes the project structure required for a .NET application. ```bash dotnet new console -o {{projectName}} ``` -------------------------------- ### Handlebars Planner Initialization Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/04/PlannerWithSK.ipynb Initializes the HandlebarsPlanner, a planner that uses Handlebars templating for plan creation. Suppresses a specific SKEXP0060 warning. ```C# using Microsoft.SemanticKernel.Planning.Handlebars; #pragma warning disable SKEXP0060 var planner = new HandlebarsPlanner(); ``` -------------------------------- ### Select Summary Function from Plugin Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/notebook.ipynb Selects the 'Summary' function from the imported 'AnswerPlugin'. ```python answerFunc = answer_plugin["Summary"] ``` -------------------------------- ### Build Kernel with Chat Completion Service in Java Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/java/03/PluginWithSK.ipynb Initializes a Semantic Kernel builder and configures it with a chat completion service. ```java Builder kernelBuilder = Kernel.builder() .withAIService(ChatCompletionService.class, chatGenerationService); ``` -------------------------------- ### Initialize KB List Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/notebook.ipynb Initializes an empty list to store KB objects. ```csharp IList kbList = new List(); ``` -------------------------------- ### Import Semantic Kernel Libraries Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/03/PluginWithSK.ipynb Imports necessary classes and modules from the semantic-kernel library for AI and prompt management. ```python import semantic_kernel as sk import semantic_kernel.connectors.ai.open_ai as skaoai from semantic_kernel.connectors.ai.open_ai import AzureChatPromptExecutionSettings, OpenAIChatPromptExecutionSettings from semantic_kernel.prompt_template import InputVariable, PromptTemplateConfig ``` -------------------------------- ### Import System Namespaces Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/05/EmbeddingsWithSK.ipynb Imports essential .NET system namespaces for general programming tasks. ```csharp using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Net.Http; using System.Text.Json; using System.Threading.Tasks; ``` -------------------------------- ### System Usings Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/notebook.ipynb Imports standard .NET namespaces for system operations, file handling, and JSON serialization. ```csharp using System; using System.IO; using System.Text.Json; ``` -------------------------------- ### Initialize Kernel and Azure OpenAI Settings Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/03/FunctionCallWithSK.ipynb Initializes the Semantic Kernel and retrieves Azure OpenAI deployment, API key, and endpoint settings from environment variables. ```python kernel = sk.Kernel() deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env() ``` -------------------------------- ### Get Transcript Files Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/notebook.ipynb Retrieves all files from the './data/transcripts' directory. ```csharp DirectoryInfo transcriptsFolder = new DirectoryInfo(@"./data/transcripts"); FileInfo[] transcriptsFiles = transcriptsFolder.GetFiles(); ``` -------------------------------- ### Import Semantic Kernel Libraries Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/04/PlannerWithSK.ipynb Imports necessary modules from the semantic_kernel library, including core components, AI connectors (OpenAI, Azure OpenAI), and prompt template configurations. ```python import os import sys import semantic_kernel as sk import semantic_kernel.connectors.ai.open_ai as skaoai from semantic_kernel.connectors.ai.open_ai import AzureChatPromptExecutionSettings, OpenAIChatPromptExecutionSettings from semantic_kernel.prompt_template import InputVariable, PromptTemplateConfig ``` -------------------------------- ### Install .NET Azure OpenAI SDK Source: https://github.com/microsoft/semantickernelcookbook/blob/main/docs/en/01.UsingAzureOpenAIServiceWithSDK.md Installs the latest Azure.AI.OpenAI NuGet package for .NET. This package provides the necessary classes to interact with Azure OpenAI Service. ```csharp #r "nuget: Azure.AI.OpenAI, *-*" ``` -------------------------------- ### Get Summary Function from Answer Plugin Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Retrieves the 'Summary' function from the imported 'AnswerPlugin'. ```python answerFunc = answer_plugin["Summary"] ``` -------------------------------- ### Install and Run Qdrant Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/java/05/EmbeddingsWithSK.ipynb This snippet shows how to pull the Qdrant Docker image and run it, mounting a local directory for persistent storage. ```bash docker pull qdrant/qdrant docker run -p 6333:6333 -p 6334:6334 \ -v $(pwd)/qdrant_storage:/qdrant/storage:z \ qdrant/qdrant ``` -------------------------------- ### Get Translation Result (C#) Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/02/LearnSK.ipynb Retrieves the string result from the asynchronous operation of invoking a Semantic Kernel function. This is typically the translated text. ```csharp transalteContent.GetValue() ``` -------------------------------- ### Initialize Kernel and Add Azure Chat Service Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/03/PluginWithSK.ipynb Initializes the Semantic Kernel and adds an Azure OpenAI chat completion service using environment variables for configuration. ```python service_id = "default" kernel = sk.Kernel() kernel.add_service( skaoai.AzureChatCompletion( service_id=service_id, env_file_path=".env" ), ) ``` -------------------------------- ### Scikit-learn User Guide Reference Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/data/notes/03-techniques-ml.md Provides a reference to the Scikit-learn user guide for exploring various model training methods and techniques. This is crucial for understanding different algorithms and their applications. ```APIDOC Scikit-learn User Guide: URL: https://scikit-learn.org/stable/user_guide.html Description: Comprehensive documentation for Scikit-learn, covering algorithms, preprocessing, model selection, and evaluation. Key Sections: - "Estimator basics": Understanding the API of estimators. - "Preprocessing data": Techniques for scaling, encoding, and imputation. - "Model selection": Cross-validation, hyperparameter tuning, and metrics. - "Supervised learning": Algorithms like regression, classification, and clustering. - "Unsupervised learning": Algorithms like dimensionality reduction and clustering. ``` -------------------------------- ### Scikit-learn User Guide Reference Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notes/03-techniques-ml.md Provides a reference to the Scikit-learn user guide for exploring various model training methods and techniques. This is crucial for understanding different algorithms and their applications. ```APIDOC Scikit-learn User Guide: URL: https://scikit-learn.org/stable/user_guide.html Description: Comprehensive documentation for Scikit-learn, covering algorithms, preprocessing, model selection, and evaluation. Key Sections: - "Estimator basics": Understanding the API of estimators. - "Preprocessing data": Techniques for scaling, encoding, and imputation. - "Model selection": Cross-validation, hyperparameter tuning, and metrics. - "Supervised learning": Algorithms like regression, classification, and clustering. - "Unsupervised learning": Algorithms like dimensionality reduction and clustering. ``` -------------------------------- ### Scikit-learn User Guide Reference Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/data/notes/03-techniques-ml.md Provides a reference to the Scikit-learn user guide for exploring various model training methods and techniques. This is crucial for understanding different algorithms and their applications. ```APIDOC Scikit-learn User Guide: URL: https://scikit-learn.org/stable/user_guide.html Description: Comprehensive documentation for Scikit-learn, covering algorithms, preprocessing, model selection, and evaluation. Key Sections: - "Estimator basics": Understanding the API of estimators. - "Preprocessing data": Techniques for scaling, encoding, and imputation. - "Model selection": Cross-validation, hyperparameter tuning, and metrics. - "Supervised learning": Algorithms like regression, classification, and clustering. - "Unsupervised learning": Algorithms like dimensionality reduction and clustering. ``` -------------------------------- ### Display KB List Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/notebook.ipynb Outputs the current content of the kbList. ```csharp kbList ``` -------------------------------- ### Semantic Kernel Core and Agent Usings Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop3/dotNETAgent/SKAIAgent.ipynb Imports essential namespaces from the Semantic Kernel library for agent creation, configuration, and OpenAI connectors. ```C# using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Experimental.Agents; using Microsoft.SemanticKernel.Connectors.OpenAI; ``` -------------------------------- ### Get Available Functions Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/03/FunctionCallWithSK.ipynb Retrieves a list of available functions from the kernel, optionally filtering out specific skills. This prepares the kernel to use functions for completion. ```python filter = {"exclude_skill": ["ChatBot"]} functions = get_function_calling_object(kernel, filter) ``` -------------------------------- ### Install and Run Qdrant Docker Container Source: https://github.com/microsoft/semantickernelcookbook/blob/main/docs/cn/05.Embeddings.md Commands to pull the Qdrant Docker image and run a Qdrant container locally. ```Bash docker pull qdrant/qdrant docker run -p 6333:6333 qdrant/qdrant ``` -------------------------------- ### Import File Plugin Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Imports the 'FilePlugin' from the specified directory into the Semantic Kernel. ```python files_plugin = kernel.import_semantic_skill_from_directory(base_plugin , "FilePlugin") ``` -------------------------------- ### Java: Basic Prompt Execution Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop2/genppt_notebook.ipynb Shows how to initialize a Semantic Kernel instance, define a prompt, and execute a semantic function in Java. This example is essential for Java developers new to the SDK. ```Java import com.microsoft.semantickernel.Kernel; Kernel kernel = Kernel.builder().build(); // Load a prompt from a file or string String prompt = "Write a short poem about a {subject}."; // Create a semantic function var poemFunction = kernel.createFunctionFromPrompt(prompt); // Invoke the function var result = kernel.invokeAsync(poemFunction, java.util.Map.of("subject", "a gentle breeze")).block(); System.out.println(result); ``` -------------------------------- ### LINQ and Task Usings Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop3/dotNETAgent/SKAIAgent.ipynb Imports namespaces for Language Integrated Query (LINQ) and asynchronous programming patterns using Tasks. ```C# using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; ``` -------------------------------- ### List Data Files Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Retrieves lists of files from the './data/notes' and './data/transcripts' directories. ```python nodes_files = os.listdir("./data/notes") transcripts_files = os.listdir("./data/transcripts") ``` -------------------------------- ### Semantic Kernel NuGet Package References Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/04/PlannerWithSK.ipynb Specifies the NuGet packages required for Semantic Kernel and its Handlebars planner integration. ```C# #r "nuget: Microsoft.SemanticKernel, *-*" #r "nuget: Microsoft.SemanticKernel.Planners.Handlebars, *-*" ``` -------------------------------- ### Semantic Kernel Core Concepts Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/plugins/AnswerPlugin/Summary/skprompt.txt Demonstrates fundamental concepts of the Semantic Kernel, including creating a kernel, loading plugins, and invoking functions. Essential for understanding the basic building blocks of the framework. ```csharp using Microsoft.SemanticKernel; // Initialize the kernel var kernel = Kernel.CreateBuilder().Build(); // Load a plugin (e.g., from a directory) // kernel.ImportPluginFromPromptDirectory("Plugins", "MySkill"); // Invoke a function // var result = await kernel.InvokeAsync("MySkill", "MyFunction", new() { ["input"] = "Hello" }); // Console.WriteLine(result); ``` -------------------------------- ### Initialize Semantic Kernel Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/04/PlannerWithSK.ipynb Initializes an instance of the Semantic Kernel, which serves as the central orchestrator for AI operations. ```python kernel = sk.Kernel() ``` -------------------------------- ### Semantic Kernel Core Concepts Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/plugins/AnswerPlugin/Summary/skprompt.txt Demonstrates fundamental concepts of the Semantic Kernel, including creating a kernel, loading plugins, and invoking functions. Essential for understanding the basic building blocks of the framework. ```python from semantic_kernel import Kernel # Initialize the kernel kernel = Kernel() # Load a plugin (e.g., from a directory) # kernel.import_semantic_skill_from_directory("plugins", "MySkill") # Invoke a function # result = await kernel.run_async("MySkill", "MyFunction", input_str="Hello") # print(result) ``` -------------------------------- ### Load Plugin from Directory (C#) Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/02/LearnSK.ipynb Creates a Semantic Kernel plugin instance by loading it from a specified directory. Assumes the directory contains a valid plugin structure. ```csharp var plugin = kernel.CreatePluginFromPromptDirectory(Path.Combine(pluginDirectory, "TranslatePlugin")); ``` -------------------------------- ### Importing Plugins from Prompt Directory Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/04/PlannerWithSK.ipynb Imports plugins from specified directories within the plugin directory. This allows loading plugins defined by prompt templates. ```C# var writetPlugin = kernel.ImportPluginFromPromptDirectory(Path.Combine(pluginDirectory, "WriterPlugin")); var emailPlugin = kernel.ImportPluginFromPromptDirectory(Path.Combine(pluginDirectory, "EmailPlugin")); var translatePlugin = kernel.ImportPluginFromPromptDirectory(Path.Combine(pluginDirectory, "TranslatePlugin")); ``` -------------------------------- ### Kernel Initialization with Azure OpenAI Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/notebook.ipynb Initializes the Semantic Kernel with Azure OpenAI chat completion service, requiring deployment name, endpoint, and API key. ```csharp Kernel kernel = Kernel.CreateBuilder() .AddAzureOpenAIChatCompletion("Your Azure OpenAI Service Deployment Name" , "Your Azure OpenAI Service Endpoint", "Your Azure OpenAI Service API Key") .Build(); ``` -------------------------------- ### Initialize Qdrant Memory Store and Collection Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/05/EmbeddingsWithSK.ipynb Initializes a Qdrant memory store and creates a collection named 'aboutMe'. This sets up the persistent storage for semantic data. ```python qdrant_store = QdrantMemoryStore(vector_size=1536, url="http://localhost",port=6333) await qdrant_store.create_collection('aboutMe') ``` -------------------------------- ### Define Prompt Template Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/03/PluginWithSK.ipynb Creates a prompt template string with a system message and a user input variable. ```python prompt = "System: You are a python developer 。 User:{{$input}}" ``` -------------------------------- ### Import Semantic Kernel and Connectors Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/02/LearnSK.ipynb Imports the core Semantic Kernel library and its connectors for AI services, specifically focusing on OpenAI. ```python import semantic_kernel as sk import semantic_kernel.connectors.ai.open_ai as skaoai ``` -------------------------------- ### Semantic Kernel Core Concepts Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/plugins/AnswerPlugin/Summary/skprompt.txt Demonstrates fundamental concepts of the Semantic Kernel, including creating a kernel, loading plugins, and invoking functions. Essential for understanding the basic building blocks of the framework. ```csharp using Microsoft.SemanticKernel; // Initialize the kernel var kernel = Kernel.CreateBuilder().Build(); // Load a plugin (e.g., from a directory) // kernel.ImportPluginFromPromptDirectory("Plugins", "MySkill"); // Invoke a function // var result = await kernel.InvokeAsync("MySkill", "MyFunction", new() { ["input"] = "Hello" }); // Console.WriteLine(result); ``` -------------------------------- ### Initialize Kernel Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/02/LearnSK.ipynb Initializes a new instance of the Semantic Kernel. This object serves as the central point for orchestrating AI capabilities. ```python kernel = sk.Kernel() ``` -------------------------------- ### DALL-E Features and Applications Source: https://github.com/microsoft/semantickernelcookbook/blob/main/docs/en/00.IntroduceLLM.md DALL-E, specifically DALL-E 3, is an AI model that generates images from text descriptions. It is known for its creativity, flexibility, and ability to produce detailed and varied image styles. DALL-E has applications in artistic creation, advertising, media, education, and research. ```en Text to Image Conversion: Generates images based on user-provided text descriptions. Creativity and Flexibility: Combines concepts to create unique visual works. Variety and Detail: Produces multiple styles and handles complex, detailed descriptions. Application Potential: - Artistic Creation: Exploring new ideas and visual expressions. - Advertising and Media: Generating theme-specific images. - Education and Entertainment: Creating instructional or entertainment content. - Research and Exploration: Investigating AI in visual arts. ``` -------------------------------- ### Load and Import Plugins Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/04/PlannerWithSK.ipynb Loads and imports various plugins (custom, writer, email, translate) into the Semantic Kernel. It demonstrates both importing native plugins and semantic plugins from specified directories. ```python #custom_plugin = kernel.import_native_skill_from_directory(base_skills_directory , "APIPlugin") # custom_plugin = kernel.import_plugin(custom_plugin.CustomPlugin(), plugin_name="CustomPlugin") #.import_native_skill_from_directory(base_plugin , "APIPlugin") # writer_plugin = kernel.import_semantic_plugin_from_directory(base_skills_directory, "WriterPlugin") # email_plugin = kernel.import_semantic_plugin_from_directory(base_skills_directory, "EmailPlugin") # translate_plugin = kernel.import_semantic_plugin_from_directory(base_skills_directory, "TranslatePlugin") custom_plugin = kernel.add_plugin(custom_plugin.CustomPlugin(), "CustomPlugin") writer_plugin = kernel.add_plugin(parent_directory=base_skills_directory,plugin_name ="WriterPlugin") email_plugin = kernel.add_plugin(parent_directory=base_skills_directory,plugin_name ="EmailPlugin") translate_plugin = kernel.add_plugin(parent_directory=base_skills_directory,plugin_name ="TranslatePlugin") ``` -------------------------------- ### Register Memory Store with Kernel Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Registers the initialized Qdrant memory store with the Semantic Kernel instance. ```python kernel.register_memory_store(memory_store=qdrant_store) ``` -------------------------------- ### Semantic Kernel Core Concepts Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/plugins/AnswerPlugin/Summary/skprompt.txt Demonstrates fundamental concepts of the Semantic Kernel, including creating a kernel, loading plugins, and invoking functions. Essential for understanding the basic building blocks of the framework. ```java import com.microsoft.semantickernel.Kernel; // Initialize the kernel Kernel kernel = Kernel.builder().build(); // Load a plugin (e.g., from a directory) // kernel.importSemanticSkillFromDirectory("plugins", "MySkill"); // Invoke a function // var result = kernel.invoke("MySkill", "MyFunction", "Hello"); // System.out.println(result); ``` -------------------------------- ### GPT-4V Capabilities Source: https://github.com/microsoft/semantickernelcookbook/blob/main/docs/en/00.IntroduceLLM.md GPT-4 Turbo with Vision (GPT-4V) is an advanced multimodal model capable of understanding and analyzing images. It excels at object detection, text recognition (OCR), face recognition, solving CAPTCHAs, and geolocation. However, it may struggle with complex scientific diagrams or images with overlapping text. ```en Object Detection: Identifies common objects like cars, animals, and household items. Text Recognition: Extracts printed or handwritten text from images (OCR). Face Recognition: Detects and analyzes facial features, including gender, age, and racial attributes. CAPTCHA Solving: Solves text- and image-based CAPTCHAs, demonstrating visual reasoning. Geolocation: Identifies geographical locations from landscape images. Limitations: Performs poorly on complex scientific diagrams, medical scans, or images with multiple overlapping text components. ``` -------------------------------- ### Semantic Kernel Core Concepts Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/plugins/AnswerPlugin/Summary/skprompt.txt Demonstrates fundamental concepts of the Semantic Kernel, including creating a kernel, loading plugins, and invoking functions. Essential for understanding the basic building blocks of the framework. ```java import com.microsoft.semantickernel.Kernel; // Initialize the kernel Kernel kernel = Kernel.builder().build(); // Load a plugin (e.g., from a directory) // kernel.importSemanticSkillFromDirectory("plugins", "MySkill"); // Invoke a function // var result = kernel.invoke("MySkill", "MyFunction", "Hello"); // System.out.println(result); ``` -------------------------------- ### Import Custom Plugin Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/04/PlannerWithSK.ipynb Imports a custom plugin into the Semantic Kernel. This example shows importing a plugin defined in a local Python file. ```python import APIPlugin.CustomPlugin as custom_plugin ``` -------------------------------- ### Initializing Sequential Planner Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/java/04/PlannerWithSK.ipynb This Java code initializes a `SequentialPlanner` with a given `Kernel` instance and specific `SequentialPlannerRequestSettings`. The planner is used to create execution plans for AI tasks. ```Java private static SequentialPlanner initPlanner(Kernel kernel, int maxTokens) { return new SequentialPlanner(kernel, new SequentialPlannerRequestSettings( null, 100, ``` -------------------------------- ### Qdrant VectorParams Import Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/notebook.ipynb Imports the VectorParams class for configuring vector storage in Qdrant. ```java import io.qdrant.client.grpc.Collections.VectorParams; ``` -------------------------------- ### Install Python OpenAI SDK Source: https://github.com/microsoft/semantickernelcookbook/blob/main/docs/en/01.UsingAzureOpenAIServiceWithSDK.md Installs or upgrades the OpenAI Python SDK to the latest version. This is a prerequisite for using the OpenAI Python client. ```python ! pip install openai -U ``` -------------------------------- ### Semantic Kernel Core Concepts Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/plugins/AnswerPlugin/Summary/skprompt.txt Demonstrates fundamental concepts of the Semantic Kernel, including creating a kernel, loading plugins, and invoking functions. Essential for understanding the basic building blocks of the framework. ```python from semantic_kernel import Kernel # Initialize the kernel kernel = Kernel() # Load a plugin (e.g., from a directory) # kernel.import_semantic_skill_from_directory("plugins", "MySkill") # Invoke a function # result = await kernel.run_async("MySkill", "MyFunction", input_str="Hello") # print(result) ``` -------------------------------- ### Define Plugin Directory Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Specifies the base directory where Semantic Kernel plugins are located. ```python base_plugin = "./plugins" ``` -------------------------------- ### Initialize Semantic Text Memory Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/notebook.ipynb Initializes SemanticTextMemory, linking the Qdrant storage with the previously configured embedding generator. ```python memory = SemanticTextMemory(storage=qdrant_store, embeddings_generator=embedding_gen) ``` -------------------------------- ### Importing Sequential Planner Libraries Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/java/04/PlannerWithSK.ipynb This snippet imports necessary classes for using the Sequential Planner in Semantic Kernel, including `SequentialPlanner` and `SequentialPlannerRequestSettings`. ```Java import com.microsoft.semantickernel.planner.sequentialplanner.SequentialPlanner; import com.microsoft.semantickernel.planner.sequentialplanner.SequentialPlannerRequestSettings; ``` -------------------------------- ### Run .NET Project Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop3/dotNETAgent/plugins/CodePlugin/dotNET/skprompt.txt Executes a .NET project. This command builds the project if necessary and then runs the compiled output. ```bash dotnet run --project ./{{projectName}} ``` -------------------------------- ### Initialize Knowledge Base List Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/notebook.ipynb Initializes an empty list that will be used to store processed data from files. ```python kblist = [] ``` -------------------------------- ### Print Plan Steps Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/04/PlannerWithSK.ipynb Iterates through the steps of a generated plan and prints a description of each step, including the function it uses and its parameters. This helps in understanding the execution flow. ```python for step in original_plan._steps: print( f"- {step.description.replace('.', '') if step.description else 'No description'} using {step.metadata.fully_qualified_name} with parameters: {step.parameters}" ) ``` -------------------------------- ### Semantic Kernel: Orchestration (C#) Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/plugins/AnswerPlugin/Summary/skprompt.txt Demonstrates orchestration in Semantic Kernel using C#. This example shows how to define a sequence of operations and execute them as a plan. ```csharp using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Orchestration; var kernel = Kernel.CreateBuilder().Build(); // Define functions (e.g., summarize, translate) kernel.ImportPluginFromFunctions( new[] { kernel.CreateFunctionFromPrompt("Summarize: {{$input}}", description: "Summarize the input text."), kernel.CreateFunctionFromPrompt("Translate to French: {{$input}}", description: "Translate the input text to French.") }, pluginName: "MyFunctions" ); // Create a plan var plan = kernel.CreateNewPlan(); plan.AddFunction("MyFunctions", "Summarize"); plan.AddFunction("MyFunctions", "Translate"); // Execute the plan var context = new ContextVariables("This is a long piece of text that needs to be summarized and translated."); var result = await kernel.RunAsync(plan, context); Console.WriteLine(result); ``` -------------------------------- ### Install OpenAI Python SDK Source: https://github.com/microsoft/semantickernelcookbook/blob/main/docs/cn/01.UsingAzureOpenAIServiceWithSDK.md Installs the latest version of the OpenAI Python SDK, which is used to interact with both OpenAI and Azure OpenAI Service. ```python ! pip install openai -U ``` -------------------------------- ### Create Formatted KB List Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/notebook.ipynb Creates a new list of strings where each string is a concatenation of 'kb' and 'content' from the KBInfo objects. ```java List kbResultList = new ArrayList(); for (KBInfo info : kbList) { kbResultList.add(info.kb+"-"+info.content); } ``` -------------------------------- ### Defining Plugin Directory Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/dotNET/04/PlannerWithSK.ipynb Specifies the relative path to the directory containing Semantic Kernel plugins. ```C# var pluginDirectory = Path.Combine("../../..", "plugins"); ``` -------------------------------- ### Initialize Knowledge Base List Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/dotNET/workshop1/data/notebook.ipynb Initializes an empty list to store processed data for the knowledge base. ```python kblist = [] ``` -------------------------------- ### Initialize Semantic Kernel and AI Services Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/05/EmbeddingsWithSK.ipynb Initializes the Semantic Kernel and configures Azure OpenAI chat and embedding services. It demonstrates how to add these services to the kernel instance. ```python kernel = sk.Kernel() chat_service_id = "default" embed_service_id="embedding" oai_chat_service = AzureChatCompletion( service_id=chat_service_id, env_file_path=".env" ) embedding_gen = AzureTextEmbedding( service_id=embed_service_id, env_file_path=".env" ) kernel.add_service(oai_chat_service) kernel.add_service(embedding_gen) # kernel.add_chat_service("azure_chat_competion_service", AzureChatCompletion("Your Azure OpenAI Service gpt-35-turbo-16k Model Delployment Name",endpoint,api_key=api_key,api_version = "2023-12-01-preview")) # kernel.add_text_embedding_generation_service( # "embeddings_services", AzureTextEmbedding("Your Azure OpenAI Service text-embedding-ada-002 Model Delployment Name", endpoint,api_key=api_key,api_version = "2023-12-01-preview") # ) ``` -------------------------------- ### Initialize Sequential Planner Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/04/PlannerWithSK.ipynb Creates an instance of the SequentialPlanner, which is used to create plans for executing a series of AI tasks. It requires the initialized Kernel and a service ID. ```python from semantic_kernel.planners import SequentialPlanner planner = SequentialPlanner(kernel, service_id) ``` -------------------------------- ### skprompt.txt Example Source: https://github.com/microsoft/semantickernelcookbook/blob/main/docs/en/03.Plugins.md Defines a prompt template for a plugin, specifying input parameters using double curly braces. ```txt Translate {{$input}} into {{$language}} ``` -------------------------------- ### Semantic Kernel Core Concepts Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/java/workshop1/plugins/AnswerPlugin/Summary/skprompt.txt Demonstrates fundamental concepts of the Semantic Kernel, including creating a kernel, loading plugins, and invoking functions. Essential for understanding the basic building blocks of the framework. ```typescript import { Kernel } from "@microsoft/semantic-kernel"; // Initialize the kernel const kernel = new Kernel(); // Load a plugin (e.g., from a directory) // await kernel.importSemanticSkillFromDirectory("plugins", "MySkill"); // Invoke a function // const result = await kernel.invoke("MySkill", "MyFunction", { input: "Hello" }); // console.log(result); ``` -------------------------------- ### Define Function Tools for AI Source: https://github.com/microsoft/semantickernelcookbook/blob/main/notebooks/python/03/FunctionCallWithSK.ipynb Defines a list of tools (functions) that the AI model can use, including their names, descriptions, and parameters. This example defines a 'search_hotels' function. ```python tools = [ { "type": "function", "function": { "name": "search_hotels", "description": "Retrieves hotels from the search index based on the parameters provided", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The location of the hotel (i.e. Seattle, WA)" }, "max_price": { "type": "number", "description": "The maximum price for the hotel" }, "features": { "type": "string", "description": "A comma separated list of features (i.e. beachfront, free wifi, etc.)" } }, "required": ["location"] } }, } ] ``` -------------------------------- ### Initialize Semantic Kernel and Azure OpenAI Settings Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop1/notebook.ipynb Initializes the Semantic Kernel instance and retrieves Azure OpenAI service settings (deployment name, API key, endpoint) from environment variables. ```python kernel = sk.Kernel() deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env() ``` -------------------------------- ### Convert Markdown to PPTX using Marp Source: https://github.com/microsoft/semantickernelcookbook/blob/main/workshop/python/workshop2/genppt_notebook.ipynb Uses the Marp CLI tool to convert the 'myfile.md' Markdown file into a PowerPoint presentation ('myfile.pptx'). ```bash ! marp myfile.md -o myfile.pptx ```