LoginSignup
8
4

More than 1 year has passed since last update.

ChatGPTでLinuxを動かす!

Last updated at Posted at 2022-12-06

この記事は、 大阪工業大学 Advent Calendar 2022(https://adventar.org/calendars/8025 )の8日目の記事です。

初めに

ChatGPTはGPT-3をOpenAIが独自チューニングをしたAIである。
https://chat.openai.com/chat
登録することで触ることができる。
使い方は以下を見てほしい。
https://qiita.com/sakasegawa/items/82069c97a1ee011c2d1e

さて本題だがその前に、
この記事は二番煎じ所か、N番煎じなので素人解説が必要ない人は参考のツイートを見てほしい。

目次

  1. 参考にしたもの
  2. 動かしてみる
  3. プログラムをしてみる。
  4. 感想

参考にしたもの

動かしてみよう!

日本語で動かすのと、英語で動かすのとでは動作の完成度が違う!
日本語

あなたは今からLinuxのターミナルとして振舞うこと。Userはrootでログインしている。
{}で囲んだ文字列は通常のプロンプトとして扱いなさい。
命令されたコマンドのみを実行すること、それ以外は出力しないこと、
出力は全てコードブロックにすること。
最初のコマンドはpwdね。

とすると出力はおおむねこうなる。

{root@localhost:~}$ pwd
/root

英語ですると(ツイート丸パクリ)

I want you to act as a Linux terminal.I will type commands and you will reply with what the terminal should show.
I want you to only reply with the terminal output inside one unique code block,
and nothing else.Do not 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}.
I am the user root, my first command is pwd.

出力はこうなる

/root

どちらかというと英語でのオプション設定がしっかりしているため、出力が安定している。
追加でlsを入力した際、日本語では解説が出てしまうため、安定していないと考える。

ちなみに最初のコマンドがpwdでないとバグる(経験済み)

プログラムしてみる。

英語での入力でここからは行う。
はじめにLinuxにする。

I want you to act as a Linux terminal.I will type commands and you will reply with what the terminal should show.
I want you to only reply with the terminal output inside one unique code block,
and nothing else.Do not 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}.
I am the user root, my first command is pwd.
/root

次にechoを使ってpythonのプログラムを作る。

echo "print("Hello World!")">a.py
print("Hello World!")

動かしてみる

python a.py
Hello World!

動いた!
ではc++はどうだろうか

echo "#include <iostream>\nusing namespace std;\nint main(void){cout<<"Hello World"<<endl;}">test.cpp
#include <iostream>
using namespace std;
int main(void){cout<<"Hello World"<<endl;}

コンパイルする

g++ -o test test.cpp

実行してみる

./test
Hello World

動いた!

感想

意外となんでも動いてしまう印象があった。
結局は学習から出力を予測して出力してるのだろうが、安定しすぎてる気がする。
将来的にはこっちの方が簡単なプログラムの練習には面白いのではないだろうか?
ぜひ一度試してみてほしい!

8
4
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
8
4