# Prerequisites

| Minimum Version: | Q4 2025 |
| ---------------- | ------- |

To use the GenAI-powered Document Insights functionality in the [RadSpreadProcessing library](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/overview), you need the following references and AI provider setup.

## Required References

In addition to the [standard RadSpreadProcessing references](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/getting-started#package-references), you need to add the following references to use the GenAI-powered Document Insights features:

| .NET Framework                                                    | .NET Standard-compatible                                  |
| ----------------------------------------------------------------- | --------------------------------------------------------- |
| **Telerik.Windows.Documents.AIConnector** \*                      | **Telerik.Documents.AIConnector** \*                      |
| **Telerik.Windows.Documents.Spreadsheet.FormatProviders.Json** \* | **Telerik.Documents.Spreadsheet.FormatProviders.Json** \* |

> **\*** The **Documents.AIConnector** NuGet package internally depends on:
>
> * **Telerik.Documents.AI.Core**
> * **Telerik.Documents.AI.RAG**
>   * **Microsoft.Extensions.AI.Abstractions**
>   * **SharpToken**
>
> **Microsoft.Extensions.AI.Abstractions** is now available only in **preview** version.
> If you reference an *assembly/dll* of **Documents.AIConnector** instead of a NuGet package, you must manually add the **SharpToken** NuGet package.

## NuGet Packages

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

| Package                                              | Use case                            |
| ---------------------------------------------------- | ----------------------------------- |
| `Microsoft.Extensions.AI.OpenAI` + `Azure.AI.OpenAI` | For using Azure OpenAI.             |
| `Microsoft.Extensions.AI.OpenAI` + `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](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/features/gen-ai-powered-document-insights/prerequisites#azure-openai-setup) | [OpenAI Setup](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/features/gen-ai-powered-document-insights/prerequisites#openai-setup) | [Ollama Setup (Local AI)](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/features/gen-ai-powered-document-insights/prerequisites#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.

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

**Example 1: Configure an Azure OpenAI chat client with the endpoint, key, and deployment name**

```C#

// 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 = (IChatClient)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.

**Example 2: Configure an OpenAI chat client with the API key and model ID**

```C#

//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);
OpenAI.Chat.ChatClient chatClient = openAIClient.GetChatClient(modelId);
IChatClient client = (IChatClient)chatClient;
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 for working with sensitive data.

1. Install Ollama from [ollama.com](https://ollama.com/).
2. Pull the model you want to use.
3. Start the Ollama server.

**Example 3: Configure an Ollama chat client for a locally hosted model**

```C#

//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

* [GenAI-powered Document Insights Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/features/gen-ai-powered-document-insights/overview)
* [SummarizationProcessor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/features/gen-ai-powered-document-insights/summarization-processor)
* [PartialContextQuestionProcessor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/features/gen-ai-powered-document-insights/partial-context-question-processor)
* [CompleteContextQuestionProcessor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/features/gen-ai-powered-document-insights/complete-context-question-processor)
