Skip to content

kamilstanuch/ai-spreadsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GROQ AI Integration for Google Sheets

A powerful Google Apps Script that brings AI capabilities directly to your Google Sheets using the Groq API. Transform your spreadsheets into intelligent data analysis tools with just a few clicks.

groq-spreadsheet-gif

πŸš€ Features

  • Direct AI Integration: Send prompts to Groq AI models directly from spreadsheet cells
  • Smart Context Processing: Automatically format spreadsheet data as context for AI analysis
  • Header Detection: Intelligently recognizes and formats data with headers
  • Error Handling: Comprehensive error handling with user-friendly messages
  • Debug Logging: Built-in logging for troubleshooting and development
  • Flexible Input: Support for both range references and single cell values
  • Simple Setup: Copy-paste script into any spreadsheet
  • Reliable: Works immediately after setup

πŸ“‹ Prerequisites

  • A Google account with access to Google Sheets
  • A Groq API key (Get one here)
  • Basic familiarity with Google Apps Script

🎯 Simple and Reliable

Why This Approach Works:

  • βœ… Copy-paste setup: Simple and straightforward
  • βœ… Works immediately: No complex library or deployment issues
  • βœ… Per-spreadsheet control: Each spreadsheet has its own copy
  • βœ… Easy troubleshooting: Clear error messages and logging
  • βœ… No Google Apps Script limitations: Avoids library and web app complications

No more library bullshit, no more deployment issues, just copy-paste and use!

⚠️ Important Notice

Google Apps Script Limitation: Unfortunately, Google Apps Script doesn't provide a native way to make custom functions globally available across all your spreadsheets automatically. This is a platform limitation, not a flaw in this script.

What this means:

  • Each spreadsheet needs its own copy of the script
  • You need to repeat the installation steps for each spreadsheet
  • There's no "install once, use everywhere" solution with Google Apps Script custom functions

Why we use this approach:

  • It's the most reliable method available
  • Works consistently without complex workarounds
  • Easy to understand and troubleshoot
  • No false promises about global availability

πŸ› οΈ Installation (Per Spreadsheet)

Step 1: Open Your Spreadsheet's Apps Script

  1. Open the Google Sheet where you want to use the GROQ function
  2. Go to Extensions β†’ Apps Script
  3. This opens the Apps Script editor for this specific spreadsheet

Step 2: Copy the Script

  1. Delete any existing code in the editor
  2. Copy the entire content from groq.gs
  3. Paste it into the Apps Script editor
  4. Save the project (Ctrl+S or Cmd+S)

Step 3: Set Up Your Groq API Key

  1. In the Apps Script editor, go to Project Settings (gear icon)
  2. Scroll down to Script Properties
  3. Click Add script property
  4. Set:
    • Property: GROQ_API_KEY
    • Value: Your Groq API key
  5. Click Save

Step 4: Authorize the Script

  1. Go back to the main Apps Script editor
  2. Click Run β†’ Run function β†’ GROQ
  3. When prompted, click Authorize access
  4. Choose your Google account
  5. Click Allow

Step 5: Use the Function

That's it! Now you can use =GROQ(prompt, contextRange) in this spreadsheet.

Repeat these steps for each spreadsheet where you want to use the GROQ function.

πŸ“– Usage

Basic Syntax

=GROQ(prompt, contextRange)

Note: You need to repeat the installation steps for each spreadsheet where you want to use the GROQ function.

Parameters

  • prompt (required): The text instruction to send to the AI
  • contextRange (optional): A spreadsheet range (e.g., A1:E10) or single cell whose data will be included as context

Examples

1. Simple Question

=GROQ("What is the capital of France?")

2. Data Analysis with Context

=GROQ("Summarize this sales data", A1:E20)

3. Single Cell Context

=GROQ("Translate to Spanish", B1)

4. Trend Analysis

=GROQ("What's the trend in this data?", C2:C50)

πŸ“Š Data Formatting

The script intelligently formats your spreadsheet data:

With Headers

If your data has headers in the first row:

Name: John, Age: 25, City: New York
Name: Jane, Age: 30, City: Los Angeles

Without Headers

If no headers are detected:

John, 25, New York
Jane, 30, Los Angeles

βš™οΈ Configuration

AI Model

The script uses the gemma2-9b-it model by default. You can modify this in the code:

const model = "gemma2-9b-it"; // Change to other models like "mixtral-8x7b-32768"

Response Parameters

  • Temperature: 0.6 (creativity level, 0.0-1.0)
  • Max Tokens: 1024 (maximum response length)

πŸ”§ Troubleshooting

Common Issues

"Error: Groq API Key not found"

  • Ensure you've set the GROQ_API_KEY script property correctly
  • Check that the property name is exactly GROQ_API_KEY

"Error from Groq API (401)"

  • Your API key is invalid or expired
  • Generate a new API key from the Groq console

"Error from Groq API (429)"

  • You've exceeded your API rate limits
  • Wait a moment and try again

"Error: Unexpected AI response format"

  • The Groq API response structure has changed
  • Check the Apps Script logs for detailed error information

"GROQ is not defined" or "Function not found"

  • Make sure you've copied the script into this spreadsheet's Apps Script
  • Check that you've saved the script after pasting
  • Verify that you've authorized the script (Step 4)

"Error: Groq API Key not found"

  • Ensure you've set the GROQ_API_KEY script property correctly
  • Check that the property name is exactly GROQ_API_KEY
  • Make sure you're in the correct Apps Script project for this spreadsheet

Debug Logging

The script includes comprehensive logging. To view logs:

  1. In Apps Script editor, click View β†’ Execution log
  2. Run your function and check the logs for detailed information

πŸ“ Examples

Sales Data Analysis

=GROQ("Analyze this sales data and identify the top performing products", A1:F100)

Text Processing

=GROQ("Extract key insights from this customer feedback", B2:B50)

Data Summarization

=GROQ("Create a summary of this quarterly report data", A1:Z20)

Translation

=GROQ("Translate this text to French", C1)

πŸ”’ Security Considerations

  • Your API key is stored securely in Google Apps Script properties
  • API calls are made server-side, not from your browser
  • Consider setting up API key rotation for production use
  • Monitor your Groq API usage to control costs

πŸ“ˆ Performance Tips

  • Keep context ranges reasonable in size (avoid entire sheets)
  • Use specific prompts for better results
  • Consider caching responses for repeated queries
  • Monitor API usage to stay within rate limits

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Kamil Stanuch - Initial work - [GitHub Profile]

Created on: 2025-07-25

πŸ™ Acknowledgments

  • Groq for providing the AI API
  • Google Apps Script team for the platform
  • The open-source community for inspiration and feedback

πŸ“ž Support

If you encounter any issues or have questions:

  1. Check the troubleshooting section
  2. Review the Apps Script execution logs
  3. Open an issue on GitHub with detailed information

Note: This script requires an active internet connection and a valid Groq API key to function. API usage may incur costs depending on your Groq plan.

Releases

No releases published

Packages

No packages published