How can I help you?
Custom AI Service Integration with ASP.NET Core Smart Paste Button
16 Dec 20252 minutes to read
The Syncfusion ASP.NET Core 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.
IChatInferenceService Interface
The IChatInferenceService interface defines a contract for integrating AI services with the Smart Paste Button, enabling the control to process clipboard data for form field mapping.
public interface IChatInferenceService
{
Task<string> GenerateResponseAsync(ChatParameters options);
}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.
Simple Implementation of a Custom AI Service
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.
using Syncfusion.EJ2.AI;
using System.Threading.Tasks;
public class MockAIService : IChatInferenceService
{
public Task<string> GenerateResponseAsync(ChatParameters options)
{
}
}Registering the Custom AI Service
Register the custom AI service in the ~/Program.cs file of your ASP.NET Core Application:
using Syncfusion.EJ2;
using Syncfusion.EJ2.AI;
builder.Services.AddRazorPages();
builder.Services.AddSyncfusionSmartComponents();
builder.Services.AddSingleton<IChatInferenceService, MockAIService>();
var app = builder.Build();
// ...Implemented AI Services
Here are examples of AI services integrated using the IChatInferenceService interface:
| Service | Documentation |
|---|---|
| Claude | Claude Integration |
| DeepSeek | DeepSeek Integration |
| Groq | Groq Integration |
| Gemini | Gemini Integration |
Troubleshooting
If the custom AI integration does not work as expected, try the following:
-
Fields Not Populating: Verify that the custom AI service’s endpoint, model, and API key are correct in
appsettings.json. Ensure theGenerateResponseAsyncmethod returns valid data. -
Service Registration Errors: Confirm that
CustomAIServiceandCustomInferenceServiceare registered in Program.cs. -
AI Parsing Errors: Check the AI service’s response format and ensure it matches the expected
CustomAIResponsestructure. Test the API independently to verify connectivity.