
はじめに
こんにちは、ACS事業部の大久保です。 蒸し暑くて大変な時期ですが皆様いかがお過ごしでしょうか? 幣事業部でもCopilot 利用が盛んになってきており、久しぶりに筆を執りたいと思います。
テーマ
LLMやそれを利用したアプリケーションの普及が進む中、ChatGPTやGithub Copilotによるコードの生成を行う中で、 コメントを用いてAIに指示を渡すプロンプトエンジニアリングを行うことが基本な使い方であるのは知られているところになります。 ChatGPTとGithub Copilotはそれぞれ生成と補完で役割が違い、期待される反応は違うと思います。
そこで以下のコメントに対してそれぞれどのようなコードを生成するか検証することで、 二つの基本的な違いを確認したいと思います。
コメント
/**
* Cart class for special users, such as celebrities, politicians, etc.
* They pay double the price of the item for charity.
* it has a method to calculate the price of the item.
* you can develop something unique for this class.
*/
public class CartForCelebrities extends Cart {
このコメントはJavaのCartクラスを継承したセレブ向けのカートクラスを定義してます。
コメントで以下の指示を投げているので、それぞれがどう反応するかを見たいと思います。
指示:
- セレブなので2倍のお値段。
- 何かユニークな機能を開発してよい(検証ポイント)
期待すること
検証ポイントは曖昧な指示への反応になります。 生成と補完に対する私としての期待値は以下になります。
| 名前 | 期待 |
|---|---|
| GPT-4 | 検証ポイントを読み取りコードを記述すること。 |
| Copilot | 検証ポイントを無視しコードを補完しないこと。 |
ChatGPT(GPT-4)
結果
検証ポイントを読み取りちょっとしたメッセージを入れてくれました。 また、全体的にコメントに対して理由を入れております。
生成コード
/**
* Cart class for special users, such as celebrities, politicians, etc.
* They pay double the price of the item for charity.
* it has a method to calculate the price of the item.
* you can develop something unique for this class.
*/
public class CartForCelebrities extends Cart {
/**
* Method to calculate the price for celebrities.
* It calculates the price of the item and multiplies it by 2 as celebrities have to pay double the amount.
*
* @param item Item object which represents the item to purchase.
* @return double It returns the final price for purchase.
*/
@Override
public double calculatePrice(Item item) {
// getting base price of the item
double basePrice = super.calculatePrice(item);
// celebrities pay double the base price
return basePrice * 2;
}
/**
* Method to show a thank you message for celebrities after purchasing.
* It is unique for celebrities as it also mentions charity.
*
*/
public void showThankYouMessage() {
System.out.println("Thank you for your purchase! Your contribution will be used for charity.");
}
}
画像

Copilot
結果
検証ポイントに対しては反応は示さず、コード補完を進めませんでした。 これならば何も考えずにtabキー連打ですることで、変なコードが出ることはないです。\ ツールとしての安心感を感じます。
生成コード
/**
* Cart class for special users, such as celebrities, politicians, etc.
* They pay double the price of the item for charity.
* it has a method to calculate the price of the item.
* you can develop something unique for this class.
*/
public class CartForCelebrities extends Cart {
/**
* This method calculates the price of the item.
* @param item
* @return
*/
@Override
public double calculatePrice(Item item) {
return item.getPrice() * 2;
}
/**
* This method calculates the total price of the items in the cart.
* @param items
* @return
*/
@Override
public double calculateTotalPrice(List<Item> items) {
double totalPrice = 0;
for (Item item : items) {
totalPrice += calculatePrice(item);
}
return totalPrice;
}
/
}
画像

まとめ
自分なりに、双方の使い分けは以下に整理いたしました。
GPT-4を使ったコード生成の利用
- 仕様からすぐに動くものを作りたい。
- 仕様からわからない実装を提案してほしい。
機能が見えている中で実装面で不確実性が多い局面で使う。 PoCやプロトタイピング、調査。
Copilotを使ったコード生成
- コーディング速度を高める
- より良い実装を提案する
- ロジック(詳細設計や疑似コードレベル)を基に提案する
開発フェーズでロジックが見えている状態での生産性を高める。 ドキュメンテーションがしっかりしているSierにも実は向いているのではないかと思います。
おわり
ACS事業部のご紹介
私達ACS事業部はAzure・AKSなどのクラウドネイティブ技術を活用した内製化のご支援をしております。
また、一緒に働いていただける仲間も募集中です!
今年もまだまだ組織規模拡大中なので、ご興味持っていただけましたらぜひお声がけください。