Because you can't type fast enough.

Because you can't type fast enough.

Now as the dust has settled after Google Next '23 (or has it?), I wanted to give DuetAI a go. DuetAI was all over the place during Google Next '23. Those who watched it saw it in a context of Workspace as well as Google Cloud. Let's see what it brings to Google Cloud.

What is DuetAI

In short, Duet AI (available in preview as of writing this article), is a brand that spans across Google Workspace and Google Cloud products that manifests its presence in the form of various assistive widgets. As far as Google Cloud is concerned those widgets aim to provide support to developers, cloud operators and admins as well as those who work with data and security.

It's also an example of Google Cloud implementing its own tech for every Google Cloud Platform user, and that is cool.

DuetAI Admins and Operators

In Cloud Console we have a button in the top right corner, next to the Cloud Shell that opens up a chat window where you can ask all sort of questions that as a cloud admin or a cloud operator you may have every day, like "How can I migrate a database form on-prem to GCP" or "How can I reduce cost of running PostgreSQL instances?".

DuetAI icon on the left

And since it's been trained on GCP documentation it provides pretty accurate responses like recommending using Database Migration Service or advising to enable Committed Use Discounts respectively.

Here's an example of how I learnt about AlloyDB AI from asking about database migrations options.

DuetAI on migrating a database
DuetAI on supported source databases

NOTE: There are other source databases that DMS supports, including Amazon RDS and Aurora, however since in the previous prompt I asked about the on-prem databases, it stayed in that context.

Next, my attention was dragged to the AlloyDb.

DueAI on AlloyDB

That way I learnt that there's been an announcement on AlloyDB AI :-) This can go on and on for ages so let's move on.

DuetAI for Developers

DuetAI for Developers comes with the Cloud Code, which is a set of IDE plugins for popular IDEs like Visual Studio Code, JetBrains and Google Cloud Workstations that make it easier to create, deploy and integrate applications with Google Cloud.

I'm going to use my local VSS Code with the Cloud Code installed that already includes DuetAI component and is authenticated to GCP.

Interacting with LLMs requires writing a prompt. In the case of DuetAI for Developers writing a commented line means writing the prompt. This is the first component of DuetAI in the IDE. It will propose code, it will also autocomplete code, so that not everything needs prompting, you just write code as usual and it will autocomplete multiple lines for you. Also, it learns from you, if you want to write a function you've used before it will generate code based on what you've already done which speeds the things even more.

I'll create a folder and a file in it and call it app.go. Once the prompt has been written I either hit Ctrl+Enter or the Magic Wand in the top right corner to trigger the code generation.

Proposed code in response to the prompt

Looks good to me so I go ahead and accept it with 'Tab' and run it. There's an error though.

Running the code

Although the error is pretty obvious. Let's discover the second component of assistive development - Duet AI chat in IDE. It's the same icon as in the Cloud Console but on the extensions panel on the left. Let's ask about this error then apply the suggested code and run it again.

Fixing stuff with DuetAI Chat

Success.

What we have actually done was to use the Moby Namesgenerator package to generate us some names. Some of you might remember what Moby is if you've been watching Docker development ;-). If I ask it to use the namesgenerator again, it will insert an int for GetRandomName() following what I've done. That's pretty useful.

What else can we do with this? Let's try to add another prompt asking Duet AI to expose this function as a web server.

Let's accept the new code and comment out what was generated in the previous step and give it a go.

All works as expected. Let's ask the chat to add some comments to the code to add some quality.

Now that we have it running locally. Let's try to deploy it to GCP. First I'll ask the chat, without giving it much of the context, to advise me on which service would it be best to run this code on. It recommends deploying it to Cloud Run. I then asked him to tell me how to deploy this source code Cloud Run and I received the following gcloud command then I copied it to the terminal window and ran:

gcloud run deploy random-name --source .        
Deploying to Cloud Run from source.

What this command does is that it creates a container image with Cloud Build and uploads it to the Artifact Registry's repo that is also created automatically, if doesn't exist, during the deployment process. Once the image is built and uploaded it gets deployed to Cloud Run. Notice, I didn't have to even write a Dockerfile. Cloud Build will use a relevant buildpack to build that image.

I run the command and pass on the region inline for better visibility.

Deployed to Cloud Run with the help from DuetAI

After a couple of minutes the service is deployed, let's test it.

I'm trying to cURL the URL I was provided but it fails.

Connection fails for nonauthorized connection

If you have been following carefully, you'd have noticed that I did not opt-in during the deployment dialog in the previous step for unauthenticated connections.

Since I can't remember the exact syntax of the cURL with authentication. Let's ask the DuetAI chat again to provide us the right syntax.

Successful call to my Cloud Run service

The response is helpful and in the context of GCP, as it provided me the gcloud command to get the token so that I can do it in one line without copying the token and using it in clear text here.

Just one more example that worked with a zero-shot prompt was to write a function that will use Google Translate API to translate from any language to English that generated over 50 lines of code.

Note: I typed in a sentence in Polish while it generated "Hello World" in line 24.

Zero-shot prompt that generated 50+ lines of code

To summarize, I was able to create code and deploy it to GCP Cloud Run service without writing a single line of code.

Having two incarnations of Duet AI for Developers, the code generator and the chat, is absolutely fantastic. There's no doubt about increased productivity while writing code faster and staying in a flow state longer, translating ideas into code rather than focusing on typing, switching windows and browsing documentation.

DuetAI for Developers uses Google trained models that are accessed via the Chat and the Magic Wand interfaces. These models aren't directly available to users but should you need to experiment with the code generative models directly you can access them from Vertex AI. Vertex AI includes a suite of models that work with code generation, code completion and chat (code-bison, code-gecko, codechat-bison respectively) that support well over 30 programming languages. See this overview of the models available.

Whether you use DueAI or the models directly you'll be able to generate code, benefit from code autocompletion, rewrite code from one language to another, explain what the code does and get help with fixing errors.

Whether you're already thinking of whether this may work for you in your daily job or not, you should at least give it a try, simply for the sake of the fact that you can't type fast enough anymore.

What about those who work with data

That part deserves a separate post as there's a lot of development in this space but not to leave this space empty, let's just have a quick look at how it can generate SQL queries from a prompt on a dataset in BigQuery.

For this example I'll add one of the public datasets that represents data on bike trips from a City bike system in NYC. Here's a preview of what that dataset looks like;

nyc_city_bike_trips dataset

I'll give it a zero-shot prompt asking to find the station IDs with the capacity for over 100 bikes:

Generating SQL query with a prompt

Looks good to me and it even included the 'name, how nice. Let's accept it and run it:

Testing the query.


If you're more of a data analyst you'll find it helpful in BigQuery as well as Looker while creating dashboards and if you're a data scientist, Duet AI in Colab for example will make it easier to build AI/ML models in Python demonstrating similar benefits like in DuetAI for Developers - focus on model building, not typing code. There's DuetAI for Security (Security Command Center and Mandiant) as well as Apigee to help you to build APIs faster.

In any of the above cases whether you're a developer, work with data or you're a cloud admin, you'll need to think about the prompt as writing a prompt can be an art sometimes. To learn more about writing good prompts for DuetAI, take a look at the Prompt guide.

Happy prompting.

要查看或添加评论,请登录

Miroslaw Polski的更多文章

社区洞察

其他会员也浏览了