使用 Gemini 輔助功能說明程式碼單元格

本文說明如何使用 Gemini in Colab Enterprise (Gemini for Google Cloud 產品之一),輔助您說明 Colab Enterprise 筆記本中的程式碼儲存格。

瞭解 Gemini for Google Cloud 如何使用您的資料,以及使用時機

本文件適用於使用 Colab Enterprise 的資料分析師、數據資料學家和資料開發人員。本文假設您已瞭解如何在筆記本環境中編寫程式碼。

總覽

Gemini in Colab Enterprise 可協助您解釋 Colab Enterprise 筆記本中的程式碼儲存格。當你使用他人的 Notebook,並想快速瞭解程式碼的作用時,不妨試試這個方法。或者,您可能需要提醒自己,在長時間未使用筆記本後,如何使用筆記本的某些部分。

取得程式碼單元格的說明後,您可以瀏覽任何內含的程式碼片段,並查看來源。您也可以使用「說明程式碼」對話方塊討論程式碼,並提出後續問題。詳情請參閱「解釋程式碼儲存格」。

事前準備

  1. 確認您已為 Google Cloud 使用者帳戶和專案設定 Gemini in Colab Enterprise。
  2. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  3. Enable the Vertex AI, Cloud AI Companion, Dataform, and Compute Engine APIs.

    Enable the APIs

  4. Enable the Vertex AI, Cloud AI Companion, Dataform, and Compute Engine APIs.

    Enable the APIs

  5. 必要的角色

    如要取得在 Colab Enterprise 中使用 Gemini 所需的權限,請要求管理員為您授予專案的下列 IAM 角色:

    如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。

    您或許還可透過自訂角色或其他預先定義的角色取得必要權限。

    解釋程式碼儲存格

    如要使用 Gemini 為 Google Cloud說明程式碼儲存格,請執行下列操作:

    1. 在 Google Cloud 控制台中,前往 Colab Enterprise 的「My notebooks」頁面。

      前往「我的筆記本」

    2. 在「Region」選單中,選取含有筆記本的區域。

    3. 按一下要開啟的筆記本。

    4. 在筆記本中,按一下含有程式碼的程式碼儲存格。

    5. 依序點選 「可用的 AI 功能」和「說明程式碼」

      系統會顯示「解釋程式碼」對話方塊,其中包含程式碼的說明。

    6. 請詳閱說明、瀏覽程式碼片段範例,並查看來源。請透過這個即時通訊對話方塊討論程式碼,並提出後續問題。

    7. 如要關閉「Explain code」對話方塊,請按一下 「Close」

    停用 Gemini in Colab Enterprise

    如要為 Google Cloud 專案停用 Gemini in Colab Enterprise,管理員必須停用 Gemini for Google Cloud API。請參閱停用服務

    如要為特定使用者關閉 Gemini in Colab Enterprise,管理員需要撤銷該使用者的 Gemini for Google Cloud 使用者 (roles/cloudaicompanion.user) 角色。請參閱「撤銷單一 IAM 角色」。

    後續步驟