You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Claude AI Service with Smart Components in Blazor App | Syncfusion
4
-
description: Learn how to integrate and use the Syncfusion component in a Blazor Web App with Claude AI services.
3
+
title: Claude AI Integration with Blazor Smart Paste Button | Syncfusion
4
+
description: Learn how to integrate the Syncfusion Blazor Smart Paste Button with Claude AI services in a Blazor App.
5
5
platform: Blazor
6
6
control: Smart Paste Button
7
7
documentation: ug
8
8
---
9
9
10
-
# Getting Started with Smart Components using Claude AI
10
+
# Claude AI Integration with Blazor Smart Paste Button
11
11
12
-
This guide walks you through integrating Anthropic's Claude AI with Syncfusion<supstyle="font-size:70%">®</sup> Smart Components in your Blazor App.
12
+
The Syncfusion Blazor SmartPaste Button component enables AI-powered, context-aware content pasting into forms, typically using OpenAI or Azure OpenAI. This guide explains how to integrate the Anthropic Claude AI service with the Smart Paste Button using the `IChatInferenceService` interface, enabling custom AI-driven responses in a Blazor Web App.
13
13
14
-
## Prerequisites
14
+
## Setting Up Claude
15
15
16
-
Before you begin, ensure you have:
16
+
1.**Create an Anthropic Account**
17
+
Visit [Anthropic Console](https://console.anthropic.com), sign up, and complete the verification process.
18
+
2.**Obtain an API Key**
19
+
Navigate to [API Keys](https://console.anthropic.com/settings/keys) and click "Create Key."
20
+
3.**Review Model Specifications**
21
+
Refer to [Claude Models Documentation](https://docs.anthropic.com/claude/docs/models-overview) for details on available models.
17
22
18
-
*[System requirements for Blazor components](https://blazor.syncfusion.com/documentation/system-requirements)
19
-
* Claude account and API key (see setup instructions below)
23
+
## Create a Claude AI Service
20
24
21
-
### Setting Up Claude
25
+
Create a service class to manage interactions with the Claude API, including authentication and response processing for the Smart Paste Button.
returnresponseObject?.Content?.FirstOrDefault()?.Text??"No response from Claude model.";
123
89
}
124
90
catch (Exceptionex) when (exisHttpRequestException||exisJsonException)
@@ -129,32 +95,30 @@ public class ClaudeAIService
129
95
}
130
96
```
131
97
132
-
## Step 2: Define Request and Response Models
98
+
N> Store the Claude API key in `appsettings.json` (e.g., `{ "Claude": { "ApiKey": "your-api-key" } }`) or as an environment variable to ensure security. Verify the `anthropic-version` header in [Claude API Documentation](https://docs.anthropic.com/claude/docs) for the latest version.
133
99
134
-
To effectively communicate with Claude's API, we need to define structured models for our requests and responses. These models ensure type safety and make the code more maintainable.
100
+
## Define Request and Response Models
135
101
136
-
### Request Models
137
-
The request models define the structure of data we send to Claude.
102
+
Define C# classes to match the Claude API’s JSON request and response format.
138
103
139
-
### Response Models
140
-
The response models handle Claude's API responses.
104
+
1. Create a new file named `ClaudeModels.cs` in the `Services` folder.
105
+
2. Add the following model classes:
141
106
142
-
```CSharp
107
+
```csharp
143
108
publicclassClaudeChatRequest
144
109
{
145
110
publicstringModel { get; set; }
146
111
publicintMax_tokens { get; set; }
147
112
publicList<ClaudeMessage> Messages { get; set; }
148
-
publicList<string> Stop_sequences { get; set; }
113
+
publicList<string> Stop_sequences{ get; set; }
149
114
}
150
115
151
116
publicclassClaudeMessage
152
117
{
153
-
publicstringRole { get; set; }// "user" or "assistant"
@@ -166,53 +130,134 @@ public class ClaudeContentBlock
166
130
}
167
131
```
168
132
169
-
## Step 3: Create a Custom AI Service
133
+
## Create a Custom AI Service
170
134
171
-
To integrate Claude with Syncfusion<supstyle="font-size:70%">®</sup> Smart Components, you need to implement the `IChatInferenceService` interface. This interface acts as a bridge between Syncfusion's components and Claude's AI capabilities.
135
+
Implement the `IChatInferenceService` interface to connect the Smart Paste Button to the Claude service, acting as a bridge for AI-generated responses.
172
136
173
-
The `IChatInferenceService` interface is designed to allow custom AI service implementations. It defines the contract for how Syncfusion<supstyle="font-size:70%">®</sup> components communicate with AI services:
137
+
1. Create a new file named `ClaudeInferenceService.cs` in the `Services` folder.
138
+
2. Add the following implementation:
174
139
175
-
1. Create a new file named `MyCustomService.cs`
176
-
2. Add the Syncfusion<supstyle="font-size:70%">®</sup> namespace
Configure your Blazor application to use the Claude AI service with Syncfusion<supstyle="font-size:70%">®</sup> Smart Components. This involves registering necessary services and setting up the dependency injection container.
162
+
Register the Claude service and `IChatInferenceService` implementation in the dependency injection container.
Hi, my name is Jane Smith. You can reach me at [email protected] or call me at +1-555-987-6543. I live at 789 Pine Avenue, Suite 12, Los Angeles, CA 90001.
[Required(ErrorMessage = "Please enter your name.")]
221
+
[Display(Name = "Name")]
222
+
public string Name { get; set; }
223
+
224
+
[Required(ErrorMessage = "Please enter your email address.")]
225
+
[Display(Name = "Email ID")]
226
+
public string Email { get; set; }
227
+
228
+
[Required(ErrorMessage = "Please enter your mobile number.")]
229
+
[Display(Name = "Phone Number")]
230
+
public string Phone { get; set; }
231
+
232
+
[Required(ErrorMessage = "Please enter your address.")]
233
+
[Display(Name = "Address")]
234
+
public string Address { get; set; }
235
+
}
236
+
}
237
+
```
238
+
239
+
N> Ensure the [Syncfusion Blazor DataForm](https://blazor.syncfusion.com/documentation/data-form/getting-started-with-web-app) package is installed for form integration.
240
+
241
+
## Testing the Integration
242
+
243
+
1. Configure the Blazor Web App with the Groq AI service and Smart Paste Button as described above.
244
+
2. Add the code to **~/Pages/Home.razor**, **Program.cs**, and the `Services` folder.
245
+
3. Run the application using <kbd>Ctrl</kbd>+<kbd>F5</kbd> (Windows) or <kbd>⌘</kbd>+<kbd>F5</kbd> (macOS).
246
+
4. Copy the sample content provided in the Razor file.
247
+
5. Click the **Smart Paste** button to verify that the form fields are populated correctly using the Groq AI service.
248
+
249
+

250
+
251
+
N> [View Sample in GitHub](https://github.com/syncfusion/smart-ai-samples).
252
+
253
+
## Troubleshooting
254
+
255
+
If the Claude AI integration does not work, try the following:
256
+
-**No Suggestions Displayed**: Verify that the Claude API key and model name are correct in the configuration. Check the `ClaudeAIService` implementation for errors.
257
+
-**HTTP Request Failures**: Ensure a stable internet connection and that the Claude API endpoint (`https://api.anthropic.com/v1/messages`) is accessible. Test with HTTP/2 if compatibility issues arise.
258
+
-**Service Registration Errors**: Confirm that `ClaudeAIService` and `ClaudeInferenceService` are registered in **Program.cs**.
259
+
260
+
## See Also
217
261
218
-
```
262
+
-[Getting Started with Syncfusion Blazor Smart Paste Button in Blazor Web App](https://blazor.syncfusion.com/documentation/smart-paste/getting-started-webapp)
0 commit comments