AI programming for Python: Github Co-Pilot

I posted this on Logik Discord channel, and I’m posting here for posterity.

My son who’s a great programmer turned me onto this AI plugin from Github and I think Microsoft collab. It’s called Github Co-Pilot and it’s a plug-in for Visual Studio and PyCharm:

Basically, it’s a glorified autocomplete and it’s trained on all the open source code in the Github repositories. It’s still in beta and you have to sign up to get a login to activate the plugin. It took me a couple months to get my invite but I think they are rolling this quicker so you may get your invite sooner than I did.

There are 3 methods (that I can tell) to invoke the Co-Pilot suggestions:

1) Write what you want to do in a comment like this:

# Make a list of fruit and print the list

What’s crazy is that even when you’re writing the comment, Co-Pilot will make suggestion for the comment itself. Co-Pilot is based on a natural language AI library called Codex so it’s not just for code suggestions. Sometimes it feels like it’s anticipating what you want next…when I typed “Make a list of fruit”…it suggests (in greyed out type) “and print the list” as the next step. You hit the Tab key to accept the suggestion.

2) Make your variables and function names descriptive.

For instance, if you start a function named:

def log_into_shotgun ()

Then Co-Pliot will guess that you want to login into shogun with the shotgun api and give you something like this:

def log_into_shotgun(user, password):
    # connect to shotgun
    sg = shotgun_api3.Shotgun('http://mrwolf.shotgunstudios.com', user, password)
    # get the project
    project = sg.find_one('Project', [['name', 'is', 'MrWolf']])
    # get the shots
    shots = sg.find('Shot', [['project', 'is', project]])
    # return the connection
    return sg

It takes into context all the text in the current file, so it was ‘smart’ enough to grab http://mrwolf.shotgunstudios.com from somewhere else in my file and infer that that was the url for the shotgun login!

  1. Open the Co-Pilot panel and it will give you 5-6 choices.

It gives you around 6 code blocks and you hit the “accept” button under the option you want to use.

So, in real world practice, the AI suggestions can either be way off base but for the most part it’s pretty useful and at best it’s uncanny in how it predicts what you want to do where it gives me the chills and goose bumps.

On the whole it does save you time, but at the end of the day, you still need to understand the code to make sure it actually works.

Usually, when I code… I write a couple lines, hit a wall, search Stack Overflow for an answer, cut and paste and so on and on. It’s tedious and time consuming. Also, I don’t code with enough frequency to remember something basic like how to catch an exception from memory. So I’m aways looking up how to do basic Python tasks. With Github Co-Pilot, you can quickly enter what you want to do in a comment as if you’re googling it, and Co-Pilot will give you an answer and you can move on without interruption.

That being said…Co-Pilot is limited to the code base it’s trained on which is the Github repository. So, if you want examples of code using the Flame api, Co-Pilot’s ‘knowledge’ will be limited because there isn’t enough Flame code on Github. You’ll have better luck with Shotgun and Pyside2 (QT Gui) programming and of course, more general topics like sorting algorithms or network related tasks.

Anyways, Co-Pilot has definitely made programming more fun for me and letting me code more efficiently.

Hit me up if you want some pointers with this plugin and also with PyCharm in general!

5 Likes

That is straight up bananas.

1 Like

There is apparently some question about its use of copyright, as they trained it on the entirety of Github. Here it is helpfully adding some Quake 3 code!

Excellent point Brian!

I bet professional software companies probably ban the use of this plug-in and other AI tools (there are actually a lot out there now) because of these copyright issues.

And you can use this technology to write literary papers for school as well.

I don’t know if you can put the genie back in the bottle at this point. Anyways, I’m taking advantage of this to alleviate the drudgery of programming for my personal projects and honestly, it’s hit and miss most of the time with occasional moments that blow your mind.

1 Like

I don’t think John Carmack’s lawyers are ever going to come after you for your homebrew python stuff, Danny. And while I’d hope we’re small enough to stay off of the radar, I can see a situation where a cool script written with the help of this plugin gets uploaded to the Flame portal and stuff maybe gets weird.

Hope you’re well, man!