How to Use The Azure OpenAIClient Class

In this Azure OpenAI .NET SDK blog post we will show you how to use the OpenAIClient class and connect to an Azure OpenAI resource.

The Azure SDK for .NET (preview) allows us to connect, create, consume, and manage Azure resources using .NET applications like C#, ASP, Blazor, and more. The SDK also allows us to connect and consume OpenAI endpoints.

Use the OpenAIClient Class

We first need to install the Azure AI OpenAI package to use the class.

To use the package in a C# class or application, we use:

Configure the OpenAI Client

Before connecting to Azure OpenAI, we must configure the client with the OpenAI endpoint, Access Key and deployment name.

Use Client

To use the client using the client we use the following code.

Configure Completion Options

The following code configures the completion options, which control the results of the OpenAI output.

Configure Prompt

Once the OpenAIClient and completion options are ready, we can define the prompt sent to the endpoint and handle the reply (assistance).

The following code will define the prompt.

Generate Output

The following code block will generate the completions returned from the OpenAI endpoint.

More AI articles

Processing…
Success! You're on the list.


by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.