Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Expliquer et corriger les erreurs avec l'aide de Gemini
Ce document explique comment utiliser Gemini dans Colab Enterprise, un produit de la gamme Gemini pour Google Cloud, pour vous aider à expliquer et à corriger les erreurs dans un notebook Colab Enterprise.
Ce document est destiné aux analystes de données, aux data scientists et aux développeurs de données qui travaillent avec Colab Enterprise. Il suppose que vous savez écrire du code dans un environnement notebook.
Présentation
Lorsque vous exécutez du code qui génère une erreur, Gemini dans Colab Enterprise peut suggérer une correction ou expliquer l'erreur pour vous aider à résoudre le problème.
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.
Enable the Vertex AI, Cloud AI Companion, Dataform, and Compute Engine APIs.
Pour obtenir les autorisations nécessaires pour utiliser Gemini dans Colab Enterprise, demandez à votre administrateur de vous accorder les rôles IAM suivants sur le projet :
Dans le menu Région, sélectionnez la région qui contient votre notebook.
Cliquez sur le notebook que vous souhaitez ouvrir.
Dans une cellule de code de votre notebook, saisissez du code contenant une erreur, puis exécutez la cellule. Par exemple, vous pouvez saisir print(a + random()) sans définir a.
Une fois votre cellule de code exécutée, Colab Enterprise affiche un message d'erreur en dessous. Si Gemini dans Colab Enterprise dispose d'une explication pour cette erreur, un bouton Expliquer l'erreur s'affiche.
Cliquez sur le bouton Expliquer l'erreur.
Colab Enterprise ouvre une boîte de dialogue de chat qui contient une explication de l'erreur. La boîte de dialogue peut également inclure des recommandations et des modifications suggérées pour résoudre le problème.
Après avoir évalué le contenu, vous pouvez effectuer l'une des actions suivantes :
Si Gemini fournit une modification de code suggérée dans sa réponse, vous pouvez cliquer sur :
Cliquez sur Accepter pour mettre à jour le code dans votre notebook.
Cliquez sur Accepter et exécuter pour mettre à jour et exécuter le code.
Annuler pour refuser la modification.
Utilisez la boîte de dialogue pour discuter de l'erreur avec Gemini.
Pour fermer la boîte de dialogue de chat, cliquez sur closeFermer.
Désactiver Gemini dans Colab Enterprise
Pour désactiver Gemini dans Colab Enterprise pour un projet Google Cloud , un administrateur doit désactiver l'API Gemini for Google Cloud. Consultez Désactiver des services.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[],[],null,["# Explain and fix errors with Gemini assistance\n=============================================\n\n|\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis document describes how you can use\nGemini in Colab Enterprise, which is a product\nin the [Gemini for Google Cloud](/gemini/docs/overview) portfolio,\nto help you explain and fix errors in a Colab Enterprise notebook.\n\nLearn [how and when Gemini\nfor Google Cloud uses your data](/gemini/docs/discover/data-governance).\n\nThis document is intended for data analysts, data scientists, and\ndata developers who work with Colab Enterprise. It assumes you have\nknowledge of how to write code in a notebook environment.\n\nOverview\n--------\n\nWhen you run code that generates an error, Gemini in\nColab Enterprise can suggest a fix or explain the error to help you\nresolve the issue.\n\nBefore you begin\n----------------\n\n| As an early-stage technology, Gemini for Google Cloud\n| products can generate output that seems plausible but is factually incorrect. We recommend that you\n| validate all output from Gemini for Google Cloud products before you use it.\n| For more information, see\n| [Gemini for Google Cloud and responsible AI](/gemini/docs/discover/responsible-ai).\n\n1. [Ensure that\n Gemini in Colab Enterprise is set up for your\n Google Cloud user account and project.](/gemini/docs/colab/set-up-gemini)\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n-\n\n\n Enable the Vertex AI, Cloud AI Companion, Dataform, and Compute Engine APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com, cloudaicompanion.googleapis.com, dataform.googleapis.com, compute.googleapis.com)\n\n-\n\n\n Enable the Vertex AI, Cloud AI Companion, Dataform, and Compute Engine APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com, cloudaicompanion.googleapis.com, dataform.googleapis.com, compute.googleapis.com)\n\n### Required roles\n\n\nTo get the permissions that\nyou need to use Gemini in Colab Enterprise,\n\nask your administrator to grant you the\nfollowing IAM roles on the project:\n\n- [Colab Enterprise User](/iam/docs/roles-permissions/aiplatform#aiplatform.colabEnterpriseUser) (`roles/aiplatform.colabEnterpriseUser`)\n- [Gemini for Google Cloud User](/iam/docs/roles-permissions/cloudaicompanion#cloudaicompanion.user) (`roles/cloudaicompanion.user`)\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nYou might also be able to get\nthe required permissions through [custom\nroles](/iam/docs/creating-custom-roles) or other [predefined\nroles](/iam/docs/roles-overview#predefined).\n| One or more of the required roles includes the `dataform.repositories.list` permission. Users who are granted the `dataform.repositories.list` permission or the [Code Creator\n| (`roles/dataform.codeCreator`)](/iam/docs/understanding-roles#dataform.codeCreator) role in a project can list the names of code assets in that project by using the Dataform API or the Dataform command-line interface (CLI). Non-administrators using BigQuery Studio can only see code assets that they created or that were shared with them.\n\nExplain and fix an error\n------------------------\n\nTo use Gemini for Google Cloud to explain and fix\nan error in your code, do the following:\n\n1. In the Google Cloud console, go to\n the Colab Enterprise **My notebooks** page.\n\n [Go to My notebooks](https://console.cloud.google.com/vertex-ai/colab/notebooks)\n2. In the **Region** menu, select the region that contains your notebook.\n\n3. Click the notebook that you want to open.\n\n4. In a code cell of your notebook, enter code that contains an error,\n and then run the cell. For example, you might enter\n `print(a + random())` without defining `a`.\n\n After your code cell runs, Colab Enterprise prints an\n error message below your code cell. If\n Gemini in Colab Enterprise has an explanation\n for this error, an **Explain error** button appears.\n5. Click the **Explain error** button.\n\n Colab Enterprise opens a chat dialog that contains an\n explanation of the error. The dialog might also include recommendations\n and suggested changes for how to resolve the problem.\n6. After evaluating the content, you can do any of the following:\n\n - If Gemini provides a suggested code edit in its response, you can click:\n - **Accept** to update the code in your notebook.\n - **Accept and run** to update and run the code.\n - **Cancel** to reject the edit.\n - Use the chat dialog to discuss the error with Gemini.\n7. To close the chat dialog, click\n close **Close**.\n\nTurn off Gemini in Colab Enterprise\n-----------------------------------\n\n\nTo turn off Gemini in Colab Enterprise for a\nGoogle Cloud project, an administrator must turn off the\nGemini for Google Cloud API. See\n[Disabling services](/service-usage/docs/enable-disable#disabling).\n\n\nTo turn off Gemini in Colab Enterprise for a specific user, an\nadministrator needs to revoke the\n[Gemini for\nGoogle Cloud User](/iam/docs/understanding-roles#cloudaicompanion.user) (`roles/cloudaicompanion.user`) role for that user. See\n[Revoke\na single IAM role](/iam/docs/granting-changing-revoking-access#revoke-single-role).\n\nWhat's next\n-----------\n\n- Read the [Gemini for Google Cloud\n overview](/gemini/docs/overview).\n\n- For more ways to write and edit code with Gemini\n assistance, see the following:\n\n - [Chat about your notebook with Gemini](/colab/docs/chat)\n - [Use code completion and code generation](/colab/docs/use-code-completion)\n - [Explain code cells](/colab/docs/explain-cells)\n - [Use the Data Science Agent](/colab/docs/use-data-science-agent)\n- Learn [how Gemini for Google Cloud uses\n your data](/gemini/docs/discover/data-governance)."]]