43
GitHub Copilot - Everything you need to know
Let's talk about a very exciting product that was recently launched by GitHub, which is called GitHub Copilot.
GitHub Copilot is your new AI Pair programmer, powered by OpenAI. It helps you to write utilify functions, tests, and explore new API(s) without having to lookup for answers on internet. It generates or autocomplete code for you.
It's currently not available publicly, so if you want to use it, you've to join the waiting list by visiting GitHub Copilot and head over to Sign up page.
After installation and authenticating it with your GitHub, you'll see Copilot icon in Visual Studio Code at bottom right.
You can enable/disable Copilot by tapping this icon.
Let's start with some simple and basic utilify functions.
Suppose, I want to have a function which accepts a number as an argument and returns the double of it, here's how Copilot helps me.
When Copilot gives you a suggestion and you hover the mouse on last character, it gives you options to navigate between Next and Previous , Accept current suggestion or Open Copilot which shows list of all the suggestions available.
These were some simple utility functions, maybe we should give a try to use Node.js default modules, such as fs
.
Depending on the what function name you use, Copilot gives different suggestions.
Okay, enough of simple examples, let's quickly build a simple CLI based application that fetch user GitHub details (api.github.com/users...
)
CLI Applications start with a shebang which syntax I always forget, but now no more (Yes, Copilot also works for comments
Now let's start using copilot. The very first thing is to extract username from arguments as the user will be passing it dynamically
./cli.js khattakdev
Here khattakdev
is a GitHub Handle
and here's the code for making an API call, since axios
is imported, so copilot suggests an axios call
Copilot is an awesome tool that works for creating utility functions, writing test cases, and exploring new API(s). It also works for comments and it gives you multiple suggestions.
43