Artificial Intelligence (AI) is transforming the way we build applications. With the introduction of Microsoft.Extensions.AI
, integrating AI services into .NET applications has never been easier. In this blog, we'll explore Microsoft.Extensions.AI, why .NET developers should try it out, and how to get started using it to build a simple text generation application.
Microsoft.Extensions.AI
provides unified abstractions and middleware for integrating AI services into .NET applications. This means you can work with AI capabilities like chat features, embedding generation, and tool calling without worrying about specific platform implementations. Whether you're using Azure AI, OpenAI, or other AI services, Microsoft.Extensions.AI
ensures seamless integration and collaboration across the .NET ecosystem.
With this extension, .NET developers can easily connect their applications to AI services like:
- Azure OpenAI (GPT models)
- OpenAI API
- Any other library that supports MEAI — including all the models in Azure AI Foundry!
Instead of juggling raw HTTP requests and complex authentication for each provider, Microsoft.Extensions.AI
gives you a unified API surface — so you interact with any AI model through one consistent, maintainable interface.
Let's walk through how to add text generation capabilities to your .NET application step by step, whether you decide to use GitHub Models or Azure AI Foundry.
GitHub Models is a free service that lets you try out and interact with different AI models right within your development environment. It's easy to use with Codespaces, making it a great tool for experimenting with various models and understanding their capabilities before you decide to implement them. GitHub Models are particularly suitable for quick trials and allow easy model switching.
To use GitHub Models, you first need to create a personal access token:
-
Select your GitHub profile picture and click ⚙️ Settings
-
In the left sidebar, click <> Developer settings
-
Under 🔑 Personal access tokens, click Tokens (classic)
-
Select Generate new token, then click Generate new token (classic)
-
Under the "Note" field, give your token a descriptive name (e.g.,
Testing-MEAI-In-NET
) -
For expiration, select Custom and set it to 7 days (recommended for security)
-
Click Generate token and copy the token to your clipboard
Here's how to go about it:
-
Go to https://github.com/japhletnwamu/MEAI-for-Dotnet-Developers
-
Fork the repo into your GitHub account by clicking Fork
-
Click the Code dropdown and open the Codespaces tab
-
Click Create codespace on main
-
You may be prompted to install required extensions like the C# Dev Kit
-
Open the terminal (
Ctrl
+\
on Windows orCmd
+\
on macOS) -
Navigate to the project directory:
cd MEAI-for-Dotnet-Developers/MEAI-GitHub-Models
-
Or right-click on the folder and select Open in Integrated Terminal
-
Run the application:
dotnet run
-
Wait a few seconds for the output message
-
You can change the prompt by editing line 16 of
Program.cs
Congratulations! 🎉 You’ve successfully integrated AI capabilities into your .NET application using Microsoft.Extensions.AI
and GitHub Models!
🚀
Next, let's explore how to create your application using Azure AI Foundry services
🚀
If you want to know more, the Generative AI for Beginners .NET repo will help with next steps like Functions, Agents, MCP, etc. Check out this resource here - Generative AI for Beginners .NET
We have a lot of other content to help your learning journey. Check out: