GitHub Copilot Labs’ Prompt Engineering

What?

GitHub Copilot Labs is hidden behind invitation as of writing.

Took some pain to reverse engineer almost all prompts from GitHub Copilot Labs to peek into their prompt engineering. However their plugin seems to ignore global proxy settings: the author dived into codebase to extract the following information.

Prompts

The author believed that those new features were implemented within the same codex model used for code completion.

${e} is the piece of code to be analyzed. The prompt looks like:

START_CODE
{the piece of code to be analyzed}
END_CODE

{prompt}

START_CODE

Readability

Make this code easier to read, including by adding comments, renaming variables, and/or reorganizing the code.

Add Types

Add types to this code:

Fix Bug

There's a bug in this code. Here is how it looks with the bug fixed:

Debug

This code could be debugged more easily and we can add some log statements, which would look like:

Clean

Remove unnecessary code, like log statements and unused variables. Leave the rest of the code the same.

List Steps

Add more detailed comments to this code to describe each step:

Robust

Make this code more robust, covering more edge cases and handling errors:

Chunk

This code could be chunked into smaller functions, which would look like:

Document

Write a comment describing what this code does, as well as any other information you think is relevant. Include any function names, variable names, or other identifiers that you think are important. You can also include any other information that you think is relevant, such as the purpose of the code, the context in which it is used, or any other information that you think is relevant.

(Why so long?)

Translate (into another coding language)

  • ${t}: Source language
  • ${n}: Target language
  • ${a}: Source code
  • ${i}: Prompt, randomly selected from the following 4 possiblities:
    • Translate the following code from ${t} to ${n}.
    • Convert the following multi-line code from ${t} to ${n}.
    • Translate the following multi-line code from ${t} to ${n}.
    • Transform the following multi-line code from ${t} to ${n}.

The author is not sure what ${s} stands for.

${s} ${i}
${s} Language: ${t}
${s} START_OF_CODE
${a}
${s} END_OF_CODE
${s} Language: ${n}
${s} START_OF_CODE

Hidden Prompts

The author also found some prompts not visible from UI:

Generalize

Make this code more generalizable:

Robustify

Make this code more robust:

(This seems to be the older version of "Robust" prompt)

Refactor

Prompt format is different for this one:

{source code}

Refactor this code

Style

This code could be styled more elegantly, which would look like:

Security

There's a security vulnerability in this code. How would you fix it?

Condense

More concisely, this code would look like:

Improve Perf

This code could be more performant, which would look like:

Reference

code.kiwi.com/articles/cautiously-configuring-copilot/

Leave a Reply

Your email address will not be published. Required fields are marked *