1. Introduction

Welcome to the Perplexity API Add-on for Google Sheets! This powerful tool allows you to harness the capabilities of the Perplexity AI directly within your spreadsheets. With this add-on, you can generate text, answer questions, and perform various AI-powered tasks without leaving your Google Sheet.

Benefits:

  • Easy access to AI-powered text generation and question-answering
  • Customisable settings to fit your specific needs
  • Seamless integration with your existing Google Sheets workflows

Perplexity for Google Sheets Add On

2. Installation

Follow these simple steps to add the Perplexity API script to your Google Sheet:

  1. Open your Google Sheet
  2. Click on "Extensions" in the top menu
  3. Select "Apps Script"
  4. Delete any existing code in the script editor
  5. Copy and paste the entire Perplexity API script into the editor
  6. Click the disk icon to save the script
  7. Give your project a name (e.g., "Perplexity API Add-on")
  8. Close the Apps Script tab
  9. Refresh your Google Sheet

After refreshing, you should see a new menu item called "Perplexity API" in your Google Sheets top menu.

3. Initial Setup

Before you can start using the add-on, you need to configure your API key:

  1. Obtain a Perplexity API key:
    • Visit the Perplexity AI website
    • Sign up or log in to your account
    • Navigate to the API section and generate a new API key
  2. Enter your API key in Google Sheets:
    • Click on the "Perplexity API" menu in your Google Sheet
    • Select "Configure API Key"
    • In the popup window, paste your API key
    • Click "OK" to save

Your API key is now securely stored and ready to use with the add-on.

4. Configuring Default Settings

The add-on allows you to customise several settings for optimal use:

Setting the Default Model

  1. Click on "Perplexity API" > "Set Default Model"
  2. Choose from the following options:
    1. llama-3.1-sonar-small-128k-online (Fastest, suitable for simple tasks)
    2. llama-3.1-sonar-large-128k-online (Balanced speed and capability)
    3. llama-3.1-sonar-huge-128k-online (Most capable, but slower)
    4. llama-3.1-8b-instruct (Offline model, faster but less capable)
    5. llama-3.1-70b-instruct (Offline model, more capable but slower)
  3. Enter the number corresponding to your choice
  4. Click "OK" to save

Setting Default Max Tokens

This setting determines the maximum length of the AI's response:

  1. Click on "Perplexity API" > "Set Default Max Tokens"
  2. Choose from the following options:
    1. 100 (Short responses)
    2. 1000 (Medium-length responses)
    3. 5000 (Long responses)
    4. Unlimited (No length limit, but may result in higher API usage)
  3. Enter the number corresponding to your choice
  4. Click "OK" to save

Setting Rate Limit

To avoid excessive API usage, you can set a rate limit:

  1. Click on "Perplexity API" > "Set Rate Limit"
  2. Enter the maximum number of API calls allowed per minute
  3. Click "OK" to save

A good starting point is 10 calls per minute, but adjust based on your needs and API plan.

5. Using the PERPLEXITY Function

Now you're ready to use the PERPLEXITY function in your spreadsheet!

Basic Usage

In any cell, type:

=PERPLEXITY(A1)
 

This will use the content of cell A1 as the prompt for the AI.

Advanced Usage

You can override the default model and max tokens for specific calls:

=PERPLEXITY(A1, "llama-3.1-sonar-large-128k-online", 1000)
 

This uses the content of A1 as the prompt, specifies the large model, and sets a max token limit of 1000.

Examples

  1. Simple question answering:
    =PERPLEXITY("What is the capital of France?")
     
  2. Text generation with a specific model:
    =PERPLEXITY(A1, "llama-3.1-sonar-huge-128k-online")
     
  3. Long-form content generation:
    =PERPLEXITY(B5, "llama-3.1-sonar-large-128k-online", 5000)

6. Understanding the Results

After using the PERPLEXITY function, the cell will display one of the following:

  • The AI-generated response to your prompt
  • An error message if something went wrong

If you see an error message, refer to the Troubleshooting section below.

7. Troubleshooting

Common issues and solutions:

  1. "API Key not configured": Make sure you've entered your API key as described in the Initial Setup section.
  2. "Rate limit exceeded": Wait a minute before making more calls, or increase your rate limit if needed.
  3. "API returned status [number]": Check the script logs for more details:
    • In Google Sheets, go to Extensions > Apps Script
    • Click on "Executions" in the left sidebar
    • Look for recent executions of the PERPLEXITY function and check their logs

8. Best Practices

  • Start with shorter outputs and increase as needed to manage API usage.
  • Use cell references for prompts to easily update and reuse them.
  • If you're doing many API calls, spread them out over multiple cells to avoid hitting rate limits.

9. Privacy and Security Considerations

Your API key is stored securely in Google's Script Properties and is only used to authenticate API calls to Perplexity. It's not visible to other users of the sheet.

10. Getting Help

If you encounter issues not covered in this guide:

  1. Check the Perplexity AI documentation for API-specific questions.
  2. For add-on specific issues, contact email me at tools{@}broadhurst.digital
  3. For general Google Sheets questions, refer to Google's Sheets Help Center.

Remember, while this add-on is powerful, it interacts with an AI model. Always review the generated content for accuracy and appropriateness before using it for important tasks.

Comments