Duet AI Review: My Perception and Use Cases — Part 2

Rubens Zimbres
Google Cloud - Community
5 min readNov 14, 2023

This article is Part 2 of a two-part review on Duet AI (Part 1 here), presenting my perceptions about the use of the tool. Here, I will approach some use cases and coding capabilities of Duet AI.

In the Google environment, there are three ways to get some help with code: first, use Google Cloud Generative AI Studio, select Language then Code Prompt (Codey chat interface that uses code-bison via PaLM API), Bard (chat interface that uses LaMDA) and Duet AI (has a chat interface and also code generation via PaLM). All of them are able to interact with prompts and have memory about past prompts, that is, you can build code (and sometimes run it in the chat interface!) with successive prompts. In this article, I will show Duet AI capabilities related to coding, how its use boosts productivity and some use cases.

Duet AI is a tool that uses Generative AI (LLMs) to provide a variety of features. Specifically for coding, we have:

  • Code companion: it helps translating code between languages, creating code, understanding code, completing code, creating unit tests and solving code vulnerabilities. In this specific case (coding), I tested it in VS Code and Google Cloud.

Duet AI in the Workplace

Here are some specific examples of how Duet AI can be used in coding:

  • A Software Engineer can use Duet AI to help them write a new feature for their application. They can simply describe the feature they want to build in natural language, and Duet AI will generate the code for them.
  • A Machine Learning Engineer needs to develop a pipeline in Kuberflow for a Tensorflow model, but wants to know other options rather than Cloud Composer to schedule this pipeline daily.
  • A Data Scientist wants to regex a specific string and then customize the matplotlib plot according to specific requirements of the client.
  • A Data Engineer wants to generate queries, write data processing scripts or even debug data pipelines. Duet AI helps with these tasks.

Code Companion

Duet AI can be used for code generation and understanding in a number of ways. For example:

  • Code generation: Duet AI can generate code in a variety of programming languages, including Python, Java, JavaScript, and Go. This can be useful for tasks such as generating boilerplate code, writing unit tests, and implementing new features. Instead of searching the whole documentation for a specific code snippet, you get it only by asking in plain text. You can generate full blocks of code to do the task you want. For instance, you want to create a bucket in Google Cloud, add audio files and then use Speech-to-Text to transcribe these files. Instead of searching the documentation for these two services, you create a comment in the notebook and full blocks of the right code will show up, in seconds.
  • Code completion: Duet AI can provide code completion suggestions based on the context of the code being written. This can help developers write code more quickly and accurately. This feature was especially useful for me, when I created and deployed a Generative AI solution in my website (article here), as I didn’t have enough knowledge of HTML to call a Cloud Run endpoint. Once you developed a piece of code, you can debug errors in the same Duet AI chat interface in order to correct the code and solve the issue.
  • Code understanding: Duet AI can help developers understand code by providing summaries of code blocks in the Duet AI chat, identifying potential problems, and suggesting solutions. This can be useful for tasks such as debugging code, onboarding to new codebases, and maintaining code.
Code explanation by Duet AI
  • Code assistance: Duet AI can help developers write code more efficiently and accurately by providing code suggestions and completing code blocks.
  • Code explanation: once you select a block of code, Duet AI has a side panel (chat) that allows you to understand what the code is doing and even solve vulnerabilities that may exist.
  • Debugging: Duet AI can help developers debug code by identifying potential problems and suggesting solutions. This is useful in VS Code and also in Google Cloud. For instance, you are deploying a container in GKE (Google Kubernetes Engine) or Cloud Run and the deployment fails. You go to Logs Explorer and see there is a Fail entry. Instead of searching the error(s) in StackOverflow, ask Duet AI via Google Cloud Side Panel and it will provide the solution.

Here are some specific examples of how Duet AI can be used for code generation and understanding:

  • A developer can use Duet AI to generate a boilerplate function for a new feature they are implementing. This can save them time and effort, and help them to avoid making mistakes.
  • Duet AI can be used to generate a unit test for a new piece of code a developer has written. This can help him/her to ensure that the code is working correctly.
  • A developer can use Duet AI to get a summary of a code block they are trying to understand. This can help them to quickly understand the purpose of the code and how it works. Here, there may be an advantage to overcome technical debt on undocumented code.
  • A developer can use Duet AI to identify potential problems in their code. This can help them to fix bugs before they cause problems in production.
  • A developer can convert a Python code to C++ or other language, like JAVA. Note in the image below that besides converting the code, Duet AI also inserts comments in the generated C++ notebook (side panel at left).
Python code conversion to C++ using Duet AI

Although not in GA yet, I noticed some benefits of using Duet AI:

  • Increased productivity: Duet AI helped me to write code more quickly by automating tasks and providing real-time assistance, in case of issues.
  • Improved code quality: it also helped me to identify potential problems and suggesting solutions, including security issues.
  • Reduced development time: as Duet AI may output complete pieces of code for Google Cloud, it helped me to reduce the time it takes to develop and deploy applications. For instance, you can get complete blocks of code when using Tensorflow or Google Cloud services and APIs, like Storage, Translation, Speech-to-text, BigQuery, without the need to search in the documentation.
  • Improved developer experience: it makes it easier and more straightforward to write code. Sometimes the response takes some time, but Google is working on it for GA.
Code generation in VS Code using Duet AI

I hope you liked my two articles about my Duet AI experience. As you can see, this will become a powerful tool to increase the efficiency of coding, saving us time and effort in our daily routine.

* Google ML Developer Programs team supported this work by providing Google Cloud Credits

--

--

Rubens Zimbres
Google Cloud - Community

I’m a Senior Data Scientist and Google Developer Expert in ML and GCP. I love studying NLP algos and Cloud Infra. CompTIA Security +. PhD. www.rubenszimbres.phd