ChatGPTをMacのターミナル(黒い画面)で使用する方法

ChatGPTをターミナルで使用すると便利

ChatGPTは公式サイトのWebページから利用できますが、AIChatをターミナルでインストールしておけばターミナルからChatGPTを使用できるようになります。

IT企業でコードを書く人などはターミナルを常時開いている人が多いので、ちょっとした質問などであればターミナルから質問したほうが使いやすいです。

ChatGPTをMacのターミナル(黒い画面)で使用する方法

AIChatのインストール方法

Homebrewを使用するので入れていない場合は以下のコマンドでインストールしてください。

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

AIChatは以下のコマンドでインストールします。

brew install aichat

インストールしたら「aichat」と入力して実行すると、初回のみ設定用に色々聞かれるので、以下のように設定してください。

AIChat設定

No config file, create a new one?

設定ファイルがないので作成するか聞いているので「y (Yes)」を入力。

Openai API Key:

OpenAIのAPI Keyを聞いているのでAPI Keyを入力

※ API Keyがない場合はAPI keysのページからCreate new secret keyで作成してください。

Use proxy?

プロキシを設定するか聞いているので「n (No)」を入力。

Save chat messages

メッセージの履歴を保存するか聞いているので「y (Yes)」を入力。

これらの設定が完了すれば水色の>のあとに質問すればChatGPTの回答が表示されます。

ChatGPTをMacのターミナル(黒い画面)で使用する方法

AIChatで使用できる各種コマンド

.info

現在の設定情報が確認できる。

API Keyはconfig.yamlに保存されています。

〉.info
config_file         /Users/i/Library/Application Support/aichat/config.yaml
roles_file          /Users/i/Library/Application Support/aichat/roles.yaml
messages_file       /Users/i/Library/Application Support/aichat/messages.md
api_key             sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx
organization_id     -
model               gpt-3.5-turbo
temperature         -
save                true
highlight           true
proxy               -
conversation_first  false
light_theme         false
connect_timeout     10
dry_run             false

.set

.set <key> <value>で設定を変更できる。

例えばapi_keyを変更する場合は以下のコマンドを実行する。

〉.set api_key sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx

.model

.model <name> でモデルをgpt-3.5-turboなどに設定できる。

gpt-4にしたい場合は「.model gpt-4」を実行する

.prompt

プロンプトを利用して以下のように質問できる。

〉.prompt 池袋について教えて下さい

P〉アニメイトはありますか(10文字以内で回答)
はい。

.role

ChatGPTに役割を与える。

事前にroles.yamlに以下のような設定が必要。

- name: emoji
  prompt: >
    I want you to translate the sentences I wrote into emojis.
    I will write the sentence, and you will express it with emojis.
    I just want you to express it with emojis.
    I want you to reply only with emojis.
〉.role emoji
name: emoji
prompt: |
  I want you to translate the sentences I wrote into emojis. I will write the sentence, and you will express it with emojis. I just want you to express it with emojis. I want you to reply only with emojis.
temperature: null

emoji〉What is your favorite food?
🤔💭🍴🍕🌮🍔🍟🥗🍣🥘🍝🍰🍩🍦

.clear role

現在選択中のroleを削除する。

.conversation

会話形式の質問を開始する。

.clear conversation

会話形式の質問を終了する。

.history

履歴を確認します。

.clear history

履歴を削除します。

.help

ヘルプを見たい場合は「.help」を入力します。

〉.help
.info                    Print the information
.set                     Modify the configuration temporarily
.model                   Choose a model
.prompt                  Add a GPT prompt
.role                    Select a role
.clear role              Clear the currently selected role
.conversation            Start a conversation.
.clear conversation      End current conversation.
.history                 Print the history
.clear history           Clear the history
.help                    Print this help message
.exit                    Exit the REP

.exit

AIChatを終了する。

再開する場合は「aichat」を実行します。

ariasにaを設定すると便利

aichatを多用する場合はaichatを毎回入力するのは手間なので、多用する場合は .bashrc (.zshrc) のariasに「a」を登録しておくと便利です。

alias a='aichat'
カテゴリーAI