Click here for more information
summary
GitHub Copilot is an AI twinning programmer that helps you write code faster and with less effort.GitHub Copilot is powered by generative AI models developed by GitHub, OpenAI, and Microsoft. It is available as an extension to the Visual Studio Code, Visual Studio, Neovim, and JetBrains integrated development environment (IDE) suites.
How to use
environmental preparation
- Scientific Internet access: A network environment with smooth access to the GitHub website.
- IDE: Supports integrated development environments such as JetBrains IDEs, Visual Studio, and more.
Environment Installation
1. Go to the official website GitHub-Copilot registration information.
2. GitHub-Copilot costs $10 a month, and you need to fill out your credit card information first, but you can try it for free for 30 days, so you can cancel the renewal before the 30 days are up.
3. Fill in the credit card information accurately and click Submit to finish.
4. Open the IDE, take Pycharm as an example, open Settings -> Plugins -> Marketplace, search for GitHub Copilot, click Install and wait for the installation to complete and click Restart IDE.
5. After installing the plugin, log in Pycharm, click Tools -> GitHub Copilot -> Login to GitHub.
6. Click Copy and Open, click the verification code to paste it into the pop-up browser, click Continue and then click Authorize Authorize GitHub Copilot Plugin.
7. Wait for Pycharm to load and then you can use GitHub Copilot.
hands-on exercise
Instructions for use
1. In the status bar at the bottom right of PyCharm, the red circle indicates the GitHub Copilot logo, which means that the GitHub Copilot plugin is enabled.
2. Whether you’re writing a comment in your code, or executing a line of code, or a block of code, or a function, GitHub Copilot will continue to provide code-completion suggestions as you type.
caveat
1. GitHub Copilot may also guess the wrong code you intend to write, but as long as you keep typing, it will give new suggestions.
2. For any given input, GitHub Copilot may provide multiple suggestions. You can choose which suggestions to use, or reject all of them, depending on your needs.
3. Users can enable or disable GitHub Copilot: Click the status icon in the status bar at the bottom right of PyCharm to select the suggestion to enable or disable GitHub Copilot.
Related Shortcuts
OS | View Next Suggestion | View previous suggestion | Receiving recommendations | Rejection of recommendations | Display Recommendations |
---|---|---|---|---|---|
macOS | command+] | command+[ | tab | esc | option+ |
Windows | Alt+] | Alt+[ | tab | esc | alt+ |
Linux | Alt+] | Alt+[ | tab | esc | alt+ |
Writing a Quick Sort with Copilot
-
Enter the relevant comment as well as the beginning.
2. It will automatically start to complete the code. The gray part is the code it suggests, click tab to receive its suggestions.
Merge two lists and sort them
1. Enter notes and requirements:
Merge two lists and sort them
2. According to the needs of the prompt, has been pressing the tab key, the middle will automatically generate comments as well as the realization of the code, all of the following code is automatically generated:
def merge_list(list1, list2):
# Merge two lists and sort them
# 1. Define two pointers to the first element of two lists.
p1 = 0
p2 = 0
# 2. Define a new list to store the results of the merge
result = []
# 3. Loop over the elements pointed to by the two pointers and add the smaller element to the new list
while p1 < len(list1) and p2 < len(list2):
if list1[p1] < list2[p2]:
result.append(list1[p1])
p1 += 1
else:
result.append(list2[p2])
p2 += 1
# 4. add elements from the uncompared list to the new list
result += list1[p1:]
result += list2[p2:]
# 5. Return to new list
return result
3. Write a unit test case to test whether it is realized, write a function nameddef test_merge_list():
, other than using auto-completion, the final unit test case generated results in:
def test_merge_list():
assert merge_list([1,2,5], [3,4,6]) == [1,2,3,4,5,6]
summarize
1. Copilot’s environment is very simple to install and use, you can think of it as a ChatGPT used in an IDE.
2. Some explicit code logic can be given to it to accomplish.
3. Not all outputs from Copilot are correct and need to be corrected appropriately during use.