Getting Started with Smart PDF Viewer using DeepSeek AI
This guide demonstrates how to integrate DeepSeek’s powerful AI capabilities with Syncfusion Smart PDF Viewer in your Blazor App.
Prerequisites
Before you begin, ensure you have:
- System requirements for Blazor components
- DeepSeek account and API key (see setup instructions below)
Setting Up DeepSeek
-
DeepSeek API Access
- Create a DeepSeek account at platform.deepseek.com
- Navigate to API Keys
-
DeepSeek Models
For detailed specifications and pricing, visit the DeepSeek Models Documentation.
Getting Started for DeepSeek AI with Smart PDF Viewer
After completing this setup, you can:
Install the following NuGet packages to your project:
open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search and install the following packages
1.Microsoft.Extensions.AI.
2.Microsoft.SemanticKernel.
3.Microsoft.SemanticKernel.Connectors.AzureOpenAI.
Step 1: Create a Custom AI Service
To integrate DeepSeek with Syncfusion Smart PDF Viewer, we’ll create a custom implementation of the IChatInferenceService
interface. This interface acts as a bridge between Syncfusion Smart PDF Viewer and your AI service.
The IChatInferenceService
interface is the bridge between Syncfusion Smart PDF Viewer and AI services:S
- Create a new file named
MyCustomService.cs
- Add the following implementation:
using Syncfusion.Blazor.AI;
using Microsoft.Extensions.AI;
public class MyCustomService : IChatInferenceService
{
private IChatClient _chatClient;
public MyCustomService(IChatClient client)
{
this._chatClient = client ?? throw new ArgumentNullException(nameof(client));
}
/// <summary>
/// Sends the chat parameters to the AI client and returns the response.
/// Also checks and updates token usage.
/// </summary>
/// <param name="options">Chat parameters including messages and settings.</param>
/// <returns>AI-generated response text.</returns
public async Task<string> GenerateResponseAsync(ChatParameters options)
{
ChatOptions completionRequest = new ChatOptions
{
Temperature = options.Temperature ?? 0.5f,
TopP = options.TopP ?? 1.0f,
MaxOutputTokens = options.MaxTokens ?? 2000,
FrequencyPenalty = options.FrequencyPenalty ?? 0.0f,
PresencePenalty = options.PresencePenalty ?? 0.0f,
StopSequences = options.StopSequences
};
try
{
ChatResponse completion = await _chatClient.GetResponseAsync(options.Messages[0].Text, completionRequest);
string rawResponse = completion.Text.ToString();
if (rawResponse.Contains("```html") || rawResponse.Contains("```"))
{
rawResponse = rawResponse.Replace("```html", "").Replace("```", "").Trim();
}
return rawResponse;
}
catch (Exception ex)
{
throw new ApplicationException("Error generating AI response", ex);
}
}
}
Step 2: Configure the Blazor App
Configure your Blazor application to use the DeepSeek AI service with Syncfusion Smart PDF Viewer. This involves registering necessary services and setting up the dependency injection container.
using Syncfusion.Blazor.AI;
using Microsoft.Extensions.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
var builder = WebApplication.CreateBuilder(args);
....
builder.Services.AddSyncfusionBlazor();
string deepSeekApiKey = "Your API Key" ?? throw new InvalidOperationException("DEEPSEEK_API_KEY environment variable is not set.");
string deploymentName = "Your Modle Name"; // This must match your Azure deployment name
string endpoint = "https://deepseek-resourceres.services.ai.azure.com/"; // Base endpoint only
var kernelBuilder = Kernel.CreateBuilder().AddAzureOpenAIChatCompletion(
deploymentName: deploymentName,
endpoint: endpoint,
apiKey: deepSeekApiKey);
Kernel kernel = kernelBuilder.Build();
IChatClient deepSeekChatClient = kernel.GetRequiredService<IChatCompletionService>().AsChatClient();
builder.Services.AddChatClient(deepSeekChatClient);
builder.Services.AddScoped<IChatInferenceService, MyCustomService>(sp =>
{
return new MyCustomService(deepSeekChatClient);
});
var app = builder.Build();
....
NOTE
NOTE
Running Deepseek service may lead to slower response times due to system resource usage.
To accommodate this, you can configure the Syncfusion Smart PDF Viewer to disable timeout for AI assist view operations by setting the timeout to 0.
Learn more