Member-only story
Unlocking OpenAI Integration with .NET 8
The Aspire.Azure.AI.OpenAI library lets you set up an OpenAIClient in the dependency injection (DI) container for consuming Azure AI OpenAI or OpenAI features. It also handles logging and telemetry.
In this guide, you’ll discover how to make the most of the .NET Aspire Azure AI OpenAI client.
To begin, you’ll need an Azure subscription, which can be created for free, and an Azure AI OpenAI or OpenAI account. Here’s how to get started with the .NET Aspire Azure AI OpenAI component:
Installation
Start by installing the Aspire.Azure.AI.OpenAI NuGet package. You can do this using the .NET CLI or PackageReference.
dotnet add package Aspire.Azure.AI.OpenAI --prerelease
Example Usage
In your project’s Program.cs file, you’ll register an OpenAIClient using an extension method. This method requires a connection name parameter.
builder.AddAzureOpenAI("openAiConnectionName");
This snippet adds an OpenAIClient to the DI container. The parameter openAiConnectionName
refers to the connection string in the configuration. You can then access…