-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New ai extensions docs #43300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New ai extensions docs #43300
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
95180c2
New ai extensions docs
alexwolfmsft 4a8dd87
updates
alexwolfmsft a2c7e59
line fix
alexwolfmsft f81ae66
fix trailing space
alexwolfmsft d8f1dda
Apply suggestions from code review
alexwolfmsft 0500a3b
fixes
alexwolfmsft f0fd7ed
Merge branch 'ai-extensions' of https://github.com/alexwolfmsft/docs …
alexwolfmsft b5950ba
remove image
alexwolfmsft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| --- | ||
| title: Unified AI building blocks for .NET | ||
| description: Learn how to developer with unified AI building blocks for .NET using Microsoft.Extensions.AI and Microsoft.Extensions.AI.Abstractions libraries | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ms.date: 11/04/2024 | ||
| ms.topic: quickstart | ||
| ms.custom: devx-track-dotnet, devx-track-dotnet-ai | ||
| author: alexwolfmsft | ||
| ms.author: alexwolf | ||
| --- | ||
|
|
||
| # Unified AI building blocks for .NET using Microsoft.Extensions.AI | ||
|
|
||
| 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: | ||
|
|
||
| - Core concepts and capabilities of the `Microsoft.Extensions.AI` library. | ||
| - How to work with AI abstractions in your apps and the benefits they offer. | ||
| - Essential AI middleware concepts. | ||
|
|
||
| ## What is the Microsoft.Extensions.AI library? | ||
|
|
||
| `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. | ||
alexwolfmsft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| :::image type="content" source="media/ai-extensions/meai-architecture-diagram.png" alt-text="An architectural diagram of the AI extensions libraries."::: | ||
|
|
||
| `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. | ||
|
|
||
| ## Work with abstractions for common AI services | ||
|
|
||
| AI capabilities are rapidly evolving, with patterns emerging for common functionality: | ||
|
|
||
| - Chat features to conversationally prompt an AI for information or data analysis. | ||
| - Embedding generation to integrate with vector search capabilities. | ||
| - Tool calling to integrate with other services, platforms, or code. | ||
|
|
||
| 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. | ||
|
|
||
| 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: | ||
|
|
||
| ```csharp | ||
| IChatClient client = | ||
| environment.IsDevelopment ? | ||
| new OllamaChatClient(...) : | ||
| new AzureAIInferenceChatClient(...); | ||
| ``` | ||
|
|
||
| Then, regardless of the provider you're using, you can send requests as follows: | ||
|
|
||
| ```csharp | ||
| var response = await chatClient.CompleteAsync( | ||
| "Translate the following text into Pig Latin: I love .NET and AI"); | ||
|
|
||
| Console.WriteLine(response.Message); | ||
| ``` | ||
|
|
||
| These abstractions allow for idiomatic C# code for various scenarios with minimal code changes, whether you're using different services for development or production, addressing hybrid scenarios, or exploring other service providers. | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
|
|
||
| As of this preview, `Microsoft.Extensions.AI` provides implementations for the following services through additional packages: | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - [OpenAI](https://aka.ms/meai-openai-nuget) | ||
| - [Azure OpenAI](https://aka.ms/meai-openai-nuget) | ||
| - [Azure AI Inference](https://aka.ms/meai-azaiinference-nuget) | ||
| - [Ollama](https://aka.ms/meai-ollama-nuget) | ||
|
|
||
| In the future, implementations of these `Microsoft.Extensions.AI` abstractions will be part of the respective client libraries rather than requiring installation of additional packages. | ||
|
|
||
| ## Middleware implementations for AI services | ||
|
|
||
| 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 developers to easily integrate these components into their applications using familiar patterns. | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The following sample demonstrates how to register an OpenAI `IChatClient`. `IChatClient` allows you to attach the capabilities in a consistent way across various providers. | ||
|
|
||
| ```csharp | ||
| app.Services.AddChatClient(builder => builder | ||
| .UseLogging() | ||
| .UseFunctionInvocation() | ||
| .UseDistributedCache() | ||
| .UseOpenTelemetry() | ||
| .Use(new OpenAIClient(...)).AsChatClient(...)); | ||
| ``` | ||
|
|
||
| The capabilities demonstrated above 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. | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Building with Microsoft.Extensions.AI | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| You can start building with `Microsoft.Extensions.AI` in the following ways: | ||
|
|
||
| - **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. | ||
| - **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. | ||
| - **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. | ||
| - **Ecosystem Contributors**: If you're interested in contributing to the ecosystem, consider writing custom middleware components. | ||
| We have a set of samples in the [dotnet/ai-samples](https://aka.ms/meai-samples) GitHub repository to help you get started. | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| For an end-to-end sample using `Microsoft.Extensions.AI`, see [eShopSupport](https://github.com/dotnet/eShopSupport). | ||
|
|
||
| ## Next Steps | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - [Build an AI chat app with .NET](/dotnet/ai/quickstarts/get-started-openai) | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - [Quickstart - Summarize text using Azure AI chat app with .NET](./quickstarts/quickstart-openai-summarize-text.md) | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.