Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Menggunakan penyelesaian kode dan pembuatan kode
Dokumen ini menjelaskan cara menggunakan Gemini di Colab Enterprise, yang merupakan produk dalam portofolio Gemini untuk Google Cloud, untuk membantu Anda menulis dan membuat kode di notebook Colab Enterprise.
Dokumen ini ditujukan untuk analis data, data scientist, dan
developer data yang menggunakan Colab Enterprise. Hal ini mengasumsikan bahwa Anda memiliki
pengetahuan tentang cara menulis kode di lingkungan notebook.
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.
Untuk mendapatkan izin yang Anda perlukan untuk menggunakan Gemini di Colab Enterprise, minta administrator untuk memberi Anda peran IAM berikut di project:
Di menu Region, pilih region yang berisi notebook Anda.
Klik notebook yang ingin Anda buka.
Di toolbar, klik tombol
pen_sparkBantu
buat kode, lalu pilih Penyelesaian kode jika
belum dipilih.
Di sel kode notebook Anda, mulai masukkan kode.
Colab Enterprise menyarankan kemungkinan cara untuk melengkapi
kode Anda dalam teks miring berwarna abu-abu.
Misalnya, jika Anda memasukkan import p,
Colab Enterprise dapat menyarankan penyelesaian kode yang
mengimpor pandas as pd yang diikuti dengan baris yang membaca file CSV
dan menyimpan konten dalam dataframe pandas.
Untuk menerima penyelesaian kode yang disarankan, tekan Tab.
Menggunakan pembuatan kode
Untuk membuat kode menggunakan Gemini untuk Google Cloud:
Di konsol Google Cloud , buka halaman Notebook saya Colab Enterprise.
Di menu Region, pilih region yang berisi notebook Anda.
Klik notebook yang ingin Anda buka.
Di toolbar, klik tombol
pen_sparkBantu
saya membuat kode dan pilih Pembuatan kode jika belum
dipilih.
Di notebook, tambahkan sel kode kosong, atau klik sel kode yang
tidak memiliki kode apa pun.
Klik
sparkFitur AI yang tersedia, lalu klik Buat kode.
Di kolom
pen_sparkBuat, ketik deskripsi kode yang ingin Anda buat,
lalu tekan Enter.
Untuk menutup panel Buat, klik Tutup.
Menonaktifkan penyelesaian kode dan pembuatan kode
Untuk menonaktifkan penyelesaian kode dan pembuatan kode, lakukan hal berikut:
Di toolbar Colab Enterprise, klik tombol
pen_sparkBantu
saya membuat kode.
Hapus fitur yang ingin Anda nonaktifkan.
Memecahkan masalah
Bagian ini menjelaskan cara menyelesaikan masalah terkait penggunaan Gemini di Colab Enterprise.
Fitur Gemini tidak berfungsi
Saat Anda mengetik di notebook Colab Enterprise, saran pelengkapan kode tidak muncul.
Atau, tombol pen_sparkBantu saya membuat kode
tidak muncul di atas sel kode.
Di setelan Colab Enterprise, Anda mungkin telah menonaktifkan setelan
Tampilkan pelengkapan kode berdasarkan konteks.
Untuk menyelesaikan masalah ini, lakukan tindakan berikut:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]