Gemini API を使用して Google Workspace のタスクを自動化する

1. 始める前に

この Codelab では、Gemini API の関数呼び出しとマルチモーダリティ機能を使用して Google Workspace のタスクを自動化する方法を学びます。

前提条件

  • Apps Script、JavaScript、または類似のプログラミング言語の基本的な知識

学習内容

  • Gemini API の関数呼び出しとマルチモーダル機能を活用する方法。
  • 複数の Gemini API 呼び出しをチェーン接続する方法。
  • Gemini API を使用して Google Workspace のタスクを自動化する方法。

必要なもの

  • ウェブブラウザ。
  • Gmail アカウント。または、Gemini API の特定の設定を実装した Google Workspace アカウント。
  • Gemini API のサポートされているリージョンからの接続。
  • 省略可: 直接 API リクエストをテストするための curl プログラムを含むコマンドライン インターフェース。

この Codelab の完全なコードは、GitHub の Gemini API Cookbook で入手できます。完成したコードが必要な場合は、こちらをご覧ください。

2. Gemini API を設定する

Gemini について

Gemini モデルは、Google の最大かつ最高性能の AI モデル ファミリーです。アプリでこれらのモデルを活用するには、Gemini API を使用します。また、Google AI Studio で Gemini API を試すこともできます。これは、コードを記述することなくプロンプトを試したり、モデル設定を調整したり、カスタムモデルをチューニングしたりできる API のウェブ インターフェースです。

キーを取得する

省略可: キーをテストする

curl を使用してコマンドラインにアクセスできる場合は、次のブロックの 1 行目にキーを追加し、ターミナルで実行して API キーをテストします。

export GOOGLE_API_KEY=Paste_your_API_key_here

curl "https://generativelanguage.googleapis.com/v1beta/models?key=${GOOGLE_API_KEY}"

models/gemini-1.0-pro などの JSON 形式のモデルのリストが表示されます。これは、正常に動作したことを意味します。

3. 省略可: Gemini API にリクエストを送信する

この省略可能な手順では、Gemini API にリクエストを送信して、コンテンツ生成の仕組みを理解してから Apps Script アプリに追加します。

モデルについて

Gemini API には、さまざまな機能と制限事項を持つ複数のモデルが用意されています。各モデルとその機能は、Gemini モデルのページに記載されています。

最初のリクエストを行う

Gemini API にテキスト プロンプトを完成させるには、JSON リクエストを作成して REST API エンドポイントに送信します。

方法は次のとおりです。

  1. 新しいファイルに、次の JSON リクエストを入力します。
{
  contents: [
   {
     parts: [
       { text: 'The most important aspects of a persuasive presentation are:' }
     ]
   }
 ]
}

JSON リクエストには、次のプロンプトが含まれています。The most important aspects of a persuasive presentation are:。モデルはこの指示を完了し、結果を直接返します。

JSON リクエストには、入力する 3 つの最上位フィールド(contentsgenerationConfigsafetySettings)があります。contents のみが必須です。他のものは、出力を制御するメカニズムを提供します。

  1. この JSON を presentation.txt ファイルに保存し、次のように curl に直接渡します。
curl -H 'Content-Type: application/json' -X POST -d @presentation.txt \
  'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro-latest:generateContent?key='${GOOGLE_API_KEY}

この例では、URL で次の値を設定します。

  • v1beta は API バージョンを指定します。
  • gemini-1.0-pro-latest は、モデルとして Gemini 1.0 Pro を指定し、最新のスナップショットを使用します。
  • generateContent は、呼び出す API メソッドを指定します。

次のような結果が表示されます。

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "* **Credibility:** The audience must trust that you are an expert on the subject matter and that you have their best interests at heart.\n* **Clearness:** Your message must be easy to understand and follow. Avoid using jargon or technical terms that your audience may not be familiar with.\n* **Concreteness:** Use specific examples and data to support your arguments. Avoid making vague or general claims.\n* **Emotional appeal:** In addition to appealing to the audience's logical side, you should also try to connect with them on an emotional level. Use storytelling, humor, and personal anecdotes to make your points more memorable and engaging.\n* **Strong closing:** End your presentation with a strong call to action. Tell the audience what you want them to do and why it is important for them to do it."
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [...]
    }
  ],
  "promptFeedback": {
    "safetyRatings": [...]
  }
}

読みやすくするために、ターミナル出力を通常の形式で示します。

  • 信頼性: 視聴者は、あなたがそのテーマの専門家であり、視聴者のことを第一に考えていると信頼する必要があります。
  • 明確さ: メッセージは理解しやすく、従いやすいものでなければなりません。視聴者が理解できない可能性のある専門用語や技術用語は避けてください。
  • 具体性: 具体的な例やデータを使用して、自分の主張を裏付けます。曖昧または一般的な主張は避けてください。
  • 感情に訴える: 視聴者の論理的な側面に訴えるだけでなく、感情的なレベルでもつながるようにします。ストーリーテリング、ユーモア、個人的な逸話を使用して、ポイントをより記憶に残る魅力的なものにします。
  • 強力な締めくくり: 行動を促す強力なフレーズでプレゼンテーションを締めくくります。視聴者に何をしてもらいたいか、そしてそれが視聴者にとってなぜ重要なのかを伝えます。

generationConfigsafetySettings などのその他の設定について詳しくは、プロンプト ガイドと安全性ガイドをご覧ください。

4. Apps Script から Gemini API を呼び出す

  1. script.new にアクセスすると、code.gs Apps Script ファイルが自動的に作成されます。
  2. code.gs ファイルにカーソルを合わせ、8bfe57773be886ab.png > [名前の変更] をクリックします。
  3. ファイル名を utils.gs に変更します。
  4. ファイルから myFunction 関数を削除して、ファイルを空にします。

API キーをプロジェクトに追加する

  1. ナビゲーション メニューで [プロジェクト設定] を選択します。
  2. [スクリプト プロパティ] で [スクリプト プロパティを追加] をクリックします。
  3. [プロパティ] に「GOOGLE_API_KEY」と入力します。
  4. [] に、Google AI Studio の API キーを入力します。

fcfe205a93879c49.png

  1. [スクリプト プロパティを保存] をクリックします。
  2. エディタに戻ります。

Gemini API コードを追加する

utils.gs ファイルで、次の操作を行います。

API キーとエンドポイントを設定します。

const properties = PropertiesService.getScriptProperties().getProperties();
const geminiApiKey = properties['GOOGLE_API_KEY'];
const geminiEndpoint = `https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro-latest:generateContent?key=${geminiApiKey}`;
  1. 特定のプロンプトで Gemini API を呼び出す次の関数を追加します。
function callGemini(prompt, temperature=0) {
  const payload = {
    "contents": [
      {
        "parts": [
          {
            "text": prompt
          },
        ]
      }
    ], 
    "generationConfig":  {
      "temperature": temperature,
    },
  };

  const options = { 
    'method' : 'post',
    'contentType': 'application/json',
    'payload': JSON.stringify(payload)
  };

  const response = UrlFetchApp.fetch(geminiEndpoint, options);
  const data = JSON.parse(response);
  const content = data["candidates"][0]["content"]["parts"][0]["text"];
  return content;
}
  1. プロンプトを設定する次の関数を追加します。
function testGemini() {
  const prompt = "The best thing since sliced bread is";
  const output = callGemini(prompt);
  console.log(prompt, output);
}

テスト

  1. 76113423d1f91775.png [保存] をクリックします。
  2. 関数のプルダウン リストで testGemini を選択し、5b9034ff679c8761.png をクリックします。
  3. 必要な権限を承認します。コードが実行され、実行ログに結果を含むコンソール出力が表示されます。

実行ログ

うまくいきました。

5. 画像を使用して Gemini API を呼び出す

Gemini ファミリーのモデルの最も強力な機能の 1 つは、マルチモーダル入力のサポートです。つまり、テキスト以外の情報も提供できます。このセクションでは、画像を使用して Gemini API を呼び出す関数を追加します。

  • utils.gs ファイルの先頭にある既存の const geminiEndpoint 宣言の後に、次の行を追加します。
const geminiProVisionEndpoint = `https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro-vision-latest:generateContent?key=${geminiApiKey}`;

Gemini Vision コードを追加する

  1. この新しく追加されたエンドポイントを呼び出す関数を utils.gs ファイルに追加します。
function callGeminiProVision(prompt, image, temperature=0) {
  const imageData = Utilities.base64Encode(image.getAs('image/png').getBytes());

  const payload = {
    "contents": [
      {
        "parts": [
          {
            "text": prompt
          },
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": imageData
            }
          }          
        ]
      }
    ], 
    "generationConfig":  {
      "temperature": temperature,
    },
  };

  const options = { 
    'method' : 'post',
    'contentType': 'application/json',
    'payload': JSON.stringify(payload)
  };

  const response = UrlFetchApp.fetch(geminiProVisionEndpoint, options);
  const data = JSON.parse(response);
  const content = data["candidates"][0]["content"]["parts"][0]["text"];
  return content;
}
  1. 次のテスト関数を追加します。
function testGeminiVision() {
  const prompt = "Provide a fun fact about this object.";
  const image = UrlFetchApp.fetch('https://storage.googleapis.com/generativeai-downloads/images/instrument.jpg').getBlob();
  const output = callGeminiProVision(prompt, image);
  console.log(prompt, output);
}

この関数は、インターネットからテスト画像を読み込み、定義した関数に渡します。後で、スプレッドシートのグラフを使用するように接続するため、これはテストにすぎません。

テスト

  • testGeminiVision 関数を保存して実行し、出力を確認します。

849c6728bfb5ec52.png

6. ツールを使用して Gemini API を呼び出す

テキストや画像に加えて、プロンプトでツールへのアクセス権を付与することもできます。

ツール処理コードを追加する

  • ツール仕様を受け取る関数を utils.gs ファイルに追加します。
function callGeminiWithTools(prompt, tools, temperature=0) {
  const payload = {
    "contents": [
      {
        "parts": [
          {
            "text": prompt
          },
        ]
      }
    ], 
    "tools" : tools,
    "generationConfig":  {
      "temperature": temperature,
    },    
  };

  const options = { 
    'method' : 'post',
    'contentType': 'application/json',
    'payload': JSON.stringify(payload)
  };

  const response = UrlFetchApp.fetch(geminiEndpoint, options);
  const data = JSON.parse(response);
  const content = data["candidates"][0]["content"]["parts"][0]["functionCall"];
  return content;
}

このスキーマと使用可能なフィールドの詳細については、FunctionDeclaration API リファレンスをご覧ください。

テスト

  1. モデルが現在の日付と時刻を検索するために使用できるツールを定義します。
function testGeminiTools() {
  const prompt = "Tell me how many days there are left in this month.";
  const tools = {
    "function_declarations": [
      {
        "name": "datetime",
        "description": "Returns the current date and time as a formatted string.",
        "parameters": {
          "type": "string"
        }
      }
    ]
  };
  const output = callGeminiWithTools(prompt, tools);
  console.log(prompt, output);
}

ここで使用する形式は FunctionDeclaration スキーマです。実際には、日時関数を呼び出しません。モデルが関数呼び出しをリクエストしたことを示すインジケーターのみが返されます。関数呼び出しは後のステップで処理します。

  1. testGeminiTools 関数を保存して実行し、出力を確認します。

実行ログ

7. Google Workspace とのデモ統合の概要

関数呼び出しの仕組みを理解したので、Gemini モデルの機能を他のサービスに簡単に拡張できます。以降のセクションでは、Google ドライブ、Google スライド、Google スプレッドシートなどの Google Workspace プロダクトに対する統合を構築します。簡略化した図は次のとおりです。

3 個のツール

大まかに言うと、ユーザー クエリが届くと、Gemini API の関数呼び出しを使用して、使用するツールを決定します。次の操作を行う 3 つのツールを構築します。

  • 会議を設定します。図の setupMeeting() 関数は、Gemini 1.0 Pro API を呼び出して Google ドライブのブログを要約し、その要約を Google カレンダーで新しく作成された会議に追加します。
  • グラフの分析情報に基づいてメールの下書きを作成する。図の draftEmail() 関数は、Gemini 1.0 Pro Vision を呼び出して Google スプレッドシートのグラフを分析し、その分析に基づいて Gmail でメールを作成します。
  • スケルトン デッキを作成します。図の createDeck() 関数は、Gemini 1.0 Pro を呼び出して、Google スライドのデッキの箇条書きをブレインストーミングします。

各ツールについて、次の 3 つの操作を行う必要があります。

  1. Gemini API の関数呼び出しレスポンスで、その特定のツールを if...else ブロックで呼び出すよう求められているかどうかを判断します。
  2. ツール機能を実装する実際の関数を追加します。
  3. Gemini API でツールを宣言して、Gemini モデルがツールの存在を認識し、正しい関数呼び出しレスポンスを返せるようにします。

8. Apps Script で会議を設定する

まず、Google カレンダーで会議の設定を自動化しますが、Google ドライブ内のファイルの概要である説明も追加します。

方法は次のとおりです。

  1. Gemini 1.5 Pro のリリースブログのテキスト コピーである、このテキスト ファイルをダウンロードします。
  2. Google ドライブのルートフォルダにファイルをアップロードします。
  3. エディタで main.gs ファイルを作成し、次のコードを追加します。
function main() {
  const userQuery = "Set up a meeting at 10AM tomorrow with Helen to discuss the news in the Gemini-blog.txt file.";

  var tool_use = callGeminiWithTools(userQuery, WORKSPACE_TOOLS);
  Logger.log(tool_use);
  
  if(tool_use['name'] == "setupMeeting") {
    setupMeeting(tool_use['args']['time'], tool_use['args']['recipient'], tool_use['args']['filename']);
    Logger.log("Your meeting has been set up.");
 }
  else
    Logger.log("no proper tool found");
}

ここでは、Gemini API の関数呼び出し機能を呼び出します。次に、ツール関数を定義する必要があります。

  1. エディタの左側にある [サービス] の横にある [+ サービスを追加 > Google Calendar API > 追加] をクリックします。これにより、高度な Google カレンダー サービスが有効になります。このサービスは、後で一部の高度な API を使用するために必要になります。

サービスを追加する

  1. utils.gs ファイルに、次のコードを追加します。
function attachFileToMeeting(event, file, fileName) {
  // Get the iCal ID for the event.
  const iCalEventId = event.getId();

  // Log the ID and title for debugging.
  console.log(`iCal event ID: ${iCalEventId}`);
  console.log(`event Title: ${event.getTitle()}`);

  // Set up the options for listing the event with the advanced Google Calendar service.
  const options = {
      iCalUID: iCalEventId,
    };

  // Use the primary calendar as the calendar ID to list events.
  const calendarId = 'primary';

  // Use the advanced Google Calendar service to list the event.
  const calEvents = Calendar.Events.list(calendarId, options);

  // Get the Calendar ID used by the advanced Google Calendar service.
  const eventId = calEvents.items[0].id;

  // Get the file URL for the attachment.
  const fileUrl = file.getUrl();

    // Set up the patch options to add the file.
    var patch = {
      attachments: [{
        'fileUrl': fileUrl,
        'title': fileName
      }]
    };

    // Patch the event to add the file as an attachment.
    Calendar.Events.patch(patch, 'primary', eventId, {"supportsAttachments": true});  
}

function setupMeeting(time, recipient, filename) {
  const files = DriveApp.getFilesByName(filename);
  const file = files.next();
  const blogContent = file.getAs("text/*").getDataAsString();
  
  var geminiOutput = callGemini("Give me a really short title of this blog and a summary with less than three sentences. Please return the result as a JSON with two fields: title and summary. \n" +  blogContent);
  // The Gemini model likes to enclose the JSON with ```json and ```
  geminiOutput = JSON.parse(geminiOutput.replace(/```(?:json|)/g, ""));  
  const title = geminiOutput['title'];
  const fileSummary = geminiOutput['summary'];

  const event = CalendarApp.getDefaultCalendar().createEventFromDescription(`meet ${recipient} at ${time} to discuss "${title}"`); 
  event.setDescription(fileSummary);
  attachFileToMeeting(event, file, filename);
}

このコードは次の処理を行います。

  • setupMeeting() 関数は Google ドライブを検索して Gemini-blog.txt ファイルを見つけます。このファイル名は、ステップ 3 の Gemini API の関数呼び出しによって自動的に返されます。
  • setupMeeting() 関数は Gemini API を呼び出してファイルの内容を要約し、自由形式の説明を使用して CalendarApp で会議を設定し、要約を会議に追加します。
  • setupMeeting() 関数は attachFileToMeeting() 関数を呼び出し、高度な Google カレンダー サービスを使用してブログファイルを会議に添付します。
  1. utils.gs ファイルの先頭に、次のコードを追加します。
const WORKSPACE_TOOLS = {
 "function_declarations": [
   {
     "name": "setupMeeting",
     "description": "Sets up a meeting in Google Calendar.",
     "parameters": {
       "type": "object",
       "properties": {
         "time": {
           "type": "string",
           "description": "The time of the meeting."
         },
         "recipient": {
           "type": "string",
           "description": "The name of the recipient."
         },   
         "filename": {
           "type": "string",
           "description": "The name of the file."
         },                     
       },
       "required": [
         "time",
         "recipient",
         "filename"
       ]
     }
   },
   // You add tools here.        
 ]
};
  1. エディタで main.gs ファイルに戻り、5b9034ff679c8761.png をクリックします。
  2. Google Workspace からスクリプトの実行権限を求められたら、[OK] をクリックします。

数秒後に、会議が設定されたことを知らせるメッセージが実行ログに表示されます。

  1. Google カレンダーで、概要と添付ファイルを含む会議を探します。

会議への招待状

9. Apps Script でメールの下書きを作成する

次に、Gmail でのメールの下書きの作成を自動化します。シナリオは次のとおりです。Google スプレッドシートでデータ分析を行うとします。すべての数値を適切な場所に配置して、グラフを作成します。Gemini Pro Vision API を使用して、グラフに基づいてメールの下書きを作成します。

方法は次のとおりです。

  1. このシートを開き、[ファイル -> コピーを作成] をクリックします。
  2. [ドキュメントをコピー] ダイアログの [名前] テキスト ボックスで、デフォルトの名前 Copy of CollegeExpensesCollegeExpenses に置き換えます。
  3. main.gs ファイルで、前のユーザー クエリを新しいクエリに置き換え、次のコードを if...else ステートメントに追加します。
function main() {
  // const userQuery = "Set up a meeting at 5PM with Helen to discuss the news in the Gemini-1.5-blog.txt file.";  
  const userQuery = "Draft an email for Mary with insights from the chart in the CollegeExpenses sheet.";

  if(...) {...}
  // Add this code
  else if(tool_use['name'] == "draftEmail") {
    draftEmail(tool_use['args']['sheet_name'], tool_use['args']['recipient']);
    Logger.log("Check your Gmail to review the draft");
  }
  else {...}

}
  1. utils.gs ファイルに、次のコードを追加します。
function draftEmail(sheet_name, recipient) {
  
  const prompt = `Compose the email body for ${recipient} with your insights for this chart. Use information in this chart only and do not do historical comparisons. Be concise.`;

  var files = DriveApp.getFilesByName(sheet_name);
  var sheet = SpreadsheetApp.openById(files.next().getId()).getSheetByName("Sheet1");
  var expenseChart = sheet.getCharts()[0];

  var chartFile = DriveApp.createFile(expenseChart.getBlob().setName("ExpenseChart.png"));
  var emailBody = callGeminiProVision(prompt, expenseChart);
  GmailApp.createDraft(recipient+"@demo-email-provider.com", "College expenses", emailBody, {
      attachments: [chartFile.getAs(MimeType.PNG)],
      name: 'myname'
  });
}

この関数は、シートから大学費用のグラフを取得し、Gemini Pro Vision に送信してメールの下書きを作成します。Gemini Pro Vision がグラフから情報を抽出し、メールの本文を下書きします。

  1. utils.gs ファイルで、You add tools here コメントの後に WORKSPACE_TOOLS オブジェクトに次のコードを追加します。
  WORKSPACE_TOOLS = {
    "function_declarations": [
      // You add tools here.

      {
        "name": "draftEmail",
        "description": "Write an email by analyzing data or charts in a Google Sheets file.",
        "parameters": {
          "type": "object",
          "properties": {
            "sheet_name": {
              "type": "string",
              "description": "The name of the sheet to analyze."
            },
            "recipient": {
              "type": "string",
              "description": "The name of the recipient."
            },            
          },
          "required": [
            "sheet_name",
            "recipient"
          ]
        }
      },   


    ]
  };
  1. エディタで main.gs ファイルに戻り、5b9034ff679c8761.png をクリックします。
  2. 10 ~ 20 秒後に Gmail を開きます。次のようなメールの下書きが表示されます。

メールの草稿は送信前に修正できます。このメールは、短いプロンプトとグラフを指定すると、Gemini Pro Vision によって完全に作成されます。

10. Apps Script を使用してスケルトン デッキを作成する

次に、Apps Script を使用して Google スライドでスケルトン デッキの作成を自動化します。

方法は次のとおりです。

  1. main.gs ファイルで、前のユーザー クエリを新しいクエリに置き換え、次のコードを if...else ステートメントに追加します。
function main() {
  // const userQuery = "Draft an email for Mary with insights from the chart in the CollegeExpenses sheet.";
  const userQuery = "Help me put together a deck about water conservation.";

  if(...) {...}
  // Add this code
  else if(tool_use['name'] == 'createDeck') {
    deckURL = createDeck(tool_use['args']['topic']);
    Logger.log("Deck URL: " + deckURL);
  }
  else {...}

}
  1. utils.gs ファイルに、次のコードを追加します。
function createDeck(topic) {
  const prompt = `I'm preparing a ${NUM_SLIDES}-slide deck to discuss ${topic}. Please help me brainstorm and generate main bullet points for each slide. Keep the title of each slide short. Please produce the result as a valid JSON so that I can pass it to other APIs.`;
  
  var geminiOutput = callGemini(prompt, 0.4);
  // The Gemini model likes to enclose the JSON with ```json and ```
  geminiOutput = geminiOutput.replace(/```(?:json|)/g, "");
  const bulletPoints = JSON.parse(geminiOutput);
    
  // Create a Google Slides presentation.
  const presentation = SlidesApp.create("My New Presentation");

  // Set up the opening slide.
  var slide = presentation.getSlides()[0]; 
  var shapes = slide.getShapes();
  shapes[0].getText().setText(topic);

  var body;
  for (var i = 0; i < NUM_SLIDES; i++) {
      slide = presentation.appendSlide(SlidesApp.PredefinedLayout.TITLE_AND_BODY);
      shapes = slide.getShapes();
      // Set title.
      shapes[0].getText().setText(bulletPoints['slides'][i]['title']);
  
      // Set body.
      body = "";
      for (var j = 0; j < bulletPoints['slides'][i]['bullets'].length; j++) {
        body += '* ' + bulletPoints['slides'][i]['bullets'][j] + '\n';
      }
      shapes[1].getText().setText(body);
  } 

  return presentation.getUrl();
}

この関数は Gemini API を呼び出して、特定のトピックについてブレインストーミングを行い、箇条書きを次の形式で返します。

の JSON を取得し、Apps Script を使用してスケルトン デッキに入力します。

  1. utils.gs ファイルで、You add tools here コメントの後に WORKSPACE_TOOLS オブジェクトに次のコードを追加します。
  WORKSPACE_TOOLS = {
    "function_declarations": [
      // You add tools here.

      {
        "name": "createDeck",
        "description": "Build a simple presentation deck with Google Slides and return the URL.",
        "parameters": {
          "type": "object",
          "properties": {
            "topic": {
              "type": "string",
              "description": "The topic that the presentation is about."
            },
          },
          "required": [
            "topic"
          ]
        }
      },


    ]
  };
  1. utils.gs ファイルの先頭で、次の定数を定義します。
const NUM_SLIDES = 3;

これは、Gemini モデルがオープニング スライドに加えて作成するスライドの数です。

  1. エディタで main.gs ファイルに戻り、5b9034ff679c8761.png をクリックします。数秒後に、実行ログにプレゼンテーションの URL が表示されます。
  2. ブラウザを使用して URL を開きます。箇条書きで埋められたスケルトン デッキが表示されます。

下書き資料

11. アイデアを探す

上記の 3 つの統合以外にも、次のアイデアを検討できます。

  • Google Chat で chatbot を構築する。大規模言語モデル(LLM)の最も一般的なユースケースの 1 つは、chatbot の構築です。Gemini API を使用すると、Google Chat 用の chatbot を簡単に構築できます。詳細については、Google Chat API と Codelab の Gemini を使用して Google Chat 用アプリを構築するをご覧ください。
  • Google ドライブまたは Keep の独自のデータを使用した検索拡張生成(RAG)。この Codelab では、要約に 1 つのテキスト ファイルのみを使用します。ただし、個人の Google ドライブや Keep のコンテンツ(メモ、PDF、画像など)を Gemini API、ベクトル データベース、必要に応じてオーケストレーション ツール(LangChain など)とともに使用して、RAG を実行し、データに基づいてモデルのレスポンスをパーソナライズすることもできます。
  • Gemini API のマルチターン関数呼び出し機能を使用する。Gemini API の関数呼び出しは 1 回のターンに限定されず、より複雑なタスクに対して複数ターンの関数呼び出しを行うことができます。
  • Google Workspace からさらに範囲を広げる必要があります。Gemini API を Google Workspace と統合する方法を理解したところで、Google Workspace を超えて、他の API を活用してみましょう。

12. 完了

Gemini API のマルチモーダル機能と関数呼び出しについて学習しました。Apps Script を使用して Google Workspace のタスクを自動化しました。

その他の情報