What is GitHub Copilot and how it works?

What is GitHub Copilot?

GitHub Copilot might be one of the most intersting AI use case from Microsoft GitHub in 2021. In this post, we look into an overview of what is GitHub Copilot and how it works with some examples.


GitHub Copilot is an artificial intelligence tool developed by GitHub and OpenAI to assist users of Visual Studio Code, Neovim, and JetBrains by autocompleting code. It was first announced by GitHub on 29 June 2021.


If you visit the GitHub Copilot official website, you will see the brief summary of Copilot as "Your AI pair programmer", and with GitHub Copilot, get suggestions for whole lines or entire functions right inside your editor.



How it works?

So based on the above description, we get an idea about what is Copilot - your pair programmer which can provide quick suggestions for completing your code (e.g., entire functions) in your editor so that you can complete your code without actually typing the content of a function for example.


To test with some examples, I applied GitHub Copilot Technical Preview and got approved, and used the following environments for the testing:


First example: Binary Search

The following video shows how we can complete binary_search function with the help of Copilot where its suggested code will be shown in gray color, and if you like the suggestion, you can use [Tab] key to accept the suggested code for your usage instead of coding from scratch - which is super awesome!


First, when I try def binary_search(, the Copilot will suggest two input parameters (i.e., arr and target) for my function based on the function name that I typed.

Secondly, when I move to the body of the function to write, as we can see from the video, Copilot will automatically suggest the entire binary search example code for us to use if we satisfied with the suggested code - which is working without any problem like a charm!








Second example: Bubble, Selection and Insertion Sort

Next, we try three basic sorting algorithm implementations with the help of Copilot in the following video. Based on the function name itself, the Copilot can automatically suggest relevant code snippet for the function when I change the function name from "bubble_sort" to "selection_sort" or "insertion_sort" - which again runs smoothly without any problem.



The first impression of the Copilot is absolutely will be very helpful for speeding up a lot of well-established functions, and the impact of it will be more clear in the next few years. It is also worth noting that the suggested code with AI technique is not perfect, and it is the programmer's responsibility to check, use, or refine it for their needs.

How does GitHub Copilot work? 


OpenAI Codex was trained on publicly available source code and natural language, so it understands both programming and human languages. The GitHub Copilot editor extension sends your comments and code to the GitHub Copilot service, which then uses OpenAI Codex to synthesize and suggest individual lines and whole functions.


Does GitHub Copilot write perfect code? 


No. GitHub Copilot tries to understand your intent and to generate the best code it can, but the code it suggests may not always work, or even make sense. While we are working hard to make GitHub Copilot better, code suggested by GitHub Copilot should be carefully tested, reviewed, and vetted, like any other code. As the developer, you are always in charge.


No comments:

Post a Comment