0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ChatGPTがあればプログラミンを勉強する必要は無くなるのか?

Posted at

ChatGPTを利用してスクリプトを生成する場合は次の2点に注意する

  1. 生成されたスクリプトは必ずとも正しく動作しないため、必ずチェックする
  2. 生成されたスクリプトは必ずとも効率的ではない。良いスクリプトを生成させるためには誘導させる必要がある

例:
次の質問をした。

結果として次のスクリプトが生成されました。

az advisor recommendation list --category Security --impact High --query '[].{description:description, potentialBenefits:potentialBenefits}' -o json

このスクリプトを実行するとaz : ERROR: unrecognized arguments: --impact Highになります。これをChatGPTに問うと次のようなスクリプトが返されました。

recommendations=$(az advisor recommendation list -o json)

# ImpactがHighかつCategoryがSecurityのレコメンデーションのDescriptionとPotential benefitsの値を抽出
filtered_recommendations=$(echo $recommendations | jq '.[] | select(.impact == "High" and .category == "Security") | {description: .description, potentialBenefits: .potentialBenefits}')

# 結果の表示
echo $filtered_recommendations

このスクリプトを実行してもエラーになります。またなぜかChatGPTはConvertFrom-Jsonではなく、jqを使う傾向があります。そのためにjqをインストールする必要があります。

最終的にはConvertFrom-Jsonを使うように指示した後にdescriptio及びpotentialBenefitsはないためshortDescriptionを使うように指示し、shortDescriptionはproblemとsolutionのハッシュのためにproblemの値だけを取得するように指示したらやっとのことで次のようなスクリプトが生成されました。

$recommendations = az advisor recommendation list --output json | ConvertFrom-Json
#$recommendations
# ImpactがHighかつCategoryがSecurityのレコメンデーションのDescriptionとPotential benefitsの値を抽出
$filtered_recommendations = $recommendations | Where-Object { $_.impact -eq 'High' -and $_.category -eq 'Security' } | Select-Object -ExpandProperty shortDescription | Select-Object -ExpandProperty problem

# 結果の表示
$filtered_recommendations

このようにChatGPTでスクリプトを生成する場合は、何時も完璧なコードが生成されるのではなく、誘導する必要がある場合もあります。そのためにまだプログラミングの知識がある方が効率よくChatGPTを利用することができます。

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?