New to Telerik UI for BlazorStart a free 30-day trial

Integration with Microsoft.Extensions.AI

The AIPrompt component incorporates the Microsoft.Extensions.AI package to simplify your AI model integration, provide flexibility and let you easily use and test various AI providers.

Other components will support similar integration in future versions of UI for Blazor.

Integration

To integrate the Microsoft.Extensions.AI library with your AIPrompt component, register an IChatClient service and configure it according to the model you are using. The AIPrompt is designed to automatically use the registered IChatClient.

The Microsoft AI library is still in preview, so breaking changes may occur. Telerik UI for Blazor references Microsoft.Extensions.AI.Abstractions version 9.1.0-preview.1.25064.3. Do not register a newer version of this package explicitly in your app, as this may cause integration issues or exceptions.

When using the Telerik AIPrompt component with the Microsoft AI library, do not subscribe to the OnPromptRequest event.

Microsoft.Extensions.AI provides a simple integration with various models where the configuration slightly differs depending on the model. The example below shows usage of Azure OpenAI and you may explore some other examples with different models in this post.

Startup.cs:

C#
    services.AddSingleton(new AzureOpenAIClient(
       new Uri("YOUR_AZURE_OPENAI_ENDPOINT"),
       new AzureKeyCredential("YOUR_AZURE_OPENAI_CREDENTIAL")));

    services.AddChatClient(services => services.GetRequiredService<AzureOpenAIClient>().AsChatClient("gpt-4o-mini"));

See Also

In this article
IntegrationSee Also
Not finding the help you need?
Contact Support