目录
Github Copilot的申请及在Pycharm的配置和使用
目前Github Copilot不是完全公开的,需要自己进入copilot官方网站进行申请,我申请下来是花了两天左右的时间。
1.简介
微软与OpenAI共同推出了一款AI编程工具GitHub Copilot。
GitHub Copilot基于 GitHub 及其他网站的源代码,可根据上文提示为程序员自动编写下文代码。
我使用下来它最实用的功能并不是说它的智能输入代码,而是它能够结合你实际业务代码的上下文进行预测你下一步的代码,会根据你的代码格式代码规范进行编写。
从个人的角度来讲,它带给我们的是更加便捷轻巧,当然,不能完全把它当作一个偷懒的工具,在一些灵活性逻辑比较复杂的一些功能上还需要我们自己验证,否则之后编译出错,你自己都找不到在哪里出问题。
2.copilot首页
https://copilot.github.com/
点击sign up 使用自己的github账户

3.copilot的申请
  
4.GitHub Copilot 官方使用文档
https://github.com/github/copilot-docs
5.PyChram下载地址
为什么会有这一步?
官方文档给出的说明:
- We have tested with the following JetBrains IDEs: IntelliJ and PyCharm versions 2021.2 and above.
意思是 经过他们的测试, JetBrains系列的 IntelliJ 和 PyCharm 这两款编译器需要使用2021.2及以上的版本
https://www.jetbrains.com/pycharm/download/other.html

6.Pychram下载 GitHub Copilot
在pycharm中的Plugins中搜索GitHub Copilot点击Install进行下载(下载完别忘记了点击Apply哦)

7.jetbrains系列官方教程
https://github.com/github/copilot-docs/blob/main/docs/jetbrains/gettingstarted.md#getting-started-with-github-copilot-in-jetbrains
8.申请通过之后的操作
等了两天,发邮件通知我通过了

既然通过了,我们可以在Tools – > GitHub Copilot中进行登录自己的Github账号进行验证 

点击Join the Waitlist  
9.使用过程
如下为我的使用过程
写注释,然后回车就会发现它会给门智能建议代码,我们只需要按下Tab键,就会选择这个建议,然后会有新的建议代码出现,符合你的需求就继续按Tab键,比如我们按下四次Tab键后得到如下结果  
除了以上的这些功能,你还可以在自己的业务代码里面尝试写一个新的方法,它会很智能的给出相关建议(需要自己确认一遍是否有误)
Github Copilot自动生成的代码
def is_huiwen(num):
str_num = str(num)
if str_num == str_num[::-1]:
return True
else:
return False
def maopao(list_num):
for i in range(len(list_num)):
for j in range(len(list_num)-i-1):
if list_num[j] > list_num[j+1]:
list_num[j],list_num[j+1] = list_num[j+1],list_num[j]
return list_num
def quick_sort(list_num):
if len(list_num) <= 1:
return list_num
else:
base = list_num[0]
left = [x for x in list_num[1:] if x < base]
right = [x for x in list_num[1:] if x >= base]
return quick_sort(left) + [base] + quick_sort(right)
10.相关功能键:
Tab 选择提供的建议Esc 拒绝提供的建议Alt +] 查看下一个建议;Alt +[ 查看上一个建议。(macos把Alt 键换成option 键即可)Alt + \ 把提供的建议注释掉。(macos把Alt 键换成option 键即可)Alt +Enter 显示当前所有的建议。(macos把Alt 键换成option 键即可)
11.退出Github Copilot
Tools – > GitHub Copilot – > Logout
|