Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Silverlight | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

GenAI-powered Document Insights Prerequisites

This article explains the requirements for using the GenAI-powered Document Insights functionality in the RadPdfProcessing library.

Required Assemblies

In addition to the standard RadPdfProcessing assemblies, you will need to reference the following assemblies to use the GenAI-powered Document Insights features:

.NET Framework .NET Standard-compatible
Telerik.Windows.Documents.AIConnector.dll * Telerik.Documents.AIConnector.dll *

The Documents.AIConnector assembly internally depends on Microsoft.Extensions.AI.Abstractions which is currently available only in preview version.*

NuGet Packages

You will also need to install a package for your specific AI provider:

  • Microsoft.Extensions.AI.OpenAI and Azure.AI.OpenAI - For using Azure OpenAI
  • Microsoft.Extensions.AI.OpenAI and OpenAI - For using OpenAI
  • Microsoft.Extensions.AI.Ollama - For using Ollama (local AI models)

AI Provider Setup

Before using the GenAI-powered Document Insights functionality, you need to set up an AI provider.

Azure OpenAI Setup OpenAI Setup Ollama Setup (Local AI)
Uses the Azure OpenAI service, which provides enterprise-grade security, compliance, and regional availability for OpenAI models. Uses direct access to OpenAI's models through their API service. Suitable for general development scenarios. Runs AI models locally on your machine. Useful for development or working with sensitive data where privacy is important.

Azure OpenAI Setup

  1. Create an Azure OpenAI resource in the Azure portal.
  2. Deploy a model in your Azure OpenAI resource.
  3. Get your Azure OpenAI endpoint and key.

The following code snippet is valid for Microsoft.Extensions.AI.OpenAI 9.3. The specific IChatClient initialization may be different according to the specific version.

[C#] Example 1: Setting up Azure OpenAI

// using Microsoft.Extensions.AI;
// using Azure.AI.OpenAI;

 // Set up Azure OpenAI client
 string key = "your-azure-openai-key";
 string endpoint = "https://your-resource-name.openai.azure.com/";
 string deploymentName = "your-deployment-name";

 AzureOpenAIClient azureClient = new(
     new Uri(endpoint),
     new Azure.AzureKeyCredential(key),
     new AzureOpenAIClientOptions());
 ChatClient chatClient = azureClient.GetChatClient(deploymentName);

 IChatClient iChatClient = new OpenAIChatClient(chatClient);
 int maxTokenLimit = 128000; // Adjust based on your model

OpenAI Setup

  1. Create an OpenAI account.
  2. Get your API key from the OpenAI dashboard.

[C#] Example 2: Setting up OpenAI

//using Microsoft.Extensions.AI;
//using OpenAI;

// Set up OpenAI client
string key = "your-openai-api-key";
string modelId = "gpt-4o-mini";

OpenAI.OpenAIClient openAIClient = new OpenAI.OpenAIClient(key);
IChatClient client = openAIClient.AsChatClient(modelId);
int maxTokenLimit = 128000; // Adjust based on your model

Ollama Setup (Local AI)

Ollama allows you to run AI models locally on your machine. This is useful for development or when dealing with sensitive data.

  1. Install Ollama from ollama.com.
  2. Pull the model you want to use.
  3. Start the Ollama server.

[C#] Example 3: Setting up Ollama

//using Microsoft.Extensions.AI;

// Install and run Ollama:
// 1. Install Ollama: https://ollama.com/
// 2. Pull the model: ollama pull llama3
// 3. Ensure Ollama is running: ollama serve

// Set up Ollama client
IChatClient iChatClient = new OllamaChatClient(new Uri("http://localhost:11434/"), "llama3");
int maxTokenLimit = 4096; // Adjust based on your model

See Also

In this article