Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Codevervollständigung und ‑generierung verwenden
In diesem Dokument wird beschrieben, wie Sie mit Gemini in Colab Enterprise, einem Produkt aus dem Gemini for Google Cloud-Portfolio, Code in einem Colab Enterprise-Notebook einfacher schreiben und generieren können.
Dieses Dokument richtet sich an Datenanalysten, Data Scientists und Datenentwickler, die mit Colab Enterprise arbeiten. Es wird davon ausgegangen, dass Sie wissen, wie Sie Code in einer Notebook-Umgebung schreiben.
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.
Bitten Sie Ihren Administrator, Ihnen die folgenden IAM-Rollen für das Projekt zuzuweisen, um die Berechtigungen zu erhalten, die Sie zur Verwendung von Gemini in Colab Enterprise benötigen:
Klicken Sie in der Symbolleiste auf die Schaltfläche pen_sparkHelp me code (Hilfe beim Programmieren) und wählen Sie die Funktionen aus, die Sie verwenden möchten.
Bei der Codevervollständigung wird Code vorgeschlagen, während Sie tippen.
Bei der Codegenerierung wird Code anhand einer Beschreibung dessen generiert, was Sie möchten.
Wenn die Schaltfläche pen_sparkHelp me code nicht aktiv ist oder Sie keine Liste mit Funktionen sehen, wenn Sie auf die Schaltfläche klicken, lesen Sie den Hilfeartikel Gemini in Colab Enterprise für ein Projekt einrichten.
Codevervollständigung verwenden
So verwenden Sie die Codevervollständigung in einem Colab Enterprise-Notebook:
Rufen Sie in der Google Cloud -Konsole die Colab Enterprise-Seite Meine Notebooks auf.
Wählen Sie im Menü Region die Region aus, in der sich Ihr Notebook befindet.
Klicken Sie auf das Notebook, das Sie öffnen möchten.
Klicken Sie in der Symbolleiste auf die Schaltfläche pen_sparkHilfe beim Programmieren und wählen Sie Codevervollständigung aus, falls diese Option nicht bereits ausgewählt ist.
Beginnen Sie in einer Codezelle Ihres Notebooks mit der Eingabe von Code.
Colab Enterprise schlägt eine mögliche Vervollständigung Ihres Codes in grau kursiv vor.
Wenn Sie beispielsweise import p eingeben, schlägt Colab Enterprise möglicherweise eine Codevervollständigung vor, die pandas as pd importiert, gefolgt von einer Zeile, in der eine CSV-Datei gelesen und der Inhalt in einem Pandas-DataFrame gespeichert wird.
Drücken Sie die Tabulatortaste, um den Vorschlag zur Vervollständigung von Code zu akzeptieren.
Codegenerierung verwenden
So generieren Sie Code mit Gemini für Google Cloud:
Rufen Sie in der Google Cloud -Konsole die Colab Enterprise-Seite Meine Notebooks auf.
Wählen Sie im Menü Region die Region aus, in der sich Ihr Notebook befindet.
Klicken Sie auf das Notebook, das Sie öffnen möchten.
Klicken Sie in der Symbolleiste auf die Schaltfläche pen_sparkHelp me code (Hilfe beim Programmieren) und wählen Sie Codegenerierung aus, falls diese Option nicht bereits ausgewählt ist.
Fügen Sie in Ihrem Notebook eine leere Codezelle hinzu oder klicken Sie auf eine Codezelle, die keinen Code enthält.
Klicken Sie auf sparkVerfügbare KI-Funktionen und dann auf Code generieren.
Geben Sie im Feld pen_sparkGenerieren eine Beschreibung des Codes ein, den Sie generieren möchten, und drücken Sie dann die Eingabetaste.
Klicken Sie auf Schließen, um den Bereich Generieren zu schließen.
Codevervollständigung und ‑generierung deaktivieren
So deaktivieren Sie die Codevervollständigung und ‑generierung:
Klicken Sie in der Colab Enterprise-Symbolleiste auf die Schaltfläche pen_sparkHilfe beim Programmieren.
Entfernen Sie das Häkchen bei den Funktionen, die Sie deaktivieren möchten.
Fehlerbehebung
In diesem Abschnitt erfahren Sie, wie Sie Probleme bei der Verwendung von Gemini in Colab Enterprise beheben.
Gemini-Funktionen funktionieren nicht
Wenn Sie in einem Colab Enterprise-Notebook tippen, werden keine Vorschläge zur Codevervollständigung angezeigt.
Oder die Schaltfläche pen_sparkHilfe beim Programmieren wird nicht über einer Codezelle angezeigt.
Möglicherweise haben Sie in Ihren Colab Enterprise-Einstellungen die Einstellung Kontextbezogene Codevervollständigungen anzeigen deaktiviert.
So beheben Sie das Problem:
Klicken Sie auf arrow_drop_downHeader-Sichtbarkeit umschalten.
Klicken Sie im Menü Tools auf Einstellungen.
Klicke auf Editor.
Wählen Sie Kontextbezogene Codevervollständigungen anzeigen aus.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (UTC)."],[[["\u003cp\u003eThis guide explains how to use Gemini in Colab Enterprise to assist with writing code within a notebook environment, including code completion and generation.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize Gemini's features, you must have the appropriate IAM roles assigned to your user account, specifically the Colab Enterprise User and Gemini for Google Cloud User roles.\u003c/p\u003e\n"],["\u003cp\u003eGemini offers code completion, which suggests code snippets as you type, and code generation, which creates code based on descriptions you provide, along with a feature to fix errors in your existing code.\u003c/p\u003e\n"],["\u003cp\u003eGemini features can be turned on or off via the "Help me code" button in the Colab Enterprise toolbar, which also allows you to select or deselect the features you wish to utilize.\u003c/p\u003e\n"],["\u003cp\u003eIf Gemini features are not working, ensure that the "Show context-powered code completions" setting is enabled in the Colab Enterprise editor settings.\u003c/p\u003e\n"]]],[],null,["# Use code completion and code generation\n=======================================\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 write and generate code 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\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\nEnable code completion and code generation\n------------------------------------------\n\nTo enable code completion and code generation, 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.\n In the toolbar, click the\n pen_spark **Help\n me code** button and select the features that you want to use.\n\n - **Code completion** suggests code while you type.\n - **Code generation** generates code from a description of what you want.\n\n\n If the\n pen_spark **Help\n me code** button isn't active, or if you don't see a list of\n features when you click the button, see\n [Set up Gemini\n in Colab Enterprise for a project](/gemini/docs/colab/set-up-gemini).\n\nUse code completion\n-------------------\n\nTo use code completion in a Colab Enterprise notebook, 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 the toolbar, click the pen_spark **Help\n me code** button and select **Code completion** if it isn't already selected.\n5. In a code cell of your notebook, start entering code.\n Colab Enterprise suggests a potential way to complete your\n code in gray italic text.\n\n For example, if you enter `import p`,\n Colab Enterprise might suggest a code completion that\n imports `pandas as pd` followed by a line that reads a CSV file\n and stores the contents in a pandas dataframe. \n\n\n6. To accept the suggested code completion, press \u003ckbd\u003eTab\u003c/kbd\u003e.\n\nUse code generation\n-------------------\n\nTo generate code using Gemini for Google Cloud:\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 the toolbar, click the\n pen_spark **Help\n me code** button and select **Code generation** if it\n isn't already selected.\n\n5. In your notebook, add a blank code cell, or click a code cell that\n doesn't have any code in it.\n\n6. Click\n spark **Available\n AI features** , and then click **Generate code**.\n\n7. In the\n pen_spark **Generate**\n field, type a description of the code that you want to generate,\n and then press \u003ckbd\u003eEnter\u003c/kbd\u003e.\n\n8. To close the **Generate** panel, click **Close**.\n\nTurn off code completion and code generation\n--------------------------------------------\n\nTo turn off code completion and code generation, do the\nfollowing:\n\n1. In the Colab Enterprise toolbar, click the\n pen_spark **Help\n me code** button.\n\n2. Clear the features that you want to turn off.\n\nTroubleshoot\n------------\n\nThis section shows you how to resolve issues with using\nGemini in Colab Enterprise.\n\n### Gemini features not working\n\n\nWhen you type in a Colab Enterprise notebook, code completion suggestions don't appear.\n\nOr, the pen_spark **Help me code** button\ndoesn't appear above a code cell.\n\nIn your Colab Enterprise settings, you might have turned off the\n**Show context-powered code completions** setting.\n\nTo resolve this issue, do the following:\n\n1. Click arrow_drop_down **Toggle\n header visibility**.\n2. On the **Tools** menu, click **Settings**.\n3. Click **Editor**.\n4. Select **Show context-powered code completions**.\n5. Click **Save**.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\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 - [Explain code cells](/colab/docs/explain-cells)\n - [Explain and fix errors](/colab/docs/explain-errors)\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)."]]