Skip to content

Latest commit

 

History

History
195 lines (141 loc) · 5.58 KB

File metadata and controls

195 lines (141 loc) · 5.58 KB

API Verification Feature

Overview

The Paper Polish System now includes a built-in verify command that validates your Gemini API configuration before running the paper polishing workflow. This helps identify configuration issues early and provides clear diagnostic information.

Quick Start

Basic Usage

# Verify with default config.json
python main.py verify

# Verify with custom config file
python main.py verify --config path/to/config.json

Help

python main.py verify --help

What It Checks

The verify command performs the following checks:

  1. Configuration File: Verifies the config file exists and is readable
  2. API Key: Checks that an API key is configured and not using placeholder text
  3. API Connection: Attempts a test API call to Gemini
  4. Model Availability: Confirms the configured model is available
  5. Response: Validates that the API returns a proper response

Output Examples

Successful Verification

╭─────────────────────╮
│ 🔍 API Verification │
╰─────────────────────╯

📂 Loading configuration...
🔐 Checking API key...
✓ API key found (length: 39 chars)
🔄 Testing API connection...
✓ API connection successful

┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
┃ Key                 ┃ Value                 ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩
│ Provider            │ gemini                │
│ Model               │ gemini-1.5-pro        │
│ API Key Status      │ ✓ Valid               │
│ Connection          │ ✓ Working             │
│ Test Response       │ API connection works! │
└─────────────────────┴───────────────────────┘

✨ All checks passed! Your API is ready to use.

Missing API Key

╭─────────────────────╮
│ 🔍 API Verification │
╰─────────────────────╯

📂 Loading configuration...
🔐 Checking API key...
❌ API key not configured
💡 Please add your Gemini API key to config.json

Connection Error

❌ Verification failed: 404 Model 'gemini-1.5-pro' not found

Troubleshooting tips:
1. Verify your API key is correct
2. Check internet connection
3. Ensure the API key has appropriate permissions
4. Visit: https://aistudio.google.com/app/apikey to check/regenerate key

Troubleshooting

"API key not configured"

"Model not found" error

  • Ensure your API key is valid and has access to the requested model
  • Check available models at: https://aistudio.google.com/app/apikey
  • Common valid models:
    • gemini-1.5-pro - Recommended for academic papers
    • gemini-1.5-flash - Faster, lower cost
    • gemini-2.0-pro - Latest features (if available)

"Connection error" or timeout

  • Check your internet connection
  • Verify the API key has proper permissions
  • Check if Google's Gemini API service is operational
  • Try increasing timeout_seconds in config.json

API returns empty response

  • The test prompt may be getting filtered by safety settings
  • This is usually temporary; try again after a moment
  • Check your API quota hasn't been exceeded

Integration with Main Workflow

Before running the paper polishing workflow:

# 1. Initialize config (creates template)
python main.py init

# 2. Add your API key to config.json

# 3. Verify the setup works
python main.py verify

# 4. If verification passes, you're ready to polish papers
python main.py polish your_paper.tex

Technical Details

Configuration Requirements

The verify command reads from your config.json:

{
  "api": {
    "provider": "gemini",
    "model": "gemini-1.5-pro",
    "api_key": "<YOUR_GEMINI_API_KEY_HERE>",
    "temperature": 0.7,
    "max_tokens": 4096,
    "timeout_seconds": 120
  }
}

Safety Settings

The verify command (and all API calls) use the following safety settings:

  • HARM_CATEGORY_SEXUALLY_EXPLICIT: BLOCK_NONE
  • HARM_CATEGORY_DANGEROUS_CONTENT: BLOCK_NONE
  • HARM_CATEGORY_HARASSMENT: BLOCK_NONE
  • HARM_CATEGORY_HATE_SPEECH: BLOCK_NONE

This ensures academic content is not inappropriately filtered.

Test Prompt

The verify command uses this test prompt:

"Say 'API connection successful!' in exactly 5 words."

This simple test validates that the API can receive and respond to prompts correctly.

Exit Codes

  • 0: All checks passed, API is ready to use
  • 1: Verification failed (see error messages for details)

Adding to Your Workflow

You can add verification to automated scripts:

#!/bin/bash
# Verify API before running analysis
python main.py verify || exit 1

# If we get here, API is working
python main.py polish input.tex --output-dir results

Customizing Verification

To modify what the verify command checks or how it tests the API, edit the verify() function in main.py.

Related Documentation