AI-powered programming with Copilot

Author

Marie-Hélène Burle

Content from the webinar slides for easier browsing.

Coding in the age of generative AI

Codex

OpenAI Codex—based on GPT-3—is the model behind GitHub Copilot.

All the big corporate companies are rushing to launch a growing number of similar (and not free, not open source) productivity products (e.g. tabnine, Microsoft Visual Studio IntelliCode, Amazon CodeWhisperer).

These products generate code in a narrow context (auto-completion or transformation of natural language to code or vise-versa).

AlphaCode 2

Google DeepMind AlphaCode 2—based on Gemini—stands out as a totally different (and for now totally unavailable) product generating code at the level of competitive programming (reaching the 85th percentile).

Think of it as code evolution by “natural” selection:

  • a very large number of code samples are generated (think “mutations”),
  • a filtering and scoring system selects for the best candidates (that’s the selection part).

AlphaCode 2 is able to solve much more open-ended problems.

What about FOSS?

Free

These models are large and most convenient to run on servers.

 → Price of cloud service.

Some self-hosted options exist. A very promising one is Tabby. Not practical for everyone.

Open source

While these models feed from open source code, they are themselves not open source 🙁

The open source community is trying to provide open source alternatives (e.g. Tabby). Despite the much more limited resources, the performance of some of these alternatives is very good.

GitHub Copilot

(not free, not open source…)

What is GitHub Copilot?

 → Cloud-hosted AI programming assistant.

Developed by GitHub (Microsoft).

Running Codex, a model by OpenAI derived from the LLM GPT-3 and trained on open source code.

Access

Individual or organization GitHub accounts.

Requires subscription.

Students, teachers, and maintainers of popular open source projects can apply for free access.

Safety

Filters are in place for offensive words, but…

Generated code comes with no guaranty of safety or quality.

A lawsuit is open against GitHub Copilot for licenses violation.

Supported languages

Any language used in public repos.

Quality of suggestions is higher for languages with lots of data.

How to use it?

Start typing code and get autocomplete suggestions.

Write comments describing what the code should do and get code generation based on context.

It is easy to:

  → accept suggestions word by word
  → line by line
  → for entire functions
  → cycle through different suggestions

Interface

Extensions to text editors:

  → Visual Studio Code/Visual Studio
  → Vim/Neovim/Emacs
  → JetBrains IDEs
  → Azure Data Studio

Setup

Get a subscription

Go to your GitHub account page:
  → Settings
  → Copilot
  → Enable

Provide free access or payment method.

Set settings.

VS Code

Install the GitHub Copilot extension.

Alt+]       Next suggestion
Alt+[       Previous suggestion

Esc         Reject suggestion
Tab         Accept suggestion
Ctrl+→      Accept next suggested word

Ctrl+Enter  Open new tab with options

Set your own key binding for editor.action.inlineSuggest.acceptNextLine to accept next suggested line.

You can also hover over suggestions.

Vim/Neovim

Install Node.js.

Clone https://github.com/github/copilot.vim.

Configure:

:Copilot setup

Enable:

:Copilot enable

Get help:

:help copilot

Emacs

Install Node.js.

Assuming straight is installed:

(straight-use-package 'editorconfig)                   ; Copilot dependency

(use-package copilot
    :straight (:host github
                     :repo "copilot-emacs/copilot.el"
                     :files ("dist" "*.el"))
    :hook (prog-mode . copilot-mode)                   ; Settings up to you
    :bind (("C-8" . copilot-complete)
           :map copilot-completion-map
           ("C-j" . copilot-accept-completion)
           ("C-f" . copilot-accept-completion-by-word)
           ("C-t" . copilot-accept-completion-by-line)
           ("C-n" . copilot-next-completion)
           ("C-p" . copilot-previous-completion)))

Login to your GitHub account (only needs to be done once): M-x copilot-login.

Copilot in the CLI

What is Copilot in the CLI?

In beta.

An extension to GitHub CLI (GitHub operations from the CLI).

 → Generate commands from natural language.
 → Generate natural language explanations from commands.

Trained on data up to 2021.

Lower performance for natural languages ≠ English.

Be very careful: the command line is powerful and you can delete your data or mess up your system if you don’t know what you are doing. Check commands carefully!

Setup

Install GitHub CLI.

Connect to your GitHub account:

gh auth login

Install Copilot in the CLI:

gh extension install github/gh-copilot

Update with: gh extension upgrade gh-copilot.

Usage

Get code explanations:

gh copilot explain

Get code from natural language:

gh copilot suggest

Resources