Chinese, Japanese

Recently, Feishu's multi-dimensional tables integrated Deepseek, allowing many people to use it for batch content generation and information processing.

In fact, Google Sheets can also achieve this. The method is simple, just follow these steps:

Preparation

First, you need to prepare an API Key. It can be from OpenAI, Deepseek, Grok, or any provider compatible with the OpenAI API.

Application links:

Provider Application Link
OpenAI Here
Deepseek Here
Grok Here

In this example, I'm using Grok, which can be applied for at X.AI.

Enabling AI in Google Sheets

Open the Google Sheet where you want to use AI, and select Extensions > Apps Script from the menu.

An image to describe post

Copy the content of this Apps Script code and paste it into the editor.

An image to describe post

Click the save button in the editor, return to Google Sheets, and prepare four cells. Enter "API Base", "API Key", "Model", and "System Prompt" respectively. In my example, they are located at $C$2, $C$3, $C$4, and $C$5. Then enter the corresponding values.

I'm using grok, so the values are:

Variable Value
API BASE https://api.x.ai/v1
API KEY Your applied API KEY
Model Model name
System Prompt Enter system prompt

Where:

  • API BASE needs to be changed to the corresponding address based on the chosen AI provider. For example, change to https://api.openai.com/v1 for OpenAI, https://api.deepseek.com for Deepseek, and https://api.x.ai/v1 for Grok.
  • Model needs to be changed to the corresponding model name based on the chosen AI provider. For example, change to 4o-mini for OpenAI, deepseek-chat for Deepseek, and grok-2-latest for Grok.
  • System Prompt is the task prompt you write yourself.

Then, directly call AskLLM in Google Sheets like calling a regular function.

An image to describe post

The calling method is:

=AskLLM($C$2, $C$3, $C$4, $C$5, B12) 

Where $C$2, $C$3, $C$4, $C$5 are the four fixed variables mentioned above, and B12 is the content you want to ask AI.

The final effect is as follows:

An image to describe post

Potential Issues and Optimizations

  1. Since the request is sent from the IP of Google's servers, it's uncertain whether it will be banned by the provider. A potentially better approach is to forward the request through your own server, making Google request your server. This way, from the provider's perspective, it appears as if the API is being called from your own server.

  2. When using this method, you need to enter the API Key in Google Sheets, which is often shared with others. If not properly safeguarded, it may lead to private key leakage. The solution is either to delete the API Key after use or implement authentication on your own server.

If Google doesn't officially implement this feature, perhaps turning it into a solution could be marketable 😋.

There are a lot of similar things in Google Workspace Marketplace already.