Skip to content

Commit 1eac44f

Browse files
Merge pull request #6642 from syncfusion-content/983466-SmartTextArea
983466: Updated the SmartTextArea UG Section.
2 parents b35207a + e3dddc7 commit 1eac44f

File tree

6 files changed

+223
-527
lines changed

6 files changed

+223
-527
lines changed

blazor-toc.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,9 +4282,6 @@
42824282
<li>Getting Started
42834283
<ul>
42844284
<li> <a href="/blazor/smart-textarea/getting-started-webapp">Blazor Web App</a></li>
4285-
<li>
4286-
<a href="/blazor/smart-textarea/getting-started">Blazor Server App</a>
4287-
</li>
42884285
</ul>
42894286
</li>
42904287
<li><a href="/blazor/smart-textarea/customization">Customize Suggestions</a></li>
Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,82 @@
11
---
22
layout: post
3-
title: Custom AI Service Integration with Syncfusion Smart Components
4-
description: Learn how to use IChatInferenceService to integrate custom AI services with Syncfusion Smart Components
3+
title: Custom AI Service Integration with Blazor Smart TextArea | Syncfusion
4+
description: Learn how to use IChatInferenceService to integrate custom AI services with the Syncfusion Blazor Smart TextArea component.
55
platform: Blazor
66
control: Smart TextArea
77
documentation: ug
88
---
99

10-
# Custom AI Service Integration
11-
12-
## Overview
13-
14-
Syncfusion<sup style="font-size:70%">&reg;</sup> Smart Components provide built-in support for OpenAI and Azure OpenAI services. However, you can also integrate other AI services using the `IChatInferenceService` interface, which acts as a bridge between Smart Components and your custom AI service.
10+
# Custom AI Service Integration with Blazor Smart TextArea
1511

12+
The Syncfusion Blazor Smart TextArea component leverages AI to provide context-aware autocompletion, typically using OpenAI or Azure OpenAI services. Developers can integrate custom AI services using the `IChatInferenceService` interface, which standardizes communication between the Smart TextArea and third-party AI providers. This section explains how to implement and register a custom AI service for the Smart TextArea.
1613

1714
## IChatInferenceService Interface
1815

19-
The `IChatInferenceService` interface defines a simple contract for AI service integration:
16+
The `IChatInferenceService` interface defines a contract for integrating custom AI services with Syncfusion Smart Components. It enables the Smart TextArea to request and receive AI-generated responses.
2017

2118
```csharp
19+
using Syncfusion.Blazor.AI;
20+
2221
public interface IChatInferenceService
2322
{
2423
Task<string> GenerateResponseAsync(ChatParameters options);
2524
}
2625
```
2726

28-
This interface enables:
29-
- Consistent communication between components and AI services
30-
- Easy switching between different AI providers
27+
- **Purpose**: Standardizes communication for AI-generated responses.
28+
- **Parameters**: The `ChatParameters` type includes properties like user input and context.
29+
- **Benefits**: Enables seamless switching between AI providers without modifying component code.
30+
31+
## Simple Implementation of a Custom AI Service
32+
33+
Below is a sample implementation of a mock AI service named `MockAIService`. This service demonstrates how to implement the `IChatInferenceService` interface by returning sample, context-aware responses. You can replace the logic with your own AI integration.
34+
35+
```csharp
36+
using Syncfusion.Blazor.AI;
37+
using System.Threading.Tasks;
38+
39+
public class MockAIService : IChatInferenceService
40+
{
41+
public Task<string> GenerateResponseAsync(ChatParameters options)
42+
{
43+
44+
}
45+
}
46+
```
47+
48+
## Registering the Custom AI Service
3149

50+
Register the custom AI service in the **~/Program.cs** file of your Blazor Web App:
51+
52+
```csharp
53+
using Microsoft.AspNetCore.Components;
54+
using Microsoft.AspNetCore.Components.Web;
55+
using Syncfusion.Blazor;
56+
using Syncfusion.Blazor.AI;
57+
using Syncfusion.Blazor.SmartComponents;
58+
59+
var builder = WebApplication.CreateBuilder(args);
60+
61+
builder.Services.AddRazorPages();
62+
builder.Services.AddServerSideBlazor();
63+
builder.Services.AddSyncfusionBlazor();
64+
builder.Services.AddSyncfusionSmartComponents();
65+
builder.Services.AddSingleton<IChatInferenceService, MockAIService>();
66+
67+
var app = builder.Build();
68+
// ...
69+
```
70+
71+
## Testing the Custom AI Integration
72+
73+
1. Implement and register the custom AI service as shown above.
74+
2. Add the Smart TextArea component to your application.
75+
3. Run the application using <kbd>Ctrl</kbd>+<kbd>F5</kbd> (Windows) or <kbd>⌘</kbd>+<kbd>F5</kbd> (macOS).
76+
4. Type phrases like "thank" or "investigate" in the Smart TextArea to verify that the custom AI service generates appropriate responses.
77+
5. Ensure suggestions appear as configured (e.g., inline or pop-up, based on the `ShowSuggestionOnPopup` setting).
78+
79+
![Smart TextArea with Custom AI Service](images/smart-textarea.gif)
3280

3381
## Implemented AI Services
3482

@@ -41,13 +89,14 @@ Here are examples of AI services integrated using the `IChatInferenceService` in
4189
| Groq | [Groq Integration](groq-service) |
4290
| Gemini | [Gemini Integration](gemini-service) |
4391

92+
## Troubleshooting
4493

45-
## Service Registration
46-
47-
Register your custom implementation in `Program.cs`:
94+
If the custom AI service does not work as expected, try the following:
95+
- **No Suggestions Displayed**: Ensure the `IChatInferenceService` implementation is registered in **Program.cs** and returns valid responses. Check for errors in the `GenerateResponseAsync` method.
96+
- **Dependency Issues**: Verify that all required NuGet packages (e.g., `Syncfusion.Blazor.SmartComponents`) are installed. Run `dotnet restore` to resolve dependencies.
97+
- **Incorrect Responses**: Debug the custom AI service implementation to ensure it processes `ChatParameters` correctly and returns expected responses.
4898

49-
```csharp
50-
using Syncfusion.Blazor.AI;
51-
builder.Services.AddSingleton<IChatInferenceService, YourCustomService>();
52-
```
99+
## See Also
53100

101+
- [Getting Started with Syncfusion Blazor Smart TextArea in Blazor Web App](https://blazor.syncfusion.com/documentation/smart-textarea/getting-started-webapp)
102+
- [Customizing Smart TextArea Suggestions](https://blazor.syncfusion.com/documentation/smart-textarea/customization)
Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,84 @@
11
---
22
layout: post
3-
title: Suggestion Customization in Blazor Smart TextArea | Syncfusion
4-
description: Checkout and learn here all about Suggestion Customization in Syncfusion Blazor Smart TextArea component and more.
3+
title: Customize Suggestions in Blazor Smart TextArea | Syncfusion
4+
description: Learn how to customize suggestion display in the Syncfusion Blazor Smart TextArea component for enhanced user interaction.
55
platform: Blazor
66
control: Smart TextArea
77
documentation: ug
88
---
99

10-
# Customizing Appearance of Suggestions
10+
# Customize Suggestions in Blazor Smart TextArea
1111

12-
The `ShowSuggestionOnPopup` attribute in Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Smart TextArea allows you to control how text suggestions are displayed to the users.
12+
The Syncfusion Blazor Smart TextArea component provides AI-powered autocompletion for context-aware text input, with customizable suggestion display options. This section explains how to configure the appearance and behavior of suggestions to enhance user experience in applications like issue trackers or customer support systems.
1313

14-
* If `ShowSuggestionOnPopup` is `true`, suggestions displayed in the pop-up window
14+
## Configure Suggestion Display
1515

16-
```cshtml
16+
The `ShowSuggestionOnPopup` attribute controls how AI-generated suggestions are presented to users in the Smart TextArea component. Suggestions are based on the `UserRole` and optional `UserPhrases` attributes, which define the context and predefined phrases for autocompletion.
17+
18+
### Pop-up Suggestions
19+
20+
Set `ShowSuggestionOnPopup="true"` to display suggestions in a pop-up window above the text area, ideal for scenarios where users need to select from multiple suggestions without cluttering the input area.
21+
22+
Add the following code to a Razor file (e.g., `~/Pages/Home.razor`):
23+
24+
```razor
1725
@using Syncfusion.Blazor.SmartComponents
1826
19-
<SfSmartTextArea UserRole="@userRole" Placeholder="Enter your queries here" @bind-Value="prompt" Width="75%" RowCount="5" ShowSuggestionOnPopup="true">
27+
<SfSmartTextArea UserRole="@userRole" UserPhrases="@userPhrases" Placeholder="Enter your queries here" @bind-Value="prompt" Width="75%" RowCount="5" ShowSuggestionOnPopup="true">
2028
</SfSmartTextArea>
2129
2230
@code {
2331
private string? prompt;
32+
// Defines the context for AI autocompletion
2433
public string userRole = "Maintainer of an open-source project replying to GitHub issues";
34+
// Predefined phrases for AI to suggest during typing
35+
public string[] userPhrases = [
36+
"Thank you for contacting us.",
37+
"To investigate, we will need a reproducible example as a public Git repository.",
38+
"Could you please post a screenshot of the issue?"
39+
];
2540
}
2641
```
2742

28-
![SUggestion on popup](images/smart-textarea-popup.gif)
43+
![Suggestion on popup](images/smart-textarea-popup.gif)
2944

30-
* If `ShowSuggestionOnPopup` is `false`, suggestions displayed inline.
45+
### Inline Suggestions
3146

32-
```cshtml
47+
Set `ShowSuggestionOnPopup="false"` (default) to display suggestions inline within the text area, suitable for seamless text entry where users can accept suggestions by continuing to type or pressing a key (e.g., Tab).
48+
49+
Add the following code to a Razor file (e.g., `~/Pages/Home.razor`):
50+
51+
```razor
3352
@using Syncfusion.Blazor.SmartComponents
3453
35-
<SfSmartTextArea UserRole="@userRole" Placeholder="Enter your queries here" @bind-Value="prompt" Width="75%" RowCount="5" ShowSuggestionOnPopup="false">
54+
<SfSmartTextArea UserRole="@userRole" UserPhrases="@userPhrases" Placeholder="Enter your queries here" @bind-Value="prompt" Width="75%" RowCount="5" ShowSuggestionOnPopup="false">
3655
</SfSmartTextArea>
3756
3857
@code {
3958
private string? prompt;
59+
// Defines the context for AI autocompletion
4060
public string userRole = "Maintainer of an open-source project replying to GitHub issues";
61+
// Predefined phrases for AI to suggest during typing
62+
public string[] userPhrases = [
63+
"Thank you for contacting us.",
64+
"To investigate, we will need a reproducible example as a public Git repository.",
65+
"Could you please post a screenshot of the issue?"
66+
];
4167
}
4268
```
4369

44-
![SUggestion inline](images/smart-textarea-inline.gif)
70+
![Suggestion inline](images/smart-textarea-inline.gif)
71+
72+
## Test Suggestion Customization
4573

46-
By default `ShowSuggestionOnPopup` is `false`.
74+
1. Add the Smart TextArea component to your Blazor Web App as shown above.
75+
2. Run the application using <kbd>Ctrl</kbd>+<kbd>F5</kbd> (Windows) or <kbd>⌘</kbd>+<kbd>F5</kbd> (macOS).
76+
3. Type phrases like "Thank you" or "To investigate" to trigger suggestions.
77+
4. For pop-up mode, verify that suggestions appear in a pop-up window and can be selected. For inline mode, confirm that suggestions appear in the text area and can be accepted by tab keypress.
4778

48-
## See also
79+
## Troubleshooting
4980

50-
* [Getting Started with Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Smart TextArea in Blazor Web App](https://blazor.syncfusion.com/documentation/)
51-
* [Getting Started with Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Smart TextArea with in Blazor Server App](https://blazor.syncfusion.com/documentation/)
81+
If suggestions do not appear, try the following:
82+
- **AI Configuration Errors**: Verify that the API key, endpoint, and model name are correctly configured in **Program.cs**. Check for typos or invalid credentials.
83+
- **Missing Dependencies**: Ensure all required NuGet packages (`Syncfusion.Blazor.SmartComponents`, `Microsoft.Extensions.AI`, etc.) are installed. Run `dotnet restore` to resolve dependencies.
84+
- **Incorrect Setup**: Confirm that the Syncfusion Blazor service is registered in **Program.cs** and the stylesheet/script references are added in **App.razor**.

blazor/smart-textarea/features.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,3 @@ The Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Smart TextArea compo
1616
* [Events](https://blazor.syncfusion.com/documentation/textarea/events)
1717
* [Methods](https://blazor.syncfusion.com/documentation/textarea/methods)
1818
* [Style and Appearance](https://blazor.syncfusion.com/documentation/textarea/styles-appearance)
19-
20-
## See also
21-
22-
* [Getting Started with Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Smart TextArea in Blazor Web App](https://blazor.syncfusion.com/documentation/)
23-
* [Getting Started with Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Smart TextArea in Blazor Server App](https://blazor.syncfusion.com/documentation/)
24-
* [Getting Started with Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor TextArea in Blazor Web App](https://blazor.syncfusion.com/documentation/textarea/getting-started-webapp)
25-
* [Getting Started with Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor TextArea in Blazor App](https://blazor.syncfusion.com/documentation/textarea/getting-started)

0 commit comments

Comments
 (0)