Skip to main content
SwissKnife includes AI-powered document summarization using Google’s Gemini AI models. This guide covers setup, configuration, and usage of the AI features.

Prerequisites

AI features require:
  • Valid Google API key
  • Internet connectivity
  • google-genai Python package (installed with core dependencies)

Getting Your Gemini API Key

1

Sign up for Google AI Studio

Visit aistudio.google.com and sign in with your Google account
2

Create a new project

If you don’t have an existing project, create a new one in Google AI Studio
3

Generate API key

  • Navigate to “Get API Key” in the sidebar
  • Click “Create API Key” button
  • Select your Google Cloud project or create a new one
  • Copy the generated API key
4

Store the API key securely

Keep your API key private and never commit it to version control
Protect your API key: Never share your API key publicly or commit it to Git repositories. Anyone with access to your key can use your Google AI quota.

Environment Variable Configuration

Set your API key as an environment variable so SwissKnife can access it:

Temporary (Current Session)

export GOOGLE_API_KEY="your_api_key_here"

Permanent Configuration

Add to your shell configuration file:For Bash (~/.bashrc or ~/.bash_profile):
echo 'export GOOGLE_API_KEY="your_api_key_here"' >> ~/.bashrc
source ~/.bashrc
For Zsh (~/.zshrc):
echo 'export GOOGLE_API_KEY="your_api_key_here"' >> ~/.zshrc
source ~/.zshrc

Verify Configuration

echo $GOOGLE_API_KEY

Using Document Summarization

Once your API key is configured, you can summarize documents using the summarize command:

Basic Usage

# Generate a summary with default (medium) length
python solution.py summarize document.pdf

# Specify summary length
python solution.py summarize report.docx --length short
python solution.py summarize thesis.txt --length medium
python solution.py summarize book.pdf --length long

Summary Length Options

Short summary - Brief overview of the document
  • Description: A brief summary about the essence of the document in 1 paragraph
  • Max tokens: 1,500
  • Temperature: 0.5 (more focused and deterministic)
  • Best for: Quick overviews, executive summaries

Output

The summarization process will:
  1. Validate the input file and size
  2. Upload the document to Google AI service
  3. Process the document using Gemini AI
  4. Display the summary in the terminal
  5. Save the summary as {original_filename}_summary.txt
python solution.py summarize research_paper.pdf --length long

File Size Limits

Maximum file size: 100 MBFiles exceeding 100MB will be rejected before upload to prevent quota issues and long processing times.
The file size check happens before uploading:
file_size_mb = input_abs.stat().st_size / (1024 * 1024)
if file_size_mb > 100:
    raise ValueError(f"File size ({file_size_mb:.1f}MB) exceeds maximum limit of 100MB")
Tips for large files:
  • Split large PDFs using the split command before summarizing
  • Extract specific sections or chapters
  • Compress media-heavy documents by removing images

Custom Prompt Configuration

You can customize the AI behavior by modifying the system prompt template.

Prompt Template File

The AI prompt is stored in summarize_prompt.txt in the root directory of SwissKnife. This file contains the instructions that guide how Gemini generates summaries.

Template Placeholders

The prompt template supports two dynamic placeholders that are automatically replaced during summarization:
{{FILE_DETAILS}}
JSON
Replaced with JSON representation of the uploaded file metadata, including:
  • File name
  • MIME type
  • File size
  • Upload timestamp
  • File URI
{{SUMMARY_REQUIREMENTS}}
string
Replaced with the description of the desired summary length and format based on the --length parameter:
  • Short: “a brief summary about the essence of the document in 1 paragraph”
  • Medium: “a concise summary about the essence of the document in 2-3 paragraphs”
  • Long: “a detailed summary about the essence of the document in 3-4 paragraphs”

Example Prompt Template

summarize_prompt.txt
You are an AI assistant specialized in generating concise, accurate summaries of documents.

Your task is to analyze the provided document and create a summary that captures the key points, main ideas, and essential information.

File Details:
{{FILE_DETAILS}}

Summary Requirements:
- {{SUMMARY_REQUIREMENTS}}
- Focus on the main topics and themes
- Use clear, professional language
- Maintain factual accuracy
- Avoid unnecessary details

Provide your summary below:

Customizing the Prompt

1

Locate the prompt file

Find summarize_prompt.txt in the SwissKnife root directory
2

Edit the template

Modify the prompt instructions while preserving the placeholders:
  • Keep {{FILE_DETAILS}} and {{SUMMARY_REQUIREMENTS}} intact
  • Add specific instructions for your use case
  • Adjust tone, style, or focus areas
3

Save and test

Save the file and test with a sample document to verify the changes
You are an AI specialized in academic document analysis.

Analyze this document with focus on:
- Research methodology
- Key findings and conclusions
- Theoretical frameworks
- Citations and references

File Details:
{{FILE_DETAILS}}

Generate {{SUMMARY_REQUIREMENTS}} with emphasis on scholarly contributions.

AI Model Configuration

SwissKnife uses Google’s Gemini 2.5 Flash model for summarization:
model="gemini-2.5-flash"
Model parameters:
  • Top P: 0.9 (nucleus sampling for diverse outputs)
  • Temperature: Varies by length (0.5-0.8)
  • Max Output Tokens: Varies by length (1,500-4,000)

Troubleshooting

Error: EnvironmentError: GOOGLE_API_KEY environment variable is not set.Solution:
  • Verify the environment variable is set: echo $GOOGLE_API_KEY (Linux/macOS) or echo %GOOGLE_API_KEY% (Windows)
  • Check for typos in the variable name (must be exactly GOOGLE_API_KEY)
  • Restart your terminal after setting the variable
  • Ensure you’ve activated the virtual environment if using one
Error: ValueError: File size (125.3MB) exceeds maximum limit of 100MBSolution:
  • Split large PDFs: python solution.py split large.pdf "1-50"
  • Extract only relevant sections from the document
  • Convert media-heavy documents to text format first
  • Compress images in the document before processing
Error: TimeoutError: File processing timed outSolution:
  • Large files may take longer to process (timeout set to 5 minutes)
  • Check your internet connection
  • Try with a smaller document first
  • Retry the operation as it may be a temporary API issue
Error: ValueError: Generated summary is empty or too shortSolution:
  • Ensure the document contains extractable text
  • Image-only PDFs may not work well (use OCR first)
  • Try adjusting the prompt template for better results
  • Increase summary length parameter (use --length long)
Error: API quota exceeded or 429 Too Many RequestsSolution:
  • Check your Google AI Studio quota limits
  • Wait before making additional requests
  • Consider upgrading your API plan for higher quotas
  • Monitor your API usage in Google Cloud Console
Error: Invalid API key or 401 UnauthorizedSolution:
  • Verify your API key is correct (no extra spaces or quotes)
  • Check if the API key is still active in Google AI Studio
  • Regenerate a new API key if the old one was revoked
  • Ensure the API key has proper permissions

Best Practices

Choose Appropriate Length

  • Use short for quick overviews
  • Use medium for balanced summaries (default)
  • Use long for comprehensive analysis

Optimize File Size

  • Keep files under 100MB
  • Split large documents first
  • Remove unnecessary content

Secure Your API Key

  • Never commit to version control
  • Use environment variables
  • Rotate keys periodically

Customize Prompts

  • Tailor prompts to your domain
  • Test changes with samples
  • Keep placeholders intact

Build docs developers (and LLMs) love