This section contains code snippets that demonstrate the usage of Semantic Kernel features.
| Features | Description |
|---|---|
| Agents | Creating and using agents in Semantic Kernel |
| Audio | Using services that support audio-to-text and text-to-audio conversion |
| AutoFunctionCalling | Using Auto Function Calling to allow function call capable models to invoke Kernel Functions automatically |
| ChatCompletion | Using ChatCompletion messaging capable service with models |
| ChatHistory | Using and serializing the ChatHistory |
| Filtering | Creating and using Filters |
| Functions | Invoking Method or Prompt functions with Kernel |
| Grounding | An example of how to perform LLM grounding |
| Local Models | Using the OpenAI connector and OnnxGenAI connector to talk to models hosted locally in Ollama, OnnxGenAI and LM Studio |
| Logging | Showing how to set up logging |
| Memory | Using Memory AI concepts |
| Model-as-a-Service | Using models deployed as serverless APIs on Azure AI Studio to benchmark model performance against open-source datasets |
| On Your Data | Examples of using AzureOpenAI On Your Data |
| Planners | Showing the uses of Planners |
| Plugins | Different ways of creating and using Plugins |
| PromptTemplates | Using Templates with parametrization for Prompt rendering |
| RAG | Different ways of RAG (Retrieval-Augmented Generation) |
| Search | Using search services information |
| Service Selector | Shows how to create and use a custom service selector class. |
| Setup | How to setup environment variables for Semantic Kernel |
| <<<<<<< HEAD | |
| <<<<<<< div | |
| ======= | |
| <<<<<<< Updated upstream | |
| <<<<<<< Updated upstream |
head <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream ======= ======= Stashed changes ======= Stashed changes ======= Stashed changes ======= Stashed changes ======= Stashed changes <<<<<<< HEAD ======= | Structured Output | How to leverage OpenAI's json_schema structured output functionality. | main <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream Stashed changes ======= Stashed changes ======= Stashed changes ======= Stashed changes ======= Stashed changes ======= Stashed changes ======= | Structured Output | How to leverage OpenAI's json_schema structured output functionality. | eab985c52d058dc92abc75034bc790079131ce75 <<<<<<< div ======= ======= ======= | Structured Output | How to leverage OpenAI's json_schema structured output functionality. | main Stashed changes ======= ======= | Structured Output | How to leverage OpenAI's json_schema structured output functionality. | main Stashed changes head | TextGeneration | Using
TextGenerationcapable service with models |
In Semantic Kernel for Python, we leverage Pydantic Settings to manage configurations for AI and Memory Connectors, among other components. Here’s a clear guide on how to configure your settings effectively:
-
Reading Environment Variables:
- Primary Source: Pydantic first attempts to read the required settings from environment variables.
-
Using a .env File:
- Fallback Source: If the required environment variables are not set, Pydantic will look for a
.envfile in the current working directory. - Custom Path (Optional): You can specify an alternative path for the
.envfile viaenv_file_path. This can be either a relative or an absolute path.
- Fallback Source: If the required environment variables are not set, Pydantic will look for a
-
Direct Constructor Input:
- As an alternative to environment variables and
.envfiles, you can pass the required settings directly through the constructor of the AI Connector or Memory Connector.
- As an alternative to environment variables and
<<<<<<< Updated upstream <<<<<<< Updated upstream
head <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream ======= ======= Stashed changes ======= Stashed changes ======= Stashed changes ======= Stashed changes ======= Stashed changes <<<<<<< HEAD ======= ======= eab985c52d058dc92abc75034bc790079131ce75 <<<<<<< div ======= ======= ======= Stashed changes ======= ======= Stashed changes head
To authenticate to your Azure resources using a Microsoft Entra Authentication Token, the AzureChatCompletion AI Service connector now supports this as a built-in feature. If you do not provide an API key -- either through an environment variable, a .env file, or the constructor -- and you also do not provide a custom AsyncAzureOpenAI client, an ad_token, or an ad_token_provider, the AzureChatCompletion connector will attempt to retrieve a token using the DefaultAzureCredential.
To successfully retrieve and use the Entra Auth Token, you need the Cognitive Services OpenAI Contributor role assigned to your Azure OpenAI resource. By default, the https://cognitiveservices.azure.com token endpoint is used. You can override this endpoint by setting an environment variable .env variable as AZURE_OPENAI_TOKEN_ENDPOINT or by passing a new value to the AzureChatCompletion constructor as part of the AzureOpenAISettings.
<<<<<<< Updated upstream <<<<<<< Updated upstream
head <<<<<<< HEAD main <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream Stashed changes ======= Stashed changes ======= Stashed changes ======= Stashed changes ======= Stashed changes ======= Stashed changes ======= eab985c52d058dc92abc75034bc790079131ce75 <<<<<<< div ======= ======= main Stashed changes ======= main Stashed changes head
- .env File Placement: We highly recommend placing the
.envfile in thesemantic-kernel/pythonroot directory. This is a common practice when developing in the Semantic Kernel repository.
By following these guidelines, you can ensure that your settings for various components are configured correctly, enabling seamless functionality and integration of Semantic Kernel in your Python projects.