JOE FERNANDEZ: In this video, we'll
explore how you can build an AI-powered tool
to help you write code.
Let's go.
[MUSIC PLAYING]
Hey folks, welcome to Build with Google AI, where we explore
how you can build practical solutions with Google AI
technology.
Writing code can be a lot of fun.
I really enjoy building new applications and tools
to demonstrate ideas, solve problems, and automate tasks.
But there's quite a lot of stuff about coding that isn't fun,
like documenting my code with comments.
Why do I need to explain my code?
It just works.
Isn't that enough?
[CRICKETS CHIRPING]
Anyway, the other thing that bothers me
when I'm writing code is whether or not
I've made some obvious mistakes.
Could I write this more efficiently?
Is there a common pattern I should be following?
I could ask my colleagues.
But inevitably, I have these thoughts way
after hours, or when folks are just
too busy to look at my experimental, half-baked code.
What to do?
Well, some of those colleagues and I
decided to apply artificial intelligence to this problem
and asked Google AI'S language models for help.
So we built Pipet code agent, an extension for Visual Studio
Code, to do just that.
Here's a quick demo.
The Pipet extension adds a couple of new commands
that you can use in a code editing window.
Let's say I wanted to add a comment
to explain the snippet from a transformer tutorial.
Just select the code where you want
to add an explanatory comment, like this function here.
Open the command palette.
Type "pipet," select the comment function, and hit Enter.
After a few seconds, the AI language model
generates a comment that explains what that code does.
This is helpful, since I really don't
like writing code comments.
However, I do need to read and verify this comment before I
submit it.
The code review function works the same way,
except that it gives you a critical feedback
for your code.
Here's a bit of code I wrote for visualizing some data.
I'll just select that part of the code
and run the review command.
Now, the AI will discover the various ways
I've failed to follow good coding practices
and tell me about them.
All right, well, let's go talk to the folks who built this--
[CLEARS THROAT]---- very helpful AI coding tool.
Woo, OK, so I'm joined today by our key contributors
to the Pipet code agent project, Shilpa Kancharla
and Mark McDonald.
Thanks for being here.
SHILPA KANCHARLA: Thanks for having me.
MARK MCDONALD: Hi, Joe.
Thanks for having us.
JOE FERNANDEZ: Now, I realize that I'm the one who
started this project.
But you guys are the ones who actually
built out the functionality.
So my question is, was it worth the effort?
Can AI technology actually help you do better code?
MARK MCDONALD: Yeah, absolutely.
We found that it was particularly helpful
having the tool available right where we're coding, so
like, right in the editor.
This way, you can ask questions as you're going.
And you can get it to generate things
like comments, or code reviews, or look for errors in the code,
and keep your pace up while you're working.
The AI models are really enthusiastic,
and they want to help.
So it's good to be able to ask questions
as if it's another person that you're pair programming with.
But we realize that sometimes, it's not perfect.
So no matter what, we always want
to make sure that we have a human reviewing the output
before we use it in production.
We are in the early days of this AI technology still.
But it's getting better really quickly.
In the meantime, it is still important
that you review your code before using it anywhere important.
JOE FERNANDEZ: OK, so next question--
how does the Pipet extension actually work?
SHILPA KANCHARLA: So it's actually pretty simple.
The extension just adds on to the VS Code interface.
What you do first is you select a piece of code
that you're interested in.
And from there, you can use the tool
to select if you're interested in generating a comment for it
or doing some code review for it.
So the extension command takes the code
that you selected, and it creates
a prompt based off that.
That prompt gets sent to the language model API.
When the response comes back, that code
gets inserted into the editor.
JOE FERNANDEZ: OK, great.
So next question-- if I want to extend this extension,
how do I do that?
MARK MCDONALD: Right, there's a couple different ways
you can extend it.
You can take one of the existing commands
and tweak the prompt a little bit to more suit
your language, your style, or the way that you work.
Or you can create a whole new command.
You could build something that integrates
with your commit process and gives you
a review feedback before you submit your code,
or comment on your code as you go.
Ultimately, you can build something
that fits in with your workflow as you like it.
JOE FERNANDEZ: OK, great.
So from what you've explained, you haven't actually
built any AI models though.
Isn't this kind of cheating?
SHILPA KANCHARLA: Well, working with AI models
is more than just building the model itself.
It's also about how you use it.
So learning how to build the model and also
the applications of it, both are equally important.
And don't let your lack of knowledge with AI
deter you from building applications with it.
A lot of great software developers
out there don't have a background in AI,
but they can still use AI to build new applications.
JOE FERNANDEZ: OK, great.
Well, thanks to both of you for being here.
Really appreciate you talking to me about the Pipet project.
SHILPA KANCHARLA: Thank you.
It was great being here.
MARK MCDONALD: Awesome, thanks for having me, Joe.
JOE FERNANDEZ: It's coding time.
Let's look at how you can extend Pipet code
agent to create your own AI-powered coding features.
Don't worry about taking notes.
There's a detailed tutorial linked in the description.
Here's the code for the Pipet extension.
The comments file contains the main code
for the commenting command.
This command uses the few-shot prompting technique.
It provides the AI language model
with several examples of what you want for a code comment.
And those examples guide the AI in generating text.
The simplest way to modify this functionality of this command
is to change the content of this prompt.
Update the examples.
Add more examples.
Or give the language model different instructions.
But what if you want to build a command that does something
completely different?
Let's say you want to write a function
to solve that most vexing of programming problems,
what to name things.
Start by making a copy of one of the existing commands.
Here, I've made a copy of the comments.ts code file
and modified it.
Give the command a new name.
Now, the important part, changing the prompt text--
you don't have to give the language model examples,
although it does give you more control of the output.
In this case, I'm going to ask for a function name
and tell the AI to explain its recommendation.
In my example, I'm updating the code that
assembles that final prompt.
But if you're using the multiple example approach,
you don't need to change this.
Now, connect this new command to the rest of the extension.
Add the command to the extension.ts file.
Then, in the package.json file, register the new command
in the contributes commands section
so you can run this new feature from the command palette.
Test the new command by selecting Run from the menu,
and start debugging.
Or just press the F5 key.
I'll take the function I was using before
and give it my default name.
Let's see what the language model thinks
we should call this function.
Nice.
The project team and I had a lot of ideas on what else
we could do with this extension, but we didn't have time
to try them all.
You might already have some ideas, so go build it.
There's a complete tutorial on extending Pipet, link below.
Let's wrap this up.
That's all the time I have to tell you
about this AI-powered coding project, Pipet code agent.
Thanks to my guests, Shilpa and Mark,
from Google's AI developer relations team.
Links to the code project and a detailed tutorial
about how to extend it are in the description.
If you get some new functionality working,
let us know in the comments.
Thanks for watching.
I really hope this video helps you build your own coding
agent that makes you and other developers
more productive with AI.
Keep learning.
Keep building.
Make something great.
We'll see you again soon.
[MUSIC PLAYING]