GuidesAI

Customization

This guide will help you learn to customize AI Chat with PDF feature in Next.js Supabase AI template. Adjust file types, sizes and chat AI models to fit your product requirement.

The Next.js Supabase AI Template include advanced AI feature, such as AI Chat with PDF, enabling users to upload PDFs, parse the content, and obtain insights and answers through text-based queries. This feature transforms uploaded PDFs into a dynamic knowledge base, similar to the functionality of ChatGPT.

This feature leverages Vercel AI SDK to process user queries and deliver accurate responses. We support various AI Models such as OpenAI, Anthropic and Gemini.

Please make sure you have the required environment variables for each of the supported model.


Configuration Options

The AI feature can be tailored to meet specific requirements by modifying configuration settings in the app.config.ts file.

1. Customizing Accepted File Types

You can define the types of files the system accepts using the FILE_TYPE_ACCEPT property. By default, the template supports PDF files only.

// Default configuration
FILE_TYPE_ACCEPT: ["application/pdf"]

To allow additional file types (e.g., CSV or TXT files):

// Example for accepting PDF, CSV, and TXT files
FILE_TYPE_ACCEPT: ["application/pdf", "text/csv", "text/plain"]

2. Customizing Maximum File Size

The FILE_MAX_SIZE_IN_BYTES property allows you to set the maximum file size for uploads. The default limit is 2MB.

// Default configuration
FILE_MAX_SIZE_IN_BYTES: 2097152 // in bytes (2MB)

To increase the limit (e.g., to 5MB):

// Updated configuration for 5MB
FILE_MAX_SIZE_IN_BYTES: 5242880 // in bytes (5MB)

3. Add support for AI Providers to chat

In order to add support for Anthropic and Gemini in PDF Template, you will need to add the environment variables for both as given below

Chat with AI Models

We support Anthropic, Gemini, Grok, OpenAI models to chat with PDF. You can add follow the guide to add support for each model

Chat with OpenAI

OpenAI is supported out of the box and serves as the default model for chat. It provides high-quality, context-aware responses using state-of-the-art language models like GPT-4.

Setup: Ensure your OpenAI API key is added to your environment configuration:

# OpenAI Model
OPENAI_API_KEY=

Tip: Ideal for general-purpose PDF querying with reliable accuracy and broad knowledge coverage.

Chat with Gemini

Gemini, powered by Google, is available for handling PDF conversations with a focus on speed and context understanding. Gemini excels at providing insightful and concise answers, particularly for structured content.

Setup: Add your Google Generative AI API key:

# Gemini AI Model
GOOGLE_GENERATIVE_AI_API_KEY=

Tip: Great for fast, high-quality responses, especially on well-organized documents.

Chat with Anthropic (Claude)

Anthropic's Claude model focuses on safe, thoughtful, and contextually aware conversations. Claude is designed to prioritize ethical responses while delivering accurate insights from your PDF.

Setup: Add your Anthropic API key

# Anhtropic AI Model
ANTHROPIC_API_KEY=

Tip: Best suited for sensitive or compliance-heavy use cases where safety and neutrality are important.

Chat with Grok

Grok, developed by xAI, is another supported model designed for creative and exploratory conversations. It works well for brainstorming, lateral thinking, and generating alternative perspectives based on your PDF content.

Setup: Add your xAI ( Grok ) API key

Tip: Ideal for more casual, creative, or exploratory use cases within your documents.

# Grok AI Model
XAI_API_KEY=

On this page