Explain and fix errors with Gemini assistance

This document describes how you can use Gemini in Colab Enterprise, which is a product in the Gemini for Google Cloud portfolio, to help you explain and fix errors in a Colab Enterprise notebook.

Learn how and when 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.

Overview

When you run code that generates an error, Gemini in Colab Enterprise can suggest a fix or explain the error to help you resolve the issue.

Before you begin

  1. Ensure that Gemini in Colab Enterprise is set up for your Google Cloud user account and project.
  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

Required roles

To get the permissions that you need to use Gemini in Colab Enterprise, ask your administrator to grant you the following IAM roles on the project:

For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required permissions through custom roles or other predefined roles.

Explain and fix an error

To use Gemini for Google Cloud to explain and fix an error in your code, do the following:

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

    Go to My notebooks

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

  3. Click the notebook that you want to open.

  4. In a code cell of your notebook, enter code that contains an error, and then run the cell. For example, you might enter print(a + random()) without defining a.

    After your code cell runs, Colab Enterprise prints an error message below your code cell. If Gemini in Colab Enterprise has an explanation for this error, an Explain error button appears.

  5. Click the Explain error button.

    Colab Enterprise opens a chat dialog that contains an explanation of the error. The dialog might also include recommendations and suggested changes for how to resolve the problem.

  6. After evaluating the content, you can do any of the following:

    • If Gemini provides a suggested code edit in its response, you can click:
      • Accept to update the code in your notebook.
      • Accept and run to update and run the code.
      • Cancel to reject the edit.
    • Use the chat dialog to discuss the error with Gemini.
  7. To close the chat dialog, click  Close.

Turn off Gemini in Colab Enterprise

To turn off Gemini in Colab Enterprise for a Google Cloud project, an administrator must turn off the Gemini for Google Cloud API. See Disabling services.

To turn off Gemini in Colab Enterprise for a specific user, an administrator needs to revoke the Gemini for Google Cloud User (roles/cloudaicompanion.user) role for that user. See Revoke a single IAM role.

What's next