Getting started with Duet AI on Google Cloud and VS Code

Exploring Google’s Duet AI on VS Code and GCP console

Akhilesh Mishra
Google Cloud - Community
6 min readDec 21, 2023

--

Google introduced Duet AI as an alternative to Microsoft co-pilot with a twist. It doesn't only generate the code, It also enables you to deploy various services on Google Cloud, detect security bugs in your cloud Infra, provide simplified documentation about Google Cloud, etc.

Note: You can use Duet AI for Developers at no cost until Feb 1, 2024, after that, it will cost you $19 per month with an annual commitment.

Photo by Steve Johnson on Unsplash

Duet AI is a handy tool that uses generative AI to do lots of cool things, such as:

  1. Chatting in real-time: It can have live conversations with users, answering questions and giving information in a way that’s easy to understand. It’s great for things like coding or figuring out stuff about Google Cloud.
  2. Finding information: Duet AI can look up and get info from different places like the internet, databases, and other smart sources. This makes it super useful for doing research and learning new things. Plus, it works well with Google Workspace, so it’s good for work, marketing, sales, and education.
  3. Helping with code: If you’re into coding, Duet AI is like a buddy. It can translate code between languages, create code, understand code, make unit tests, and fix code problems.

Getting started with Duet AI on VS Code

Google provides a VS Code extension to use DuetAI from your VS Code IDE. It also provides extensions for JetBrains IDEs, and it is available from Google Cloud Shell. In this blog, I will test Duet AI on VS code.

Let’s get going

  1. Install vs code extension for Duet AI— Google Cloud Code

2. To use this you will need to connect your VS code to a Google Cloud project. Go to the extension and scroll to the bottom to sign into Google Cloud.

3. Now go to change settings and make sure duet ai is enabled.

4. Enable duet AI project

To use duetAI, you need to 2 things.

  • Assign the Cloud AI Companion User, and Service Usage Viewer roles to your user or the service account you used to authenticate the extension.
  • Enable cloud AI Companion API in your Google Cloud project

5. Log into the Google Cloud console and enable Cloud AI Companion API in the GCP project

Now that you have completed the setup, let's use the cloud code extension and see what we can do with it.

Cloud code extension can be used to deploy services like Kubernetes, cloud run, cloud function, and many more services.

Deploying a cloud-run service using the cloud code extension and DUET AI

You can use the extension to create a sample application which you can modify as needed, and DUET AI will do most of the work.

Before you start with cloud run, make sure you have enabled the cloud run API.

This will create a simple flask app code, a docker file including a readme.MD file with a step-by-step guide to deploy the cloud run function.

Asking DUET AI to help us deploy a cloud-run service

Open the app.py file switch to the Duet AI tab on the left and ask it to explain the code.

See how effortlessly it explained the complete code. Let’s ask it how to deploy a cloud-run service.

How to deploy this cloud run app

Open the terminal and try to deploy the app using the cloud commands suggested by Duet AI.

# Install gcloud cli on mac
brew install --cask google-cloud-sdk

# authenticate to GCP and set project and
gcloud auth login
gcloud config set project duetai-poc-132456
gcloud config set compute/region europe-west1

# Deploying the docker image in gcr
gcloud builds submit --tag gcr.io/duetai-poc-132456/hello-world

# Deploy the cloud run service
gcloud run deploy hello-world --image gcr.io/duetai-poc-132456/hello-world

And that is all, now go to the URL — https://duetai-poc-132456-hello-world.a.run.app

Now let's ask Duet AI to repurpose the code with one simple query prompt.

I want to repurpose this application to be a photo 
editing app that can do somebasic photo editing.
Also generate the html templates for it.

This will create the Python code along with HTML templates to go with it. It also tests the code so we get the result as intended.

We will replace the app.py code with the snippets provided by DuetAI.

If you hover over the code, it will tell you the source/information of the code and licensing information.

I will deploy the app and see how it looks.

I tested uploading the picture and it worked although it could have been better with the editing image part. I had to provide multiple prompts to get it here. This is how it looks.

Now you can keep building it up by providing more prompts, and it should generate the code for you.

Using Duet AI for exploring logs summary.

Duet AI can be very helpful while working with logs. It can thoroughly explain the complex logs.

In my project, I tried to create an auto-pilot project and its creation failed due to an org policy that disabled the use of public IP. Let's see what logs say about it with the help of Duet AI.

Let’s go to Log Explorer in the Google Cloud console. We see a lot of errors on VM. Let's take a look at one of them.

And this is what it tells us.

Conclusion

Duet AI looks promising, especially for devops engineers like me who have to work with provisioning cloud infrastructure, fixing security issues, analyzing logs, writing automation scripts evolving multiple GCP services, building pipelines, and sometimes building small tools using Python/JS frameworks.

There are so many great use cases of Duet AI and I will cover those in upcoming blogs.

Follow me so you don’t miss out on great content like this.

Connect with me on Linkedin: https://www.linkedin.com/in/akhilesh-mishra-0ab886124/

--

--

Akhilesh Mishra
Google Cloud - Community

Self taught DevOps engineer with expertise in multi-cloud, and various DevOps tools. Open for mentorship - https://topmate.io/akhilesh_mishra