Linuxになってもらう [ChatGPTの裏ワザ]
本記事はChatGPTの中にLinux仮想環境を作る方法を参考に作成しています.今回はOpenAIが提供するChatGPT-4でトライしています.
https://www.engraved.blog/building-a-virtual-machine-inside/
ChatGPTにLinuxになってもらう方法はいたってシンプルで,下記のテキストをプロンプトとして与えるだけでよい.
I want you to act as a Linux Terminal. I will type commands and you will reply with that the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do no write explanations. Do not type commands unless I instruct you to do so. When I need to tell you something in English I will do so by putting text inside curly brackets {like this}. My first command is pwd.
すると以下のように,Linuxでpwdコマンドを打った時のように現在の位置が表示される.
![](https://i0.wp.com/vasteelab.com/wp-content/uploads/2023/03/image.png?resize=781%2C301&ssl=1)
さらに,現在誰がログインしているかを表示するwhoを打つと・・・
![](https://i0.wp.com/vasteelab.com/wp-content/uploads/2023/03/image-1.png?resize=782%2C198&ssl=1)
きっちり今日の日付でログイン情報が表示される.
GPUの存在を確認するために,nvidia-smiを打ってみると・・・
![](https://i0.wp.com/vasteelab.com/wp-content/uploads/2023/03/image-2.png?resize=781%2C460&ssl=1)
この仮想環境にはGPUが1枚刺さっていることが確認できた.
さらにダメもとでpythonと打ってみる.
![](https://i0.wp.com/vasteelab.com/wp-content/uploads/2023/03/image-3.png?resize=779%2C263&ssl=1)
この環境ではpython 3.8.10が動かせるようだ.
しかもnumpyをインポートできて,行列の足し算とべき乗も正しく行うことができた.
![](https://i0.wp.com/vasteelab.com/wp-content/uploads/2023/03/image-4.png?resize=439%2C1024&ssl=1)
Forループもお手の物で,大文字にする処理を間に挟むこともできた.
![](https://i0.wp.com/vasteelab.com/wp-content/uploads/2023/03/image-5.png?resize=783%2C864&ssl=1)
さらに,インポートしていないライブラリを使おうとすると・・・
![](https://i0.wp.com/vasteelab.com/wp-content/uploads/2023/03/image-7.png?resize=789%2C265&ssl=1)
インポートするように怒られ,re.seachの引数の順番が違うと,きちんとエラーになり,正しい順番まで丁寧に教えてくれる.これは通常のIDEの一歩先を行っているのではないか・・・
修正すると,正規表現を用いた文字照合が行えることが確認できた.
![](https://i0.wp.com/vasteelab.com/wp-content/uploads/2023/03/image-8.png?resize=780%2C378&ssl=1)
さすがにkerasを使ってMNISTで学習をするコードまでは動かせないようだった.これもプロンプトを工夫するとできるようになるのか・・・?
![](https://i0.wp.com/vasteelab.com/wp-content/uploads/2023/03/image-9.png?resize=725%2C1024&ssl=1)
ディスカッション
コメント一覧
まだ、コメントがありません