Getting Started with Gemini Code Assist

Google Cloud’s always-on Coding Assistant

Cloud Jake
Google Cloud - Community
7 min readMay 20, 2024

--

Gemini Code Assist (formerly Duet AI for Developers) is Google’s AI-powered assistant to help developers build applications with higher velocity and quality while reducing repetitive tasks and toil.

Gemini 4-point start logo with wording “Gemini Code Assist”

In this article, we’ll explore Gemini for Google Cloud — a new generation of AI assistants for developers, Google Cloud services, and applications — and where google has integrated Gemini into their Google Cloud offerings.

Then, we’ll take a deeper dive with Gemini Code Assist and outline how to get started using Gemini to accelerate your Software Development and Application Lifecycles.

Gemini for Google Cloud

Gemini for Google Cloud is a new generation of AI assistants for developers, Google Cloud services, and applications. These assist users in working and coding more effectively, gaining deeper data insights, navigating security challenges, and more. Using Google’s Gemini family of models, Gemini for Google Cloud lets teams accomplish more in the cloud.

Integrating Gemini into Google Cloud Offerings

Let’s take a closer look at how Google is integrating Gemini into their Cloud offerings:

Table of 6 cells showing where Google has integrated the Gemini AI model into Google Cloud — Software Development, Application Lifecycle, Security, Data Analytics, Business Intelligence, Databases.
  • Software Development & Application Lifecycle: Gemini accelerates development with code generation and personalized guidance, streamlining the entire application lifecycle.
  • Security: Gemini empowers secure coding practices and helps identify potential vulnerabilities for more robust cloud deployments.
  • Data Analytics & Business Intelligence: Gemini simplifies data exploration and analysis by suggesting queries and generating data summaries, leading to quicker insights.
  • Databases: Gemini enhances database management within Cloud SQL by offering intelligent code completion and context-aware suggestions for database tasks.

Gemini for Google Cloud offers enterprise-ready, AI capabilities that deliver robust security, compliance, and privacy controls, all with industry-leading availability.

Gemini Code Assist

Gemini Code Assist is your always-on AI assistant for Google Cloud development. It understands your code, suggests completions and fixes, generates code from your descriptions, and even helps with reviews and debugging — all within your familiar IDE like VS Code and JetBrains.

Activate Gemini Code Assist in a Google Cloud project

Gemini Code Assist is available to try without a subscription at no cost until July 11, 2024, limited to one user per billing account. After this date, follow the instructions to purchase a subscription to Gemini Code Assist.

To activate Gemini Code Assist in a Google Cloud project, a privileged user will need to complete the following steps:

  • enable the Cloud AI Companion API
  • grant the Cloud AI Companion User role
  • grant the Service Usage Viewer IAM role

Let’s walk through these steps by creating a new project and completing the required steps using the Google Cloud SDK from the Cloud Shell.

1 — From the Google Cloud Console, open the Cloud Shell by clicking the Cloud Shell icon in the top right of the screen.

Top menu of the Google Cloud console highlighting the icon for the Cloud Shell with a red box and red arrow

2 — Establish some variables to simplify the commands

Set the current user:

PRINCIPAL=$(gcloud config get account)

Set the name of the project to create (replace “<<project name>>” with a globally unique name that conforms to project naming conventions)

PROJECT_ID=<<project nanme>>

3 — Create the project

gcloud projects create $PROJECT_ID

You will receive a confirmation that the project has been created

terminal screen showing the output of the command “gcloud projects create $PROJECT_ID” for the PROJECT_ID=jake-gemini-code-assist

4 — Enable the Cloud AI Companion API

gcloud services enable cloudaicompanion.googleapis.com --project $PROJECT_ID

5 — Grant the two IAM roles that are required to use Gemini:

5a — Grant the Cloud AI Companion User role

gcloud projects add-iam-policy-binding  $PROJECT_ID \
--member=user:${PRINCIPAL} --role=roles/cloudaicompanion.user

5b — grant the Service Usage Viewer IAM role

gcloud projects add-iam-policy-binding  $PROJECT_ID \
--member=user:${PRINCIPAL} --role=roles/serviceusage.serviceUsageViewer

To confirm that you now have access to Gemini in Google Cloud, open a new instance of the Google Cloud Console and select the project that we just created from the dropdown in the top left.
https://console.cloud.google.com/

Top navigation menu of Google Cloud console with Project ID outlined in red and a red arrow.

Locate the name of the project that we just created (you may need to click the “All” tab).

Top navigation menu of Google Cloud console with the 4-sided star Gemini logo outlined in red and a red arrow.

Finally, to confirm that you are able to access Gemini in Google Cloud, click the 4-sided star Gemini logo in the top tight of the screen (next to the Cloud Shell icon). A new pane will appear on the right side of the screen with a dialog box to enter a prompt for Gemini.

Enable Gemini Code Assist in the Cloud Shell Editor

Now that we’ve enabled Gemini for Google Cloud, the easiest way to try it out is with the Cloud Shell Editor. To access the Cloud Shell Editor from the Google Cloud Console, again click the Cloud Shell icon in the top right of the screen, then select Open Editor

Top menu of the Google Cloud console highlighting the icon for the Cloud Shell with a red box
Top menu of the Google Cloud console highlighting the icon for the Cloud Shell Editor with a red box and red arrow

Once you’ve clicked Open Editor, the Cloud Shell Terminal will be replaced with the Cloud Shell Editor. The first thing we’ll need to do is activate Gemini Code Assist by clicking the “disabled” Gemini icon in the Gemini Code Assist menu at the bottom right of the window

Google Cloud Shell Editor full page with a red arrow highlighting the Gemini Code Assist icon with a line through it denoting that it is currently disabled.

When clicking the Gemini Code Assist icon, you will be prompted to Sign In to a Google Cloud project with Gemini enabled. When prompted to authorize Cloud Shell, click Authorize.

Popup in the Google Cloud Shell Editor prompting to “Select Google Cloud Project”

When prompted, select the name of the Google Cloud project that we just created with Gemini for Google Cloud enabled. You should now see the Gemini Code Assist icon enabled (no longer a line through it)

Google Cloud Shell Editor status bar showing the Gemini Code Assist icon is now enabled

Try Out Gemini Code Assist in the Cloud Shell Editor

Now that we’ve completed the one-time steps to activate Gemini for Google Cloud and enable Gemini Code Assist in the Cloud Shell Editor, we can take it for a test drive! Let’s start by creating a Hello World Python app.

1 — In the Cloud Shell Editor, open the command palette by pressing Command+Shift+P (for MacOS) or Control+Shift+P (For Windows and Linux).

2 — In the command palette field, enter Cloud Code: New Application, and then click the result.

3 — From the list of available samples, select Cloud Run application.

4 — From the list of available templates, select Python (Flask): Cloud Run.

5 — Save the new app in your preferred location.

A notification confirms that your app was created. A preview of the README file for your selected service opens in your IDE.

Cloud Shell Editor with the README.md file open for Hello World Cloud Run

Now that you’ve created your Hello World app in Cloud Run, you can use Gemini to explain the files and code snippets that are deployed in your IDE.

In the left Explorer pane, click on the file named Dockerfile.

In the main code window, select all lines of code. A yellow light bulb icon will appear. Right-click the selected code and choose Gemini: Explain this

Main code window of the Cloud Shell Editor with all lines of code selected. The user is prompted with the Gemini menu to perform AI funcions:

In the left pane, Gemini generates an explanation in natural language about the contents and function of Dockerfile. If you're unsure about some points within the response, you can ask follow-up questions.

Main code window of the Cloud Shell Editor with a new Gemini Chat pane explaining the code.

Let’s go back to the Explorer pane and choose app.py. Highlight the section that includes “””Return a friendly HTTP greeting”””, click the yellow Code Actions icon and choose Gemini: Transform Code. When prompted, enter something like “Also resturn the time of day”

Main code window of the Cloud Shell Editor with a block of code selected. The user is prompted with the Gemini menu to Transform Code as asks to also return the time of day in the function.

If you are satisfied with the suggested code, click Accept, otherwise you can make changes to the proposed code.

Finally, select all of the code and click the yellow Code Actions icon and choose Generate Unit Tests. You’ll see some suggested unit tests in the left Gemini pane.

Main code window of the Cloud Shell Editor with all lines of code selected. The user is prompted with the Gemini menu to Generate Unit Tests. Gemini suggests unit tests in the left pane.

Summary

In this article, we explored Gemini for Google Cloud and Gemeni Code Assist. We walked through the steps to activate Gemini Code Assist in a Google Cloud project and detailed a hands-on example of how to use Gemini Code Assist to accelerate developer velocity.

Get Started with Gemini for Google Cloud

Ready to get started with Gemini for Google Cloud?

Try Gemini Code Assist and accelerate software delivery!

References

Gemini for Google Cloud

Gemini Code Assist (formerly Duet AI for Developers)

Gemini Code Assist overview

Code with Gemini Code Assist

Develop a Python app with Gemini for Google Cloud assistance

--

--