Write code in a Colab Enterprise notebook with Gemini assistance

This document describes how you can use Gemini, an AI-powered collaborator in Google Cloud, to use inline code completion in a Colab Enterprise notebook.

Gemini doesn't use your prompts or its responses as data to train its models. For more information, see How Gemini for Google Cloud uses your data.

This document is intended for data analysts, data scientists, and data developers who work with Colab Enterprise. It assumes you have knowledge of how to write code in a notebook environment.

Before you begin

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

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

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI, Dataform, and Compute Engine APIs.

    Enable the APIs

Required roles

To ensure that your user account has the necessary permissions to use code completion in a Colab Enterprise notebook, ask your administrator to grant your user account the Colab Enterprise User (roles/aiplatform.colabEnterpriseUser) IAM role on the project. For more information about granting roles, see Manage access.

Your administrator might also be able to give your user account the required permissions through custom roles or other predefined roles.

Write code by using code completion

To use inline code completion in a Colab Enterprise notebook, do the following:

  1. In the Google Cloud console, go to the Colab Enterprise Notebooks page.

    Go to Notebooks

  2. In the Region menu, select the region that contains your notebook.

  3. On the My notebooks tab, click the notebook that you want to open. If you haven't created a notebook yet, create a notebook.

  4. In a code cell of your notebook, start entering code. Gemini suggests a potential way to complete your code in gray italic text.

    For example, if you enter import p, Gemini might suggest a code completion that imports pandas as pd followed by a line that reads a CSV file and stores the contents in a pandas dataframe.

  5. To accept the suggested code completion, press Tab.

What's next