Prerequisites
AI features require:
- Valid Google API key
- Internet connectivity
google-genaiPython package (installed with core dependencies)
Getting Your Gemini API Key
Sign up for Google AI Studio
Visit aistudio.google.com and sign in with your Google account
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
Environment Variable Configuration
Set your API key as an environment variable so SwissKnife can access it:- Linux/macOS
- Windows (CMD)
- Windows (PowerShell)
Using Document Summarization
Once your API key is configured, you can summarize documents using thesummarize command:
Basic Usage
Summary Length Options
- Short
- Medium
- Long
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:- Validate the input file and size
- Upload the document to Google AI service
- Process the document using Gemini AI
- Display the summary in the terminal
- Save the summary as
{original_filename}_summary.txt
File Size Limits
The file size check happens before uploading:- Split large PDFs using the
splitcommand 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 insummarize_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:Replaced with JSON representation of the uploaded file metadata, including:
- File name
- MIME type
- File size
- Upload timestamp
- File URI
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
Customizing the Prompt
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
AI Model Configuration
SwissKnife uses Google’s Gemini 2.5 Flash model for summarization:- 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
API key not found error
API key not found error
Error:
EnvironmentError: GOOGLE_API_KEY environment variable is not set.Solution:- Verify the environment variable is set:
echo $GOOGLE_API_KEY(Linux/macOS) orecho %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
File size limit exceeded
File size limit exceeded
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
File processing timeout
File processing timeout
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
Empty or short summary generated
Empty or short summary generated
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)
API quota exceeded
API quota exceeded
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
Invalid API key
Invalid API key
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