Skip to content

Commit 9cd193c

Browse files
authoredFeb 11, 2025
Document integration with Microsoft.Extensions.AI (#2753)
* chore(AIPrompt): add docs for integration with ai extensions * docs(common): add more information * chore(common): fix * chore(common): add link in aipromptoverview * chore(common): address feedback
1 parent 8346eef commit 9cd193c

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Integration with Microsoft.Extensions.AI
3+
page_title: Integration with Microsoft.Extensions.AI
4+
description: How to integrate the UI for Blazor components with Microsoft.Extensions.AI
5+
slug: common-features-microsoft-extensions-ai-integration
6+
tags: telerik,blazor,aiprompt,ai,extensions,integration
7+
published: True
8+
position: 4
9+
---
10+
11+
# Integration with Microsoft.Extensions.AI
12+
13+
The [AIPrompt component](slug:aiprompt-overview) incorporates the [Microsoft.Extensions.AI package](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.ai?view=net-9.0-pp) to simplify your AI model integration, provide flexibility and let you easily use and test various AI providers.
14+
15+
Other components will support similar integration in future versions of UI for Blazor.
16+
17+
## Integration
18+
19+
To integrate the **Microsoft.Extensions.AI** library with your AIPrompt component, register an [`IChatClient`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.ai.ichatclient?view=net-9.0-pp) service and configure it according to the model you are using. The AIPrompt is designed to automatically use the registered `IChatClient`.
20+
21+
**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](https://www.nuget.org/packages/Azure.AI.OpenAI) and you may [explore some other examples with different models in this post](https://devblogs.microsoft.com/dotnet/introducing-microsoft-extensions-ai-preview/#chat).
22+
23+
>caption Startup.cs:
24+
25+
<div class="skip-repl"></div>
26+
````C#
27+
services.AddSingleton(new AzureOpenAIClient(
28+
new Uri("YOUR_AZURE_OPENAI_ENDPOINT"),
29+
new AzureKeyCredential("YOUR_AZURE_OPENAI_CREDENTIAL")));
30+
31+
services.AddChatClient(services => services.GetRequiredService<AzureOpenAIClient>().AsChatClient("gpt-4o-mini"));
32+
````
33+
34+
## See Also
35+
36+
* [AIPrompt Overview - Documenation](slug:aiprompt-overview)
37+
* [AIPrompt - Live Demo](https://demos.telerik.com/blazor-ui/aiprompt/overview)
38+
* [Microsoft.Extensions.AI](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.ai?view=net-9.0-pp)
39+
* [Introducing Microsoft.Extensions.AI Preview – Unified AI Building Blocks for .NET](https://devblogs.microsoft.com/dotnet/introducing-microsoft-extensions-ai-preview/)

‎components/aiprompt/overview.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ The component allows you to interact with the output from the AI and execute a s
6161
}
6262
````
6363

64+
## Integration with Microsoft.Extensions.AI
65+
66+
The AIPrompt supports using the [Microsoft.Extensions.AI library](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.ai?view=net-9.0-pp) to provide seamless integration with various AI models and boost your workflow when connecting the AIPrompt with AI models. [Learn how to integrate Microsoft.Extensions.AI with your AIPrompt component...](slug://common-features-microsoft-extensions-ai-integration)
6467

6568
## ToolBar
6669

@@ -92,14 +95,15 @@ The table below lists the AIPrompt parameters. For a full list of the AIPrompt A
9295
| --- | --- | --- |
9396
| `AIPromptViews` | `RenderFragment` | Allows control over the views of the content. Use it to set the visibility of a predefined view or to create custom views. If a render fragment is not provided, the AIPrompt will display its default views. |
9497
| `AIPromptToolBar` | `RenderFragment` | Any additional buttons that will be rendered within the ToolBar. This parameter will append the new items, rather than override buttons related to existing views. |
98+
| `Class` | `string` | The `class` attribute of the `<div class="k-prompt">` element. Use it to apply custom styles or [override the theme](slug://themes-override). |
99+
| `Commands` | `List<AIPromptCommandDescriptor>` | The predefined commands displayed within the Commands view. |
100+
| `Height` | `string` | The `height` style of the component in any [supported CSS unit](slug://common-features/dimensions). The default AIPrompt dimensions depend on the CSS theme. |
95101
| `PromptText` | `string` | The value of the text within the prompt view. Use it when you need to add some form of transformation to the prompt. The parameter supports two-way binding. |
96102
| `PromptTextChanged` | `EventCallback<string>` | The handler called whenever the `PromptText` changes. |
97103
| `PromptSuggestions` | `List<string>` | The prompt suggestions displayed within the Prompt view. |
98104
| `PromptSuggestionItemTemplate` | `RenderFragment<string>` | The Prompt Suggestion Item template of the AIPrompt. |
99-
| `Commands` | `List<AIPromptCommandDescriptor>` | The predefined commands displayed within the Commands view. |
100105
| `ShowOutputRating` | `bool` <br /> (`false`) | Controls the visibility of the rating buttons within the output card. |
101-
| `Class` | `string` | The `class` attribute of the `<div class="k-prompt">` element. Use it to apply custom styles or [override the theme](slug://themes-override). |
102-
| `Height` | `string` | The `height` style of the component in any [supported CSS unit](slug://common-features/dimensions). The default AIPrompt dimensions depend on the CSS theme. |
106+
| `SystemPrompt` | `string` <br/> (See "Description" column) | Defines the system prompt that is passed to the [`IChatClient.CompleteAsync`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.ai.ichatclient.completeasync?view=net-9.0-pp), when such is used. The default value is: `"You are a helpful assistant designed to assist users. Your goal is to provide helpful, accurate, and contextually appropriate information in a clear and concise manner. Avoid discussing harmful, illegal, or inappropriate topics"`.
103107
| `Width` | `string` | The `width` style of the component in any [supported CSS unit](slug://common-features/dimensions). The default AIPrompt dimensions depend on the CSS theme. |
104108

105109
## AIPrompt Reference and Methods

0 commit comments

Comments
 (0)
Please sign in to comment.