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-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,21 +10,21 @@ 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 <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:
13
+
The .NET ecosystem provides abstractions for integrating AI services into .NET applications and libraries using the <xref:Microsoft.Extensions.AI> libraries. The .NET team has also enhanced the core `Microsoft.Extensions` libraries with these abstractions for use in generative AI .NET 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.
17
17
- Essential AI middleware concepts.
18
18
19
19
For more information, see [Introduction to Microsoft.Extensions.AI](../core/extensions/artificial-intelligence.md).
20
20
21
-
## What is the Microsoft.Extensions.AI library?
21
+
## What are the Microsoft.Extensions.AI libraries?
22
22
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.
23
+
The `Microsoft.Extensions.AI` libraries provides core exchange types and abstractions for interacting with AI services, such as small and large language models (SLMs and LLMs). They also provide the ability to register services like logging and caching in your dependency injection (DI) container.
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
27
-
`Microsoft.Extensions.AI`provides abstractions that can be implemented by various services, all adhering to the same core concepts. This library is not intended to provide APIs tailored to any specific provider's services. The goal of `Microsoft.Extensions.AI` is to act as a unifying layer within the .NET ecosystem, enabling developers to choose their preferred frameworks and libraries while ensuring seamless integration and collaboration across the ecosystem.
27
+
The `Microsoft.Extensions.AI`namespaces provide abstractions that can be implemented by various services, all adhering to the same core concepts. This library is not intended to provide APIs tailored to any specific provider's services. The goal of `Microsoft.Extensions.AI` is to act as a unifying layer within the .NET ecosystem, enabling developers to choose their preferred frameworks and libraries while ensuring seamless integration and collaboration across the ecosystem.
28
28
29
29
## Work with abstractions for common AI services
30
30
@@ -34,9 +34,9 @@ AI capabilities are rapidly evolving, with patterns emerging for common function
34
34
- Embedding generation to integrate with vector search capabilities.
35
35
- Tool calling to integrate with other services, platforms, or code.
36
36
37
-
The `Microsoft.Extensions.AI` library provides abstractions for these types of tasks, so developers can focus on coding against conceptual AI capabilities rather than specific platforms or provider implementations. Unified abstractions are crucial for developers to work effectively across different sources.
37
+
The `Microsoft.Extensions.AI.Abstractions` package provides abstractions for these types of tasks, so developers can focus on coding against conceptual AI capabilities rather than specific platforms or provider implementations. Unified abstractions are crucial for developers to work effectively across different sources.
38
38
39
-
For example, the `IChatClient` interface allows consumption of language models from various providers, whether you're connecting to an Azure OpenAI service or running a local Ollama installation. Any .NET package that provides an AI client can implement the `IChatClient` interface, enabling seamless integration with consuming .NET code:
39
+
For example, the <xref:Microsoft.Extensions.AI.IChatClient> interface allows consumption of language models from various providers, such as an Azure OpenAI service or a local Ollama installation. Any .NET package that provides an AI client can implement the `IChatClient` interface to enable seamless integration with consuming .NET code:
40
40
41
41
```csharp
42
42
IChatClientclient=
@@ -45,7 +45,7 @@ IChatClient client =
45
45
newAzureAIInferenceChatClient(...);
46
46
```
47
47
48
-
Then, regardless of the provider you're using, you can send requests as follows:
48
+
Then, regardless of the provider you're using, you can send requests by calling <xref:Microsoft.Extensions.AI.IChatClient.CompleteAsync(System.Collections.Generic.IList{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatOptions,System.Threading.CancellationToken)>, as follows:
49
49
50
50
```csharp
51
51
varresponse=awaitchatClient.CompleteAsync(
@@ -54,7 +54,7 @@ var response = await chatClient.CompleteAsync(
54
54
Console.WriteLine(response.Message);
55
55
```
56
56
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.
57
+
These abstractions allow for idiomatic C# code for various scenarios with minimal code changes. They make it easy to use different services for development and production, addressing hybrid scenarios, or exploring other service providers.
58
58
59
59
Library authors who implement these abstractions make their clients interoperable with the broader `Microsoft.Extensions.AI` ecosystem. Service-specific APIs remain accessible if needed, allowing consumers to code against the standard abstractions and pass through to proprietary APIs only when required.
60
60
@@ -69,9 +69,9 @@ 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 tool-calling 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, caching, and tool-calling capabilities. The `Microsoft.Extensions.AI`packages provides APIs that enable you to easily integrate these components into your applications using familiar dependency injection and middleware patterns.
73
73
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.
74
+
The following sample demonstrates how to register an OpenAI `IChatClient`. You can attach capabilities in a consistent way across various providers by calling methods such as <xref:Microsoft.Extensions.AI.FunctionInvokingChatClientBuilderExtensions.UseFunctionInvocation(Microsoft.Extensions.AI.ChatClientBuilder,Microsoft.Extensions.Logging.ILoggerFactory,System.Action{Microsoft.Extensions.AI.FunctionInvokingChatClient})> on a <xref:Microsoft.Extensions.AI.ChatClientBuilder>.
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.
85
+
The capabilities demonstrated in this snippet are included in the `Microsoft.Extensions.AI` library, but they're 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.
86
86
87
87
## Build with Microsoft.Extensions.AI
88
88
89
89
You can start building with `Microsoft.Extensions.AI` in the following ways:
90
90
91
-
-**Library Developers**: If you own libraries that provide clients for AI services, consider implementing the interfaces in your libraries. This allows users to easily integrate your NuGet package via the abstractions.
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
-
-**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
-
-**Ecosystem Contributors**: If you're interested in contributing to the ecosystem, consider writing custom middleware components.
91
+
-**Library developers**: If you own libraries that provide clients for AI services, consider implementing the interfaces in your libraries. This allows users to easily integrate your NuGet package via the abstractions.
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
+
-**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
+
-**Ecosystem contributors**: If you're interested in contributing to the ecosystem, consider writing custom middleware components.
95
95
96
96
To get started, see the samples in the [dotnet/ai-samples](https://aka.ms/meai-samples) GitHub repository.
0 commit comments