使用gpt-2_用GPT-3替换我的git备忘单

使用gpt-2

There are some basic skills that are easy if you learn when you are young but can be baffling if you have to master them later in life. For example, driving a car with a manual transmission can seem to be perversely difficult to somebody who learned to drive on an automatic. However, the challenge of “driving stick” pales in comparison to mastering the git command line interface if you didn’t grow up with git. In this article I’ll describe how I harnessed OpenAI’s GPT-3 to generate git commands from English language descriptions.

如果您年轻时学习一些简单的技能,但是如果您在以后的生活中必须掌握这些基本技能,可能会感到困惑。 例如,对于那些学会了自动驾驶的人来说,驾驶手动变速箱似乎很困难。 但是,如果您不熟悉git,那么与精通git命令行界面相比,“驾驶杆”的挑战显得苍白无力。 在本文中,我将介绍如何利用OpenAI的GPT-3从英语描述中生成git命令。

git的优点(不是很好) (What’s great (and not so great) about git)

Git is a foundational technology and a brilliant contribution to modern software development. It also has a set of commands which can seem to be purposely haphazard and inconsistent.

Git是一项基础技术,对现代软件开发做出了杰出的贡献。 它也有一组命令,这些命令看起来似乎是偶然的并且是不一致的。

“With all that there is to like about Git, I have always been so frustrated at the lack of clarity in the command-lines for doing anything beyond the simplest action. Heck, even the simplest actions are harder than they need to be.” from Why the heck is git so hard by Daniel Eklund.

“尽管有很多关于Git的信息,但令我感到沮丧的是,命令行中对于执行除最简单的操作之外的任何操作都不够清晰。 哎呀,即使最简单的动作也比他们所需要的难。 见鬼,为什么是Git的这么辛苦 丹尼尔Eklund的。

I came to git late in life. I had used a variety of code control / versioning systems in my career at IBM, including the venerable CMVC and Clearcase, which was reasonably accessible but still esoteric in the manner of IBM software from that era. Neither of these systems prepared me at all for the wonderful world of git.

我来晚了git。 在IBM的职业生涯中,我曾使用过各种代码控制/版本控制系统,包括古老的CMVC和Clearcase,它们相当容易使用,但仍然与那个时代的IBM软件一样深奥。 这些系统都没有为git的美好世界做任何准备。

Faced with the challenge of git syntax, I did what any self-respecting software developer in the 21st century would do. I saved my most common git commands in a Word document, along with a description of what the commands did. When I needed to repeat a particular git incantation I could look in this Word document to see if I had done it before and try to figure out the syntax. Sounds awesome, right? Unfortunately, I now had the problem of keeping this document in sync between my personal and work environments, and as it got bigger I ran the risk of losing track of the more basic git commands.

面对git语法的挑战,我做了21世纪任何自重的软件开发人员都会做的事情。 我将最常用的git命令以及命令功能的说明保存在Word文档中。 当我需要重复特定的git咒语时,我可以查看此Word文档,看看我以前是否做过,并尝试弄清楚语法。 听起来很棒,对吗? 不幸的是,我现在遇到了使该文档在我的个人和工作环境之间保持同步的问题,并且随着文档的增大,我冒着无法追踪更基本的git命令的风险。

If only there were some way to replace my git cheat sheet with an intelligent assistant that could translate my English language descriptions into git commands…

如果只有某种方法可以用智能助手替换我的git备忘单,它可以将我的英语描述转换成git命令…

GPT-3和git:天堂般的婚姻 (GPT-3 and git: a marriage made in heaven)

I was literally fiddling around with my stupid git cheat sheet while I was experimenting (unsuccessfully) with using GPT-3 to convert simple COBOL functions into Python. I still think that’s a good idea, but I have forgotten too much COBOL to come up with decent examples. So, if COBOL to Python isn’t a good use case for GPT-3, what is? If only there were a practical problem that I had to solve with English as the input and some commands as output…

当我尝试(未成功)使用GPT-3将简单的COBOL函数转换为Python时,我实际上是在摆弄愚蠢的git备忘单。 我仍然认为这是一个好主意,但是我忘记了太多COBOL来提出不错的示例。 那么,如果COBOL to Python不是GPT-3的好用例,那是什么? 如果只有我必须解决的实际问题,以英语为输入,而一些命令为输出...

The answer was staring me in the face — use GPT-3 to translate English descriptions into git commands.

答案直面我-使用GPT-3将英语描述翻译成git命令。

git assistant —一个简单的Python程序,可从英文描述中获取git命令 (git assistant — a simple Python program to get git commands from English descriptions)

I wrote a simple Python program, git assistant, to get GPT-3 to provide the git commands corresponding with English language descriptions of what I want git to do. The program consists of a loop that prompts the user for input, calls the GPT-3 API with the input, and returns GPT-3’s prediction of the corresponding git command:

我编写了一个简单的Python程序git assistant ,以获取GPT-3来提供与我要git进行的英语描述相对应的git命令。 该程序包括一个循环,该循环提示用户输入,使用输入调用GPT-3 API,并返回GPT-3对相应git命令的预测:

Image for post
GPT-3 gets an English description and returns a git command
GPT-3获得英文说明并返回git命令

To prime the pump, I provided GPT-3 with a small set of examples of English text descriptions and the corresponding git command:

为了给泵加注水,我为GPT-3提供了一小组英文说明示例和相应的git命令:

gpt.add_example(Example('initialize a git repository', 'git init'))
gpt.add_example(Example('add file foo to the staging area for git', 'git add foo'))
gpt.add_example(Example('add all files in the current directory to the staging area for git', 'git add .'))
gpt.add_example(Example('record the changes made to the files to a local repository', 'git commit -m "commit message"'))
gpt.add_example(Example('return the current state of the repository', 'git status'))
gpt.add_example(Example('Clone the remote repository https://github.com/ryanmark1867/webview_rasa_example','git clone https://github.com/ryanmark1867/webview_rasa_example'))
gpt.add_example(Example('remove file foo from the staging area', 'git rm -f foo'))
gpt.add_example(Example('show the chronological commit history for a repository', 'git log'))

Here’s an example of a session running git assistant. GPT-3’s responses are listed after “output:”

这是一个运行git Assistant的会话的示例。 GPT-3的回应列在“输出:”之后

Image for post
Session with the git assistant
与git助手的会话

The results are not perfect. For example, the response to “merge changes into the current branch” is repeated 3 times. That being said, git assistant is good enough that I can retire my git cheat sheet.

结果并不完美。 例如,对“将更改合并到当前分支中”的响应重复3次。 话虽如此,git Assistant足够好,我可以退休我的git备忘单。

结论 (Conclusions)

Git is an example of a very widely used application that has somewhat arcane syntax. I’ve shown in this article that with a few hints, GPT-3 can do a decent job of generating git commands from English language descriptions. I am now using this simple git assistant to remind me of git syntax and save me from having to refer to a static cheat sheet of git commands.

Git是一个应用非常广泛的示例,其语法有些神秘。 我已经在本文中显示了一些提示,GPT-3可以很好地根据英语描述生成git命令。 我现在正在使用这个简单的git助手来提醒我git语法,并使我不必引用git命令的静态备忘单。

You can find the code described in this article in this repo:

您可以在此仓库中找到本文描述的代码:

翻译自: https://towardsdatascience.com/replacing-my-git-cheat-sheet-with-gpt-3-69223e58626f

使用gpt-2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值