Getting Started with Gemini Code Assist
Google Cloud’s always-on Coding Assistant
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.
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:
- 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.
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
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/
Locate the name of the project that we just created (you may need to click the “All” tab).
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
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
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.
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)
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.
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
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.
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”
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.
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 Code Assist (formerly Duet AI for Developers)
Develop a Python app with Gemini for Google Cloud assistance