In my last post, I went through a list of things I'm excited about for the new JetBrains AI Assistant that runs inside JetBrains IDEs. Since I'm off from work for the end-of-year shutdown, I've got some spare time to take it out for a test drive.
For my first time taking the JetBrains AI Assistant (which I'll call the JBAI for short) for a spin, I thought I'd go big with an attempt at what I'm calling Chat-Driven Development. That is, test-driven development through code generated by an AI.
A big thanks to Denise Yu for letting me use her Gophermon drawings for this blog series!
Series tl;dr: I was able to chat with the JBAI, so that it created a unit test for a shell function, and then asked it to implement that function. And it freaking worked.
This post's tl;dr: Lessons learned:
Do the simple stuff yourself, rather than spending too much time trying to negotiate the right prompt for the JBAI.
The AI Assistant chat and the Generate Code feature operate entirely differently.
Just want to see the code? The code for this part of the series lives on a branch in this GitHub repo.
I probably could have gotten away with a simple hello-world app that featured some basic Golang, but that wouldn't have been much of a test drive. For this project, I wanted to build a multi-layer RESTful microservice.
The data would be just an in-memory map, so that part isn't very complex. BUT! This gives me a chance to see how the JBAI does with integrating building out and integrating a service layer into REST handlers that conform to an open-source library. That's pretty ambitious, considering this is only the first date.
This is part one of my pair-programming experience with the JBAI. There will be a total of five parts:
Getting Started (or, Forming)
Early Stumbles and Small Wins (or, Storming)
Hitting a Groove (or, Norming)
Connecting the Pieces (or, Performing)
Lessons Learned (or, Adjourning)
As far as my Google search results can tell me, I'm the first person to use this term. So, if that's accurate...awesome.
Think it works? Or am I just trying to make "fetch" happen?
This series goes through my experience building out a demo RESTful web service almost entirely using the JBAI.
Using the JBAI
There are two core ways to use JBAI in Goland (and I'd imagine the case is the same in the other IDEs).
The first, most obvious, and likely the most familiar for users getting started (because it looks like ChatGPT), is to open the AI Assistant panel on the right side of the window. This is where you might ask questions and expect to get answers that you can then implement in your code.
The second, less obvious, and far more powerful is by right-clicking (or two-finger clicking for us Mac-users) in the actual editor window, where you'd like to modify your code. This will bring up a context menu, and in that is the AI Actions sub-menu, which includes Code Generation, and opens a prompt input in the text editor, at the line you've clicked on.
That's where happiness lives.
The Setup
I'm used to creating a project with a basic structure, so before I knew it I had already manually created an empty main
function in main.go
:
package main
func main() {}
And I had an app
package with an app.go
file:
package app
func Start() {}
Notice that at this point, the main
function doesn't call the app.Start
function yet. Let's start with some baby steps and see if we can get JBAI to call it for us.
Starting Simple, Which Went Poorly
Maybe I wasn't prompting right, but the simple task of asking JBAI to have main
call app.Start
didn't go very well.
I right-clicked on the empty main funtion, and asked the following:
Me: Can you please have this main function call the Start function from the app package in this module?
The result was less than stellar:
package main
import "app"
func main() {
app.Start()
}
Well, there's no such package called app
in Golang; even the IDE code validator knew this wasn't going to work. So I clicked on the specify option in the JBAI diff to add more context to my prompt:
Me > Generate Code > Specify: Can you please modify the import path so that it reflects the app package being in this module?
That didn't go very well either:
package main
import "./app"
func main() {
./app.Start()
}
I thought it might need a point of reference to base the import URL from, so I asked:
Me > Generate Code > Specify: Can you please modify the import URL so that it matches the module URL listed in the go.mod file?
package main
import "module/url/app"
func main() {
./app.Start()
}
Sigh.
The first test run of Chat-Driven Development didn't go well. I took way more time trying to tweak my prompts than it would have taken for me to use the IDE's long-existing autocomplete to just plugin a call to app.Start
, and having the IDE's intelligence automatically add the import statement with the correct URL.
Conclusion: do the simple stuff yourself, rather than spending too much time trying to negotiate the right prompt.
Taking a Different Approach
Ok, not great. But I was not giving up yet.
I thought it might be a good idea to ask JBAI in its chat panel what some good RESTful libraries are that I can use:
Me > AI Assistant Chat: What are some of the best rest libraries that I can use?
The response came with four different options, including Gin and Gorilla Mux at the top:
JBAI > AI Assistant Chat: There are many great libraries available to support RESTful API development. The choice can depend on the specific requirements and the programming language being used. As this project is using the Go programming language, here are few Go libraries that are considered good for building REST APIs:
Gin: A very minimalistic framework that performs exceptionally well. It's simple to use and comes with features like routing, middleware support, rendering, and more. You can install it using go get: go get -u github.com/gin-gonic/gin
Gorilla Mux: It implements a request router and dispatcher for matching incoming requests to their respective handler. The name mux stands for "HTTP request multiplexer". To install it: go get -u github.com/gorilla/mux
(There were some others; I left them out for brevity)
Ok, now we're getting somewhere.
I asked it to install Gin, and it said:
JBAI > AI Assistant Chat: I'm sorry for any misunderstandings, but as an AI Assistant, I don't have the capability to add dependencies directly to your project.
Not my fave. However, it did print the command to run the installation myself in my terminal, with a convenient clipboard icon for copying:
go get github.com/gin-gonic/gin
Ok, that's progress. It saved me time from having to Google the Gin repo, find the installation part of the readme, and then copying it there before coming back to my command line.
Next conclusion: The AI Assistant chat and the Generate Code feature operate entirely differently. This will become apparent later on, when the JBAI introduces a hidden dependency.
What's Next?
This whole experiment hinges on the JBAI's ability to receive a prompt and generate not only the function I'm looking for, but also the tests that prove its functionality. In the next post, I'll actually dive into prompting functional code generation.
Since the next part is called "Storming", you can probably imagine there were some bumps in the road.