Take a spin with my new GitHub co-pilot ‘AI Pair Programmer’
I tried to get GitHub Copilot to write this article for me, but it couldn’t do it. He can do lots of other things. Some are quite nice.
If you haven’t heard of GitHub Copilot, it’s an advanced coding assistant tool similar to IntelliSense/IntelliCode that can do more than just suggest how to complete your lines of code. It is based on the advanced OpenAI Codex technology which allows natural language interaction. It recently became generally available for $10 per month (or $100 per year). It is also available in a 60 day trial, which I used.
I’m not a coder, but thought I could install it and try a few things. Here’s how it happened.
Configuration, authentication, pairing… and errors
One of the reasons I’m not a coder is that I’m impatient and impulsive and don’t follow instructions. I dive and try things until something works. (If you’re like that – probably not a coder, then – this article can serve as a lesson in what not to do to get started.)
So I didn’t follow the instructions in the documentation “Getting started with GitHub Copilot in Visual Studio Code” which says to go to VS Code Marketplace and find the extension and install it. I have not read this documentation. I just installed the extension from the editor.
While trying to use it, I got a notification to sign in to access GitHub Copilot.
I didn’t really expect this to work, but it seemed to.
I was warned “Extension ‘GitHub Copilot’ wants to connect using GitHub”, but the process timed out, generating this message: “You are not yet done authorizing this extension to use GitHub Would you like to keep trying?
I managed to make my way to a permission screen.
To complete the authentication, I had to go to GitHub and paste the one-time code generated from the authorization page.
This again took GitHub where I entered the code.
I was finally able to authorize GitHub for VS Code (GitHub reminding me that I live in the town of Libby, Montana).
And I was informed that I was ready.
Except I wasn’t. While trying to use the tool, I had to allow the extension to open the authentication URI.
Then I was informed that my experience was not fully set up and I needed to complete my setup.
I went to Settings and reached an “Enable GitHub Copilot” screen.
The 60 day trial
After which, I reached the 60-day trial page.
And confirmed my payment information.
Some preferences were then, where I could indicate whether I wanted GitHub to allow or block suggestions for public code, and whether I agreed to allow GitHub to use my code snippets to improve the product. I obligingly accepted the latter, although I can absolutely guarantee that no one wants to use my code snippets to improve their product.
And then I was presented with another step: pairing with my pair programmer.
After being informed (with colorful falling confetti, no less) that I had successfully paired, I received a message to install the extension. I had done that first thing, remember, so the documentation told me in this case that I just had to restart the editor.
I did, and my pair programmer and I were finally up and running! I had to go through a few extra steps because I didn’t follow the setup instructions, but I still felt like even the official process took a lot of steps.
//Generate a function to add two numbers together
By clicking Enter, the tool suggested a grayed-out code that could be accepted by clicking Tab. This caused Copilot to spin for a few seconds (the little GitHub Copilot icon at the bottom right is spinning).
The co-pilot activated line suggestion – turning grayed out text into properly formatted and colored code – then stood waiting for more instructions, as indicated by a red tilde.
Repeatedly clicking Enter brought up the whole function, complete with a helpful comment that the end of the function had been reached.
After this first success, I got frisky and decided to ask Copilot to calculate the value of pi (π). As I started typing “Compute pi…”, I got a suggestion to use Leibniz’s formula for this calculation of pi. When I started typing “Calculate the value of pi…”, Copilot suggested “…until the nth digit”.
You can supposedly browse suggestions with the Windows key combinations (with Mac equivalents) of
Alt + ] (forward) or
Alt + ] (backward). I couldn’t get the suggestions to cycle through the various options, or get Copilot to calculate the value of pi in any form, even accepting suggestions. Update: The day after this article was published, I tried the pi calculation again and it worked perfectly. Go figure. I used the exact same command but this time it gave this:
//Compute the value of pi //The value of pi is 3.141592653589793
I tried to generate a function to calculate the area of a circle and found that if I kept hitting Tab, Copilot kept generating comments explaining aspects of the equation, eventually repeating itself until ’til I click enter and complete the function code.
I asked Copilot to start a new HTTP server and it did this:
var http = require('http'); //import http module from node js
I tried a series of “Create a…” commands to see what Copilot came up with as suggestions. Suggestions from various comments are presented below, with the suggestions in parentheses.
Create a new (copilot object)
Create a function (which takes a string and returns the string in reverse order)
Create a table of contents (of the co-pilot test)
Regarding the latter, all that happened after clicking Tab to accept the suggestion was that Copilot generated this comment:
//Create a table of contents for the copilot test. This will be used to generate the copilot test. The table of contents will be generated from the copilot test.
When I kept pressing Tab, the comments started repeating.
I tried the
// Express server on port 3000 command from the official documentation and found that Copilot also started repeating itself when I kept clicking Enter/Tab combinations. It first generated over 75 lines of code that looked like a complete and correct program. But when I kept clicking Enter/Tab combinations, it eventually started repeating itself in the Routes section of the code.
Explain this code
I also tried the “explain this code” feature provided in the GitHub Copilot Labs companion extension (preview). As the name suggests, this experimental tool can take a piece of code and explain in natural language what it does.
I didn’t have to jump through any hoops to install this tool; I did it quickly and easily from the editor – no context switching or restarting required.
In the sidebar, it offers two options, Explain and Language Translation.
My first attempt at explaining (by highlighting some code and clicking the Ask Copilot button) produced an error message: “Error generating response from copilot, please try again. Changes in the prompt or shutdown sequence may resolve this issue.”
I don’t know what “changes in prompt” or “shutdown sequence” even mean, but reloading VS Code and logging back in to use Copilot worked.
I grabbed a piece of code from Mozilla’s site and asked Copilot what it meant.