Alternative Architecture DOJO

オルターブースのクラウドネイティブ特化型ブログです。

GitHub Copilot in the CLI は日本語も解釈してくれて便利そう

こんにちは、MLBお兄さんこと松村です。
今年の MLB はテキサス・レンジャーズのワールドシリーズ制覇で幕を閉じました。
これからはストーブリーグが始まり、選手の移籍市場が活発になってきます。我がヤンキースはどんな戦力補強を見せてくれるのでしょうか!


この記事を書いている11月9日はアメリカ・サンフランシスコで GitHub Universe 2023 が行われています。
当社からも5人が現地で参加をしており、楽しそうな写真が社内にシェアされています。

さて、キーノートでは触れられませんでしたが、このたび「GitHub Copilot in the CLI」がパブリックベータとして発表されました。
これは GitHub CLI のなかで Copilot による支援を受けることができる拡張機能です。

以前は「Copilot for CLI」と呼ばれていましたが、「GitHub Copilot in the CLI」へと名前が変わりました。
「Copilot for CLI」の頃から Waitlist に登録していましたが、結局アクティベーションされることなく今日を迎え、「GitHub Copilot in the CLI」が利用できるようになっていました。

試してみた

ということで、早速 GitHub Copilot in the CLI を使ってみました。
結論としては日本語も解釈してくれるので、使い勝手が良さそうだなと思いました。

GitHub Copilot in the CLI のドキュメントはこちらです。

docs.github.com

インストール

GitHub Copilot in the CLI は GitHub CLI の拡張機能なので、GitHub CLI 自体のインストールが終わっている前提で説明します。
拡張機能としての Copilot のインストールを行います。

$ gh extension install github/gh-copilot
✓ Installed extension github/gh-copilot

あっさりです。これで CLI で Copilot が利用可能となります。

$ gh copilot -h
Your AI command line copilot.

Usage:
  copilot [command]

Examples:

$ gh copilot suggest "Install git"
$ gh copilot explain "traceroute github.com"


Available Commands:
  config      Configure options
  explain     Explain a command
  suggest     Suggest a command

Flags:
  -h, --help      help for copilot
  -v, --version   version for copilot

Use "copilot [command] --help" for more information about a command.

上記のヘルプにあるように、 GitHub Copilot in the CLI には大きく2つの機能があります。
(config は使用状況の分析データの送信に関する構成です)

  1. explain : コマンドを説明してもらう
  2. suggest : コマンドを提案してもらう

コマンドを説明してもらう

ドキュメントにもありますが、まずは sudo apt-get を説明してもらいます。
apt-get のあとに指定できるコマンドを説明してくれるので分かりやすいです。

$ gh copilot explain "sudo apt-get"

? Allow GitHub to collect optional usage data to help us improve? This data does not include your queries.
> Yes

Welcome to GitHub Copilot in the CLI!
version 0.5.2-beta (2023-11-07)

I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.

Explanation:

  sudo is a command used to run a command with elevated privileges, i.e. root-level access.

  apt-get is the Ubuntu package manager.

  • install is one of the sub-commands of the apt-get manager.
  • remove is also one of the sub-commands of the apt-get manager, which is used to remove packages.
  • update is also one of the sub-commands of the apt-get manager, which is used to update package lists.
  • upgrade is also one of the sub-commands of the apt-get manager, which is used to upgrade the installed packages.
  • dist-upgrade is also one of the sub-commands of the apt-get manager, which is used to perform a distribution upgrade.

  The pattern to use is "sudo apt-get "

ただし curl だけといったざっくりな指定ではダメなようです。

$ gh copilot explain "curl"

Welcome to GitHub Copilot in the CLI!
version 0.5.2-beta (2023-11-07)

I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.

Explanation:

  This is a partial command and there is not enough information to provide an explanation. Please provide the full
  command and I will be happy to help.

オプションまで含んだ状態のコマンドを説明してもらうのが良さそうです。

$ gh copilot explain "az account list"

Welcome to GitHub Copilot in the CLI!
version 0.5.2-beta (2023-11-07)

I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.

Explanation:

  az account list:

  • az - Azure command-line interface (CLI)
  • account - Sub-commands and actions related to Azure accounts
    • list - List the available Azure accounts.

コマンドを提案してもらう

続いては gh copilot suggest です。
これはやりたいことを伝えると、それを実行するためのコマンドを提案してくれる機能です。

例えば Git をインストールしたいけど、そのコマンドが分からない場合にコマンドを知ることができます。
提案されたコマンドをクリップボードにコピーしたり、コマンド自体を説明 (gh copilot explain) することもできて便利そうです。

$ gh copilot suggest "Install git"

Welcome to GitHub Copilot in the CLI!
version 0.5.2-beta (2023-11-07)

I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.

? What kind of command can I help you with?
> generic shell command

Suggestion:

  sudo apt-get install git

? Select an option  [Use arrows to move, type to filter]
  Copy command to clipboard
> Explain command
  Revise command
  Rate response
  Exit

? Select an option
> Explain command

Explanation:

  This is an invalid command. git: is not a valid package name in apt-get.

多少ふわっとした依頼でも大丈夫そうです。

$ gh copilot suggest "Install azure functions"

Welcome to GitHub Copilot in the CLI!
version 0.5.2-beta (2023-11-07)

I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.

? What kind of command can I help you with?
> generic shell command

Suggestion:

  npm install -g azure-functions-core-tools

逆に、ある程度具体的な内容でコマンドを組み上げてくれることもできました。
以下の例では「http://localhost:8000/api/example にHTTP POSTリクエストを送信したい」という内容です。

$ gh copilot suggest "Post http request to http://localhost:8000/api/example"

Welcome to GitHub Copilot in the CLI!
version 0.5.2-beta (2023-11-07)

I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.

? What kind of command can I help you with?
> generic shell command

Suggestion:

  curl --request POST http://localhost:8000/api/example

.NET 8 SDKをインストールしたいという依頼はダメでした。
実際にはインストールできる方法はあるので、今後の改善に期待ですね。

$ gh copilot suggest "Install .NET 8 SDK"

Welcome to GitHub Copilot in the CLI!
version 0.5.2-beta (2023-11-07)

I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.

? What kind of command can I help you with?
> generic shell command

Suggestion:

  sudo apt-get install dotnet-sdk-3.1

では最後に 提案してほしいコマンドを日本語で依頼する とどうでしょうか。

$ gh copilot suggest -t shell "http://localhost:8000/api/example にHTTPリクエストを送信し、レスポンスボディを整形する。
"

Welcome to GitHub Copilot in the CLI!
version 0.5.2-beta (2023-11-07)

I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve.

Suggestion:

  curl http://localhost:8000/api/example | jq '.'

いい感じですね!
そのまま使える場合もあれば、ちょっと手直ししたほうがいい場合もありますが、そもそもコマンドが分からない場合の取っ掛かりとしては十分だと思います。

明日の GitHub Universe Day2 ではどんな発表があるのか楽しみですね。


サービス一覧

www.alterbooth.com

cloudpointer.tech

www.alterbooth.com