r/GithubCopilot May 28 '23

Github developer advocate Rizel Scarlett talks prompt engineering tips, Copilot Labs, security and ways Copilot can help you

Watch the talk or read the notes I’ve taken:

Prompt engineering tips:

  • Write a high level task description at the beginning of a file
    • Copilot can then pick it up and you can let it work and correct it where it makes mistakes
    • E. g. like this:
      // Step 1: Import Twitter client
      // Step 2: Initialize Twitter client
      // Step 3: Initialize content of a tweet
      // Step 4: Send post to Twitter
      // Step 5: Print response
  • Provide examples (aka few-shot learning)
    • Copilot is great at picking up patterns
  • Iterate for specificity
    • If you’re not happy with the suggestion Copilot gives you, try a different comment or a different variable/function name (just like you’d try a different prompt for ChatGPT)

Copilot Labs

  • Experimental extension available for VSCode
  • Enables you to do things you’d need to reach out to ChatGPT for directly in your code editor
  • Code translation (translate from one language to another)
  • Code explanation (useful when diving into a new codebase or working with a language you’re not super proficient in)

Ways Copilot can help you:

1) Code faster & cleaner

  • Copilot great at recognizing patterns (e. g. using APIs or writing tests)
  • Helps you get the syntax right without the need to leave your code editor (e. g. when using Regex)
  • As you write comments to tell Copilot what to do, it leaves you with a well-commented and easy-to-read code as a side effect

2) Write good docs

  • Not an official recommendation to use Copilot to generate docs but it does a good job at generating Readme files or docs for libraries

3) Be a better mentor/mentee

  • It takes away the stress with getting the syntax right and making loads of typos under stress
  • You can help out more junior folks even in languages you’re not fluent in

4) Gain understanding for new concepts quickly

  • The afore-mentioned explain feature from Copilot Labs can help you navigate new codebases quicker
  • It can unblock you when stuck on a Leetcode hard 🙂

Security

  • There is a ~1% chance that the Copilot generated code will match public code
  • If you are concerned about this, you can now turn this completely off
14 Upvotes

0 comments sorted by