You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ai/ai-extensions.md
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ ms.author: alexwolf
10
10
11
11
# Unified AI building blocks for .NET using Microsoft.Extensions.AI
12
12
13
-
The .NET ecosystem provides abstractions for integrating AI services into .NET applications and libraries using the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI) and [`Microsoft.Extensions.AI.Abstractions`](https://www.nuget.org/packages/Microsoft.Extensions.AI.Abstractions) libraries. The .NET team also enhanced the core `Microsoft.Extensions.*` libraries with these abstractions for .NET Generative AI applications and libraries. In the sections ahead, you learn:
13
+
The .NET ecosystem provides abstractions for integrating AI services into .NET applications and libraries using the <xref:Microsoft.Extensions.AI> and [`Microsoft.Extensions.AI.Abstractions`](https://www.nuget.org/packages/Microsoft.Extensions.AI.Abstractions) libraries. The .NET team also enhanced the core `Microsoft.Extensions.*` libraries with these abstractions for .NET generative AI applications and libraries. In the sections ahead, you learn:
14
14
15
15
- Core concepts and capabilities of the `Microsoft.Extensions.AI` libraries.
16
16
- How to work with AI abstractions in your apps and the benefits they offer.
@@ -20,7 +20,7 @@ For more information, see [Introduction to Microsoft.Extensions.AI](../core/exte
20
20
21
21
## What is the Microsoft.Extensions.AI library?
22
22
23
-
`Microsoft.Extensions.AI` is a set of core .NET libraries created in collaboration with developers across the .NET ecosystem, including Semantic Kernel. These libraries provide a unified layer of C# abstractions for interacting with AI services, such as small and large language models (SLMs and LLMs), embeddings, and middleware.
23
+
<xref:Microsoft.Extensions.AI> is a set of core .NET libraries created in collaboration with developers across the .NET ecosystem, including Semantic Kernel. These libraries provide a unified layer of C# abstractions for interacting with AI services, such as small and large language models (SLMs and LLMs), embeddings, and middleware.
24
24
25
25
:::image type="content" source="media/ai-extensions/meai-architecture-diagram.png" lightbox="media/ai-extensions/meai-architecture-diagram.png" alt-text="An architectural diagram of the AI extensions libraries.":::
26
26
@@ -40,18 +40,18 @@ For example, the `IChatClient` interface allows consumption of language models f
40
40
41
41
```csharp
42
42
IChatClientclient=
43
-
environment.IsDevelopment?
44
-
newOllamaChatClient(...) :
45
-
newAzureAIInferenceChatClient(...);
43
+
environment.IsDevelopment?
44
+
newOllamaChatClient(...) :
45
+
newAzureAIInferenceChatClient(...);
46
46
```
47
47
48
48
Then, regardless of the provider you're using, you can send requests as follows:
49
49
50
50
```csharp
51
-
varresponse=awaitchatClient.CompleteAsync(
52
-
"Translate the following text into Pig Latin: I love .NET and AI");
51
+
varresponse=awaitchatClient.CompleteAsync(
52
+
"Translate the following text into Pig Latin: I love .NET and AI");
53
53
54
-
Console.WriteLine(response.Message);
54
+
Console.WriteLine(response.Message);
55
55
```
56
56
57
57
These abstractions allow for idiomatic C# code for various scenarios with minimal code changes, whether you're using different services for development and production, addressing hybrid scenarios, or exploring other service providers.
@@ -69,17 +69,17 @@ In the future, implementations of these `Microsoft.Extensions.AI` abstractions w
69
69
70
70
## Middleware implementations for AI services
71
71
72
-
Connecting to and using AI services is just one aspect of building robust applications. Production-ready applications require additional features like telemetry, logging, and toolcalling capabilities. The `Microsoft.Extensions.AI` abstractions enable you to easily integrate these components into your applications using familiar patterns.
72
+
Connecting to and using AI services is just one aspect of building robust applications. Production-ready applications require additional features like telemetry, logging, and tool-calling capabilities. The `Microsoft.Extensions.AI` abstractions enable you to easily integrate these components into your applications using familiar patterns.
73
73
74
74
The following sample demonstrates how to register an OpenAI `IChatClient`. `IChatClient` allows you to attach the capabilities in a consistent way across various providers.
75
75
76
76
```csharp
77
-
app.Services.AddChatClient(builder=>builder
77
+
app.Services.AddChatClient(builder=>builder
78
78
.UseLogging()
79
-
.UseFunctionInvocation()
80
-
.UseDistributedCache()
81
-
.UseOpenTelemetry()
82
-
.Use(newOpenAIClient(...)).AsChatClient(...));
79
+
.UseFunctionInvocation()
80
+
.UseDistributedCache()
81
+
.UseOpenTelemetry()
82
+
.Use(newOpenAIClient(...)).AsChatClient(...));
83
83
```
84
84
85
85
The capabilities demonstrated in this snippet are included in the `Microsoft.Extensions.AI` library, but they are only a small subset of the capabilities that can be layered in with this approach. .NET developers are able to expose many types of middleware to create powerful AI functionality.
@@ -92,6 +92,7 @@ You can start building with `Microsoft.Extensions.AI` in the following ways:
92
92
-**Service Consumers**: If you're developing libraries that consume AI services, use the abstractions instead of hardcoding to a specific AI service. This approach gives your consumers the flexibility to choose their preferred service.
93
93
-**Application Developers**: Use the abstractions to simplify integration into your apps. This enables portability across models and services, facilitates testing and mocking, leverages middleware provided by the ecosystem, and maintains a consistent API throughout your app, even if you use different services in different parts of your application.
94
94
-**Ecosystem Contributors**: If you're interested in contributing to the ecosystem, consider writing custom middleware components.
95
+
95
96
To get started, see the samples in the [dotnet/ai-samples](https://aka.ms/meai-samples) GitHub repository.
96
97
97
98
For an end-to-end sample using `Microsoft.Extensions.AI`, see [eShopSupport](https://github.com/dotnet/eShopSupport).
Copy file name to clipboardExpand all lines: docs/ai/azure-ai-services-authentication.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ var kernel = builder.Build();
36
36
37
37
Using keys is a straightforward option, but this approach should be used with caution. Keys aren't the recommended authentication option because they:
38
38
39
-
- Don't follow [the principle of least privilege](/entra/identity-platform/secure-least-privileged-access)—they provide elevated permissions regardless of who uses them or for what task.
39
+
- Don't follow [the principle of least privilege](/entra/identity-platform/secure-least-privileged-access). They provide elevated permissions regardless of who uses them or for what task.
40
40
- Can accidentally be checked into source control or stored in unsafe locations.
41
41
- Can easily be shared with or sent to parties who shouldn't have access.
42
42
- Often require manual administration and rotation.
@@ -47,19 +47,21 @@ Instead, consider using [Microsoft Entra ID](/#explore-microsoft-entra-id) for a
47
47
48
48
Microsoft Entra ID is a cloud-based identity and access management service that provides a vast set of features for different business and app scenarios. Microsoft Entra ID is the recommended solution to connect to Azure OpenAI and other AI services and provides the following benefits:
49
49
50
-
-Key-less authentication using [identities](/entra/fundamentals/identity-fundamental-concepts).
51
-
- Role-based-access-control (RBAC) to assign identities the minimum required permissions.
50
+
-Keyless authentication using [identities](/entra/fundamentals/identity-fundamental-concepts).
51
+
- Role-basedaccesscontrol (RBAC) to assign identities the minimum required permissions.
52
52
- Can use the [`Azure.Identity`](/dotnet/api/overview/azure/identity-readme) client library to detect [different credentials across environments](/dotnet/api/azure.identity.defaultazurecredential) without requiring code changes.
53
53
- Automatically handles administrative maintenance tasks such as rotating underlying keys.
54
54
55
-
The workflow to implement Microsoft Entra authentication in your app generally includes the following:
55
+
The workflow to implement Microsoft Entra authentication in your app generally includes the following steps:
56
56
57
57
- Local development:
58
+
58
59
1. Sign-in to Azure using a local dev tool such as the Azure CLI or Visual Studio.
59
60
1. Configure your code to use the [`Azure.Identity`](/dotnet/api/overview/azure/identity-readme) client library and `DefaultAzureCredential` class.
60
61
1. Assign Azure roles to the account you signed-in with to enable access to the AI service.
61
62
62
63
- Azure-hosted app:
64
+
63
65
1. Deploy the app to Azure after configuring it to authenticate using the `Azure.Identity` client library.
64
66
1. Assign a [managed identity](/entra/identity/managed-identities-azure-resources/overview) to the Azure-hosted app.
65
67
1. Assign Azure roles to the managed identity to enable access to the AI service.
Copy file name to clipboardExpand all lines: docs/ai/dotnet-ai-ecosystem.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,26 +45,26 @@ Many different SDKs are available for .NET to build apps with AI capabilities de
45
45
46
46
Azure offers many other AI services to build specific application capabilities and workflows. Most of these services provide a .NET SDK to integrate their functionality into custom apps. Some of the most commonly used services are shown in the following table. For a complete list of available services and learning resources, see the [Azure AI Services](/azure/ai-services/what-are-ai-services) documentation.
47
47
48
-
| Service | Description |
49
-
|---|---|
50
-
|[Azure AI Search](/azure/search/)| Bring AI-powered cloud search to your mobile and web apps. |
51
-
|[Azure AI Content Safety](/azure/ai-services/content-safety/)| Detect unwanted or offensive content. |
|[Azure AI Search](/azure/search/)| Bring AI-powered cloud search to your mobile and web apps. |
51
+
|[Azure AI Content Safety](/azure/ai-services/content-safety/)| Detect unwanted or offensive content. |
52
52
|[Azure AI Document Intelligence](/azure/ai-services/document-intelligence/)| Turn documents into intelligent data-driven solutions. |
53
-
|[Azure AI Language](/azure/ai-services/language-service/)| Build apps with industry-leading natural language understanding capabilities. |
54
-
|[Azure AI Speech](/azure/ai-services/speech-service/)| Speech to text, text to speech, translation, and speaker recognition. |
55
-
|[Azure AI Translator](/azure/ai-services/translator/)| AI-powered translation technology with support for more than 100 languages and dialects. |
56
-
|[Azure AI Vision](/azure/ai-services/computer-vision/)| Analyze content in images and videos. |
53
+
|[Azure AI Language](/azure/ai-services/language-service/)| Build apps with industry-leading natural language understanding capabilities. |
54
+
|[Azure AI Speech](/azure/ai-services/speech-service/)| Speech to text, text to speech, translation, and speaker recognition. |
55
+
|[Azure AI Translator](/azure/ai-services/translator/)| AI-powered translation technology with support for more than 100 languages and dialects. |
56
+
|[Azure AI Vision](/azure/ai-services/computer-vision/)| Analyze content in images and videos.|
57
57
58
58
## Develop with local AI models
59
59
60
60
.NET apps can also connect to local AI models for many different development scenarios. [Semantic Kernel](https://github.com/microsoft/semantic-kernel) is the recommended tool to connect to local models using .NET. Semantic Kernel can connect to many different models hosted across a variety of platforms and abstracts away lower-level implementation details.
61
61
62
62
For example, you can use [Ollama](https://ollama.com/) to [connect to local AI models with .NET](quickstarts/quickstart-local-ai.md), including several Small Language Models (SLMs) developed by Microsoft:
63
63
64
-
| Model | Description |
65
-
|---|---|
66
-
|[phi3 models](https://azure.microsoft.com/products/phi-3)| A family of powerful SLMs with groundbreaking performance at low cost and low latency. |
67
-
|[orca models](https://www.microsoft.com/en-us/research/project/orca/)| Research models in tasks such as reasoning over user given data, reading comprehension, math problem solving, and text summarization. |
|[phi3 models][phi3]| A family of powerful SLMs with groundbreaking performance at low cost and low latency. |
67
+
|[orca models][orca]| Research models in tasks such as reasoning over user-provided data, reading comprehension, math problem solving, and text summarization. |
68
68
69
69
> [!NOTE]
70
70
> The preceding SLMs can also be hosted on other services such as Azure.
@@ -81,3 +81,6 @@ This article summarized the tools and SDKs in the .NET ecosystem, with a focus o
81
81
82
82
-[What is Semantic Kernel?](/semantic-kernel/overview/)
83
83
-[Quickstart - Summarize text using Azure AI chat app with .NET](./quickstarts/quickstart-openai-summarize-text.md)
* Azure subscription. [Create one for free](https://azure.microsoft.com/free/ai-services?azure-portal=true)
16
+
* Azure subscription. [Create one for free](https://azure.microsoft.com/free/ai-services?azure-portal=true).
17
17
* Access granted to Azure OpenAI in the desired Azure subscription.
18
18
19
-
Currently, access to this service is granted only by application. You should [apply for access](https://aka.ms/oai/access) to Azure OpenAI.
19
+
Currently, access to this service is granted only by application. You should [apply for access](https://aka.ms/oai/access) to Azure OpenAI.
20
20
21
21
*[Dev containers](https://containers.dev/) are available for both samples, with all dependencies required to complete this article. You can run the dev containers in GitHub Codespaces (in a browser) or locally using Visual Studio Code.
0 commit comments