Skip to content

Commit 178c4df

Browse files
Merge pull request #6679 from syncfusion-content/983466-SmartPaste-1
983466: Improved the UG content for Smart PasteButton.
2 parents 5353689 + 81c5b29 commit 178c4df

File tree

3 files changed

+77
-32
lines changed

3 files changed

+77
-32
lines changed
Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
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 Syncfusion Smart Paste
4+
description: Learn how to integrate custom AI services with the Syncfusion Blazor Smart Paste Button using the IChatInferenceService interface for AI-driven form filling.
55
platform: Blazor
66
control: Smart Paste Button
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 Paste Button
1511

12+
The Syncfusion Blazor Smart Paste Button leverages AI to parse clipboard content and populate form fields, enhancing user productivity. By default, it supports OpenAI and Azure OpenAI services, but you can integrate custom AI services using the `IChatInferenceService` interface. This interface facilitates communication between the Smart Paste Button and your custom AI provider, enabling precise mapping of clipboard data to form fields.
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 AI services with the Smart Paste Button, enabling the component to process clipboard data for form field mapping.
2017

2118
```csharp
2219
public interface IChatInferenceService
@@ -25,10 +22,57 @@ public interface IChatInferenceService
2522
}
2623
```
2724

28-
This interface enables:
29-
- Consistent communication between components and AI services
30-
- Easy switching between different AI providers
25+
The `GenerateResponseAsync` method takes `ChatParameters` (containing clipboard data and form field metadata) and returns a string response from the AI service, which the Smart Paste Button uses to populate form fields.
26+
27+
## Simple Implementation of a Custom AI Service
28+
29+
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.
30+
31+
```csharp
32+
using Syncfusion.Blazor.AI;
33+
using System.Threading.Tasks;
34+
35+
public class MockAIService : IChatInferenceService
36+
{
37+
public Task<string> GenerateResponseAsync(ChatParameters options)
38+
{
39+
40+
}
41+
}
42+
```
43+
44+
## Registering the Custom AI Service
3145

46+
Register the custom AI service in the **~/Program.cs** file of your Blazor Web App:
47+
48+
```csharp
49+
using Microsoft.AspNetCore.Components;
50+
using Microsoft.AspNetCore.Components.Web;
51+
using Syncfusion.Blazor;
52+
using Syncfusion.Blazor.AI;
53+
using Syncfusion.Blazor.SmartComponents;
54+
55+
var builder = WebApplication.CreateBuilder(args);
56+
57+
builder.Services.AddRazorPages();
58+
builder.Services.AddServerSideBlazor();
59+
builder.Services.AddSyncfusionBlazor();
60+
builder.Services.AddSyncfusionSmartComponents();
61+
builder.Services.AddSingleton<IChatInferenceService, MockAIService>();
62+
63+
var app = builder.Build();
64+
// ...
65+
```
66+
67+
## Testing the Custom AI Integration
68+
69+
1. Configure the Blazor Web App Server with the Smart Paste Button and custom AI service as described above.
70+
2. Add the code to **~/Pages/Home.razor** and ensure **Program.cs** includes the service registrations.
71+
3. Run the application using <kbd>Ctrl</kbd>+<kbd>F5</kbd> (Windows) or <kbd>⌘</kbd>+<kbd>F5</kbd> (macOS).
72+
4. Copy the sample content provided in the Razor file.
73+
5. Click the **Smart Paste** button to verify that the form fields are populated correctly using the custom AI service.
74+
75+
![Syncfusion Blazor Smart Paste Button with Custom AI](images/smart-paste.gif)
3276

3377
## Implemented AI Services
3478

@@ -41,13 +85,14 @@ Here are examples of AI services integrated using the `IChatInferenceService` in
4185
| Groq | [Groq Integration](groq-service) |
4286
| Gemini | [Gemini Integration](gemini-service) |
4387

88+
## Troubleshooting
4489

45-
## Service Registration
46-
47-
Register your custom implementation in `Program.cs`:
90+
If the custom AI integration does not work as expected, try the following:
91+
- **Fields Not Populating**: Verify that the custom AI service’s endpoint, model, and API key are correct in `appsettings.json`. Ensure the `GenerateResponseAsync` method returns valid data.
92+
- **Service Registration Errors**: Confirm that `CustomAIService` and `CustomInferenceService` are registered in **Program.cs** after `AddSyncfusionBlazor`.
93+
- **AI Parsing Errors**: Check the AI service’s response format and ensure it matches the expected `CustomAIResponse` structure. Test the API independently to verify connectivity.
4894

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

97+
- [Getting Started with Syncfusion Blazor Smart Paste Button in Blazor Web App](https://blazor.syncfusion.com/documentation/smart-paste/getting-started-webapp)
98+
- [Syncfusion Blazor DataForm Documentation](https://blazor.syncfusion.com/documentation/data-form/getting-started-with-web-app)

blazor/smart-paste/getting-started-webapp.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
layout: post
33
title: Get Started with Blazor Smart Paste Button | Syncfusion
4-
description: Learn how to integrate the Syncfusion Blazor Smart Paste Button in a Blazor Web App with step-by-step instructions.
4+
description: Learn how to integrate the Syncfusion Blazor Smart Paste Button in a Blazor Web App Server with step-by-step instructions.
55
platform: Blazor
66
control: Smart Paste Button
77
documentation: ug
88
---
99

1010
# Getting Started with Smart Paste Button
1111

12-
This section explains how to integrate the [Blazor Smart Paste Button](https://www.syncfusion.com/blazor-components/blazor-smartpaste-button) component in a Blazor Web App using [Visual Studio](https://visualstudio.microsoft.com/vs/) or Visual Studio Code. The Smart Paste Button leverages AI to intelligently populate form fields from copied text, streamlining user input workflows.
12+
This section explains how to integrate the [Blazor Smart Paste Button](https://www.syncfusion.com/blazor-components/blazor-smartpaste-button) component in a Blazor Web App Server using [Visual Studio](https://visualstudio.microsoft.com/vs/) or Visual Studio Code. The Smart Paste Button leverages AI to intelligently populate form fields from copied text, streamlining user input workflows.
1313

1414
To get started quickly with the Blazor Smart Paste Button component, watch this video:
1515

@@ -29,7 +29,7 @@ To get started quickly with the Blazor Smart Paste Button component, watch this
2929

3030
N> Syncfusion Blazor Smart Components support both OpenAI and Azure OpenAI and are compatible with Blazor Server Interactivity mode.
3131

32-
## Create a New Blazor Web App in Visual Studio
32+
## Create a New Blazor Web App Server in Visual Studio
3333

3434
Create a **Blazor Web App** using Visual Studio 2022 with [Microsoft Templates](https://learn.microsoft.com/en-us/aspnet/core/blazor/tooling?view=aspnetcore-8.0) or the [Syncfusion Blazor Extension](https://blazor.syncfusion.com/documentation/visual-studio-integration/template-studio). Configure the app with the Server interactive render mode.
3535

@@ -65,12 +65,12 @@ N> Syncfusion Blazor components are available on [nuget.org](https://www.nuget.o
6565

6666
N> Syncfusion Blazor Smart Components support both OpenAI and Azure OpenAI and are compatible with Blazor Server Interactivity mode.
6767

68-
## Create a New Blazor Web App in Visual Studio Code
68+
## Create a New Blazor Web App Server in Visual Studio Code
6969

7070
Create a **Blazor Web App** using Visual Studio Code with [Microsoft Templates](https://learn.microsoft.com/en-us/aspnet/core/blazor/tooling?view=aspnetcore-8.0&pivots=vsc) or the [Syncfusion Blazor Extension](https://blazor.syncfusion.com/documentation/visual-studio-code-integration/create-project). Configure the app with the Server interactive render mode using the following commands:
7171

7272
{% tabs %}
73-
{% highlight c# tabtitle="Blazor Web App" %}
73+
{% highlight c# tabtitle="Blazor Web App Server" %}
7474

7575
dotnet new blazor -o BlazorWebApp -int Server
7676
cd BlazorWebApp
@@ -119,7 +119,7 @@ For Server interactive render mode, open the **~/Components/_Imports.razor** fil
119119
Register the Syncfusion Blazor service in the **~/Program.cs** file:
120120

121121
{% tabs %}
122-
{% highlight C# tabtitle="Blazor Web App" hl_lines="3 10" %}
122+
{% highlight C# tabtitle="Blazor Web App Server" hl_lines="3 10" %}
123123

124124
using Microsoft.AspNetCore.Components;
125125
using Microsoft.AspNetCore.Components.Web;
@@ -166,7 +166,7 @@ For OpenAI, obtain an API key from [OpenAI](https://help.openai.com/en/articles/
166166
Add the following to the **~/Program.cs** file:
167167

168168
{% tabs %}
169-
{% highlight C# tabtitle="Blazor Web App" hl_lines="7 8 9 11 12 13" %}
169+
{% highlight C# tabtitle="Blazor Web App Server" hl_lines="7 8 9 11 12 13" %}
170170

171171
using Microsoft.AspNetCore.Components;
172172
using Microsoft.AspNetCore.Components.Web;
@@ -204,7 +204,7 @@ For Azure OpenAI, deploy a resource and model as described in [Azure OpenAI docu
204204
Add the following to the **~/Program.cs** file:
205205

206206
{% tabs %}
207-
{% highlight C# tabtitle="Blazor Web App" hl_lines="7 8 9 11 12 13" %}
207+
{% highlight C# tabtitle="Blazor Web App Server" hl_lines="7 8 9 11 12 13" %}
208208

209209
using Microsoft.AspNetCore.Components;
210210
using Microsoft.AspNetCore.Components.Web;

blazor/smart-textarea/getting-started-webapp.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
layout: post
33
title: Blazor Smart TextArea Tutorial | Syncfusion
4-
description: Learn how to get started with the Syncfusion Blazor Smart TextArea component in a Blazor Web App, including setup and AI configuration.
4+
description: Learn how to get started with the Syncfusion Blazor Smart TextArea component in a Blazor Web App Server, including setup and AI configuration.
55
platform: Blazor
66
control: Smart TextArea
77
documentation: ug
88
---
99

1010
# Getting Started with Blazor Smart TextArea
1111

12-
The Syncfusion Blazor Smart TextArea component provides AI-powered autocompletion for context-aware text input, suitable for applications like issue trackers or customer support systems. This section explains how to integrate the component into a Blazor Web App using Visual Studio or Visual Studio Code.
12+
The Syncfusion Blazor Smart TextArea component provides AI-powered autocompletion for context-aware text input, suitable for applications like issue trackers or customer support systems. This section explains how to integrate the component into a Blazor Web App Server using Visual Studio or Visual Studio Code.
1313

1414
To get started quickly, watch this video tutorial:
1515

@@ -29,9 +29,9 @@ To get started quickly, watch this video tutorial:
2929

3030
N> Syncfusion Blazor Smart Components support both OpenAI and Azure OpenAI and are compatible with Blazor Server Interactivity mode.
3131

32-
## Create a New Blazor Web App in Visual Studio
32+
## Create a New Blazor Web App Server in Visual Studio
3333

34-
Create a **Blazor Web App** using Visual Studio 2022 with [Microsoft Templates](https://learn.microsoft.com/en-us/aspnet/core/blazor/tooling?view=aspnetcore-8.0) or the [Syncfusion Blazor Extension](https://blazor.syncfusion.com/documentation/visual-studio-integration/template-studio). Configure the app with the Server interactive render mode.
34+
Create a **Blazor Web App Server** using Visual Studio 2022 with [Microsoft Templates](https://learn.microsoft.com/en-us/aspnet/core/blazor/tooling?view=aspnetcore-8.0) or the [Syncfusion Blazor Extension](https://blazor.syncfusion.com/documentation/visual-studio-integration/template-studio). Configure the app with the Server interactive render mode.
3535

3636
## Install Syncfusion Blazor SmartComponents and Themes NuGet Packages
3737

@@ -65,9 +65,9 @@ N> Syncfusion Blazor components are available on [nuget.org](https://www.nuget.o
6565

6666
N> Syncfusion Blazor Smart Components support both OpenAI and Azure OpenAI and are compatible with Blazor Server Interactivity mode.
6767

68-
## Create a New Blazor Web App in Visual Studio Code
68+
## Create a New Blazor Web App Server in Visual Studio Code
6969

70-
Create a **Blazor Web App** using Visual Studio Code with [Microsoft Templates](https://learn.microsoft.com/en-us/aspnet/core/blazor/tooling?view=aspnetcore-8.0&pivots=vsc) or the [Syncfusion Blazor Extension](https://blazor.syncfusion.com/documentation/visual-studio-code-integration/create-project). Configure the app with the Server interactive render mode using the following commands:
70+
Create a **Blazor Web App Server** using Visual Studio Code with [Microsoft Templates](https://learn.microsoft.com/en-us/aspnet/core/blazor/tooling?view=aspnetcore-8.0&pivots=vsc) or the [Syncfusion Blazor Extension](https://blazor.syncfusion.com/documentation/visual-studio-code-integration/create-project). Configure the app with the Server interactive render mode using the following commands:
7171

7272
{% tabs %}
7373
{% highlight c# tabtitle="Blazor Web App Server" %}

0 commit comments

Comments
 (0)