Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Usar o preenchimento e a geração de código
Este documento descreve como usar o Gemini no Colab Enterprise, um produto do portfólio do Gemini para Google Cloud, para ajudar você a escrever e gerar código em um bloco do Colab Enterprise.
Este documento é destinado a analistas, cientistas e desenvolvedores de dados que trabalham com o Colab Enterprise. É necessário saber como escrever código em um ambiente de 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.
Para receber as permissões necessárias para usar o Gemini no Colab Enterprise, peça ao administrador para conceder a você os seguintes papéis do IAM no projeto:
No menu Região, selecione a região que contém o notebook.
Clique no notebook que você quer abrir.
Na barra de ferramentas, clique no botão
pen_sparkQuero ajuda
para programar e selecione Conclusão de código se ainda
não estiver selecionado.
Em uma célula de código do notebook, comece a inserir o código.
O Colab Enterprise sugere uma maneira possível de concluir seu
código em texto cinza em itálico.
Por exemplo, se você inserir import p, o Colab Enterprise poderá sugerir uma conclusão de código que importa pandas as pd seguida por uma linha que lê um arquivo CSV e armazena o conteúdo em um dataframe do pandas.
Para aceitar o preenchimento de código sugerido, pressione Tab.
Usar a geração de código
Para gerar código usando o Gemini para Google Cloud:
No console do Google Cloud , acesse a página Meus notebooks do Colab Enterprise.
No menu Região, selecione a região que contém o notebook.
Clique no notebook que você quer abrir.
Na barra de ferramentas, clique no botão
pen_sparkQuero ajuda
para codificar e selecione Geração de código se ainda
não estiver selecionado.
No notebook, adicione uma célula de código em branco ou clique em uma célula que não tenha código.
Clique em
sparkRecursos de IA
disponíveis e em Gerar código.
No campo
pen_sparkGerar
, digite uma descrição do código que você quer gerar
e pressione Enter.
Para fechar o painel Gerar, clique em Fechar.
Desativar o preenchimento e a geração de código
Para desativar o preenchimento e a geração de código, faça o seguinte:
Na barra de ferramentas do Colab Enterprise, clique no botão
pen_sparkPreciso de ajuda com o código.
Desmarque os recursos que você quer desativar.
Resolver problemas
Nesta seção, mostramos como resolver problemas ao usar o Gemini no Colab Enterprise.
Os recursos do Gemini não estão funcionando
Ao digitar em um notebook do Colab Enterprise, as sugestões de preenchimento de código não aparecem.
Ou o botão pen_sparkQuero ajuda para programar não aparece acima de uma célula de código.
Nas configurações do Colab Enterprise, talvez você tenha desativado a opção Mostrar sugestões de preenchimento de código com base no contexto.
Para resolver esse problema, faça o seguinte:
Clique em
arrow_drop_downAlternar
visibilidade do cabeçalho.
No menu Ferramentas, clique em Configurações.
Clique em Editor.
Selecione Mostrar sugestões de preenchimento de código com base no contexto.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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)."]]