
시작하기 전에
- 실습에서는 정해진 기간 동안 Google Cloud 프로젝트와 리소스를 만듭니다.
- 실습에는 시간 제한이 있으며 일시중지 기능이 없습니다. 실습을 종료하면 처음부터 다시 시작해야 합니다.
- 화면 왼쪽 상단에서 실습 시작을 클릭하여 시작합니다.
Configure the OAuth consent screen
/ 30
Create an Apps Script project
/ 30
Apply sentiment analysis
/ 40
Add-ins can extend Google Workspace capabilities to help Google Workspace users be more productive and improve their workflow. In this lab, you build a Google Workspace add-on that leverages the power of Gemini and Vertex AI to conduct sentiment analysis for Gmail. You set up the necessary cloud resources (including the Vertex AI APIs), configure an Apps Script project, and to deploy the add-on.
The add-on allows you to automatically identify and label emails with a negative tone. You can use it to prioritize customer service responses or quickly identify potentially sensitive emails.
By the end of the lab, you'll have a functional tool that demonstrates the practical application of AI for enhancing productivity and communication within a business context.
In this lab, you do the following:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
You've signed into the Google Cloud console. Now you sign into Gmail.
Tip: Arrange the tabs in separate windows for easier viewing.
You're all set to begin the lab activities!
In this task you enable the Vertex AI API and then configure OAuth consent screen to define what Google Workspace displays to users.
In Google Cloud console, in the Navigation menu, click APIs and Services > Library.
Type Vertex AI API into the Search for APIs & Services box, and then click Vertex AI API in the search results.
Click Enable to enable the API.
The API/Service Details page opens.
In the left pane, click OAuth consent screen.
Click Get Started.
For App Information, set the following and then click Next:
Click Check my progress to verify the objective.
In this task, you create and configure your add-on as an Apps Script project.
To get your Google Cloud project number to use when you create an Apps Script project:
In the Navigation menu () click Cloud overview > Dashboard.
From the Project info section, record the Project number to use later in this lab.
In the Student Resources pane, click this link, script.google.com/ to open the Apps Script page.
Click New project to create an Apps Script project.
Name your project:
Make the manifest file visible:
Change your Google Cloud Platform project:
Click Check my progress to verify the objective.
Follow the instructions below to update your project with the sample code.
appsscript.json
and replace its file contents with the following:Hello, You are late in delivery, again.
Please contact me ASAP before I cancel our subscription.
`, name: 'Customer C' } ]; // Send each sample email for (const email of sampleEmails) { GmailApp.sendEmail(userEmail, email.subject, email.body, { name: email.name, htmlBody: email.htmlBody }); } // Return a notification return buildNotificationResponse("Successfully generated sample emails"); } /** * Analyzes the sentiment of the first 10 threads in the inbox * and labels them accordingly. * * @returns {ActionResponse} - A notification confirming completion. */ function analyzeSentiment() { // Analyze and label emails analyzeAndLabelEmailSentiment(); // Return a notification return buildNotificationResponse("Successfully completed sentiment analysis"); } /** * Analyzes the sentiment of emails and applies appropriate labels. */ function analyzeAndLabelEmailSentiment() { // Define label names const labelNames = ["HAPPY TONE 😊", "NEUTRAL TONE 😐", "UPSET TONE 😡"]; // Get or create labels for each sentiment const positiveLabel = GmailApp.getUserLabelByName(labelNames[0]) || GmailApp.createLabel(labelNames[0]); const neutralLabel = GmailApp.getUserLabelByName(labelNames[1]) || GmailApp.createLabel(labelNames[1]); const negativeLabel = GmailApp.getUserLabelByName(labelNames[2]) || GmailApp.createLabel(labelNames[2]); // Get the first 10 threads in the inbox const threads = GmailApp.getInboxThreads(0, 10); // Iterate through each thread for (const thread of threads) { // Iterate through each message in the thread const messages = thread.getMessages(); for (const message of messages) { // Get the plain text body of the message const emailBody = message.getPlainBody(); // Analyze the sentiment of the email body const sentiment = processSentiment(emailBody); // Apply the appropriate label based on the sentiment if (sentiment === 'positive') { thread.addLabel(positiveLabel); } else if (sentiment === 'neutral') { thread.addLabel(neutralLabel); } else if (sentiment === 'negative') { thread.addLabel(negativeLabel); } } } } /** * Sends the email text to Vertex AI for sentiment analysis. * * @param {string} emailText - The text of the email to analyze. * @returns {string} - The sentiment of the email ('positive', 'negative', or 'neutral'). */ function processSentiment(emailText) { // Construct the API endpoint URL const apiUrl = `https://${VERTEX_AI_LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${VERTEX_AI_LOCATION}/publishers/google/models/${MODEL_ID}:generateContent`; // Prepare the request payload const payload = { contents: [ { role: "user", parts: [ { text: `Analyze the sentiment of the following message: ${emailText}` } ] } ], generationConfig: { temperature: 0.9, maxOutputTokens: 1024, responseMimeType: "application/json", // Expected response format for simpler parsing. responseSchema: { type: "object", properties: { response: { type: "string", enum: ["positive", "negative", "neutral"] } } } } }; // Prepare the request options const options = { method: 'POST', headers: { 'Authorization': `Bearer ${ScriptApp.getOAuthToken()}` }, contentType: 'application/json', muteHttpExceptions: true, // Set to true to inspect the error response payload: JSON.stringify(payload) }; // Make the API request const response = UrlFetchApp.fetch(apiUrl, options); // Parse the response. There are two levels of JSON responses to parse. const parsedResponse = JSON.parse(response.getContentText()); const sentimentResponse = JSON.parse(parsedResponse.candidates[0].content.parts[0].text).response; // Return the sentiment return sentimentResponse; }Click Save to save your project.
In this task you deploy the add-on, then verify the installation.
In the title bar, click Deploy > Test deployments.
Confirm Gmail is listed for Application(s) and click Install.
Click Done.
If you don't see your add-on in the list, refresh the browser window.
If it's still not there, go back to the Apps Script project, uninstall the add-on from the Test deployments window, and then reinstall it.
You're ready to run the add-on! In this task you open and authorize the add-on, then generate emails to verify that the analysis works.
Still in Gmail, in the right pane, click Sentiment Analysis ().
When the side panel opens, click Authorize access to grant the add-on permission to run.
A consent screen opens. Select your email (
Once you have granted consent, the Sentiment Analysis pane opens on the right.
The add-on now generates sample emails to test the analysis. A message will be displayed once the generation has completed, which only takes a few seconds.
Wait for the sample emails to show-up in your inbox. You may have to refresh your inbox to see the new emails.
Once the sample emails are in your inbox, in the Sentiment Analysis pane, click Analyze emails.
A message that the analysis has been completed shows on the bottom of the add-on screen.
The add-on analyzes your emails and applies the appropriate label ("HAPPY TONE 😊
", "UPSET TONE 😡
" or "NEUTRAL TONE 😐
") to messages in your inbox.
You may have to refresh your Gmail to see the applied labels.
Click Check my progress to verify the objective.
You've successfully completed the Gmail Sentiment Analysis with Gemini and Vertex AI lab.
In this lab, you learned how to:
You now have a functional Gmail add-on that can help you prioritize emails and improve your workflow. Feel free to experiment further with the add-on—perhaps by customizing the sentiment analysis or adding new features.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated March 25, 2025
Lab Last Tested February 25, 2025
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
현재 이 콘텐츠를 이용할 수 없습니다
이용할 수 있게 되면 이메일로 알려드리겠습니다.
감사합니다
이용할 수 있게 되면 이메일로 알려드리겠습니다.
한 번에 실습 1개만 가능
모든 기존 실습을 종료하고 이 실습을 시작할지 확인하세요.