Published using Google Docs
AppSheet Apps Script Vertex AI Simple Sample
Updated automatically every 5 minutes

Simple AppSheet Apps Script Vertex AI Sample

Author: Christian Schalk

Dec 8, 2023

Overview

This is a combined AppSheet app and App Script project that demonstrates how to call the Vertex AI API from an Apps Script function that is called from an AppSheet automation.

The simple use case is an ‘Issue Tracker’ where a user can enter some text in long form. For example: “There is a massive power outage and all production has stopped in the factory!”.

This text is then sent to the Vertex AI (via an Apps Script function) for analysis where both a priority and summary are generated and returned back to the AppSheet app for followup.

This sample consists of:

Special Kudos to DerekCo for providing the initial inspiration for this sample!

Installation steps

Create a GCP Project and enable the Vertex AI API

  1. Sign in to the GCP Console: cloud.google.com.
  2. Create a new Cloud project or open one to which you have access.
  1. Create a new service account.
  1. You will then see your new service account listed in the Service accounts page. Note the service account’s email address, you’ll need this later when setting up your Apps Script project.
  1. Create a JSON security key for your service account.
  1. "private_key": "-----BEGIN PRIVATE KEY-----\n*********\n-----END PRIVATE KEY-----\n",
  1. Enable the Vertex AI API for your project

Your GCP project is now configured. You will need the following when setting up your Apps Script project:

Copy and customize the sample Apps Script project

  1. Open the public Apps Script ‘Issue Tracker’ template project. 
  2. Make a copy of the project by clicking on the copy button on the right side.  

Feel free to rename the project.

  1. In the copied project, open constants.gs.
  2. Update the following:
  1. PROJECT_ID=’<your-project-id>’;
  2. SERVICE_ACCOUNT_EMAIL = '<your-service-account-email-here>';
  3. SERVICE_ACCOUNT_PRIVATE_KEY = '-----BEGIN PRIVATE KEY-----\n<your-service-account-private-key>\n-----END PRIVATE KEY-----\n';
  1. Save the file. Your Apps Script project is now configured.

Copy and customize the AppSheet template

  1. Open the public AppSheet ‘Issue Tracker’ sample.
  2. In the AppSheet editor (on the lower left), click Manage > Collaborate & Publish > Copy App
  1. In the Copy your App dialog, accept the defaults and click Copy app.
  1. After the app is copied, you’ll need to update the Automation to call a function in your copied Apps Script project.
  2. In the AppSheet editor menu, click Automation > When a new Issue
  3. Click on the automation step: “Call Vertex AI via AS
  4. Edit the Apps Script Project field by clicking on the Google Drive icon and locating your copy of the Apps Script project.
  5. After selecting your copied Apps Script project, click the Authorize button and re authenticate with your account.
  1. Note: You can also see in the automation that it will also check if the returned priority from Vertex AI is ‘High’. If so, it will send an Alert email to your account.
  1. Click Save. Your AppSheet app is now configured.

Run the AppSheet app

Now that everything is configured, you can begin running the sample app by entering an issue.

  1. In the app preview on the right, click the Issues tab, and click + to enter a new issue.

Try to enter a High priority issue by using extreme language.

  1. Click on the detail view of the new issue and watch as the priority and response (summary) from Vertex AI appears in a few seconds!

  1.  If the priority was ‘High’, check your email. You’ll see a note about the issue!