LoginSignup
0
0

MacでOpen-interpreterのインストールとR言語の実行について: Macターミナル上でLLMを動かしてみよう

Posted at

この記事の音声読み上げ

VOICEVOX:冥鳴ひまり

はじめに

Open Interpreterは、自然言語で指示を与えることでコードを書き、実行まで行ってくれるツールであり、これはローカル環境にインストールすることで利用可能となる、OpenAI社のCode Interpreter(Advanced Data Analysis)のオープンソース版と言えます。

例えば、Macのターミナル上でOpen Interpreterをインストールすることで、大規模言語モデル・Large Language Model (以下、LLM) を利用することができるようになります。

GPT-4を使用するには、OpenAIのAPIキーが必要ですが、Code Llamaというローカルで動作するコード生成モデルも無料で利用可能であり、ただし、インストールと適切な計算環境の設定が必要です。

今回は、macOSにOpen Interpreter(バージョン open-interpreter-0.1.6 & openai-0.28.1)をインストールし、その設定とターミナル上でのGPT-4の動作を確認した結果を報告します。

ターミナル上でのローカル実行は、多くの利点をもたらすかもしれません。。

プレインストールの設定

Open InterpreterはPythonのライブラリであるため、pipコマンドを使用してインストールを行います。

初めに、Pythonとpipのバージョンを確認しましたが、私の環境では、minicondaを使用してインストールされたPython 3.9.12とpip 21.2.4が利用されていました。しかし、これらのバージョンはOpen Interpreterとの相性が良くないことが判明しました。

こんな状況でした。

01.png

(このとき、バージョン確認で実行したコマンドは以下の通りです。)

# バージョン確認コマンド
which python
#/Users/sas/miniconda/bin/python

python -V
#Python 3.9.12

which pip
#/Users/sas/miniconda/bin/pip

pip -V
#pip 21.2.4 from /Users/sas/miniconda/lib/python3.9/site-packages/pip (python 3.9)

そのため、Pythonとpipの最新版をインストールし、私は/opt/homebrew/binにあるpip3.11を使用しました。

/opt/homebrew/bin/pip3.11 -V
#pip 23.2.1 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)

open-interpreterのインストールと設定

インストールはpipコマンドを使用し、open-interpreterを指定します。
私の環境ではパスが通っていないため、フルパスでpipコマンドを実行しました。

#インストール
/opt/homebrew/bin/pip3.11 install open-interpreter

#アップグレード時
/opt/homebrew/bin/pip3.11 install --upgrade open-interpreter

インストールが完了したら、ヘルプを表示して動作を確認します。

このバージョンでは、すでに、--versionの引数は廃止されているようです。

ヘルプ表示の実行結果は以下の通りです。

02.png

# ヘルプ表示
$ interpreter -h        

usage: interpreter [-h] [-s SYSTEM_MESSAGE] [-l] [-y] [-d] [-m MODEL]
                   [-t TEMPERATURE] [-c CONTEXT_WINDOW] [-x MAX_TOKENS]
                   [-b MAX_BUDGET] [-ab API_BASE] [-ak API_KEY] [--config]
                   [--conversations] [-f]

Open Interpreter

options:
  -h, --help            show this help message and exit
  -s SYSTEM_MESSAGE, --system_message SYSTEM_MESSAGE
                        prompt / custom instructions for the language model
  -l, --local           run in local mode
  -y, --auto_run        automatically run the interpreter
  -d, --debug_mode      run in debug mode
  -m MODEL, --model MODEL
                        model to use for the language model
  -t TEMPERATURE, --temperature TEMPERATURE
                        optional temperature setting for the language model
  -c CONTEXT_WINDOW, --context_window CONTEXT_WINDOW
                        optional context window size for the language model
  -x MAX_TOKENS, --max_tokens MAX_TOKENS
                        optional maximum number of tokens for the language
                        model
  -b MAX_BUDGET, --max_budget MAX_BUDGET
                        optionally set the max budget (in USD) for your llm
                        calls
  -ab API_BASE, --api_base API_BASE
                        optionally set the API base URL for your llm calls
                        (this will override environment variables)
  -ak API_KEY, --api_key API_KEY
                        optionally set the API key for your llm calls (this
                        will override environment variables)
  --config              open config.yaml file in text editor
  --conversations       list conversations to resume
  -f, --fast            (depracated) runs `interpreter --model gpt-3.5-turbo`

Open-interpreterの使用

続いて、実際に、Open-interpreterを使ってみます。

コマンドはinterpreterで、その基本的な使用方法として、-y-m [モデル名]--api_key [OpenAI APIキー]を引数として指定して使います。

# 基本コマンド
interpreter -y -m [モデル名] --api_key [APIキー]

しかし、どうも困ったことに、GPT-4のモデルが正しく指定されないようです。

これはバグかどうか不明ですが、将来のアップデートで修正されることを期待しています。

03.png

使用したAIモデルに質問したら、彼はGPT-3.5のようです。

日本語と英語の両方で実行が可能であることが確認されましたが、GPT-3.5なら、英語で使うのが無難ですね。

続いて、実行例として、以下のプロンプトを実行しました。

日本語プロンプト: 
R言語で主成分分析のコードを示してください。Rコードも示してください。  

下図がプロンプトの実行結果です。

04-01.png
04-02.png
04-03.png
04-04.png
04-05.png

英語プロンプト: 
Please show the code for Principal Component Analysis in R. Please also show the R code.  

下図がプロンプトの実行結果です。

05.png

まとめ

今回の環境では、なぜかGPT-4を使用することができず、ガクッとやる気が落ちましたけど、、、

作成したコードを、ローカル環境でコード実行できる魅力は非常に大きいものがあります。

とりあえず、今後に期待しています。

補足: interpreter -yでの実行時の表示

06.png

補足: Code-Llamaに進んだ場合のメッセージ

───────────────────────────────────────────────────────────────────────────────────────────────

▌ OpenAI API key not found                                                                   

To use GPT-4 (recommended) please provide an OpenAI API key.                                   

To use Code-Llama (free but less capable) press enter.                                         

───────────────────────────────────────────────────────────────────────────────────────────────

OpenAI API key: 

▌ Switching to Code-Llama...                                                                 

Tip: Run interpreter --local to automatically use Code-Llama.                                  

───────────────────────────────────────────────────────────────────────────────────────────────

Open Interpreter will use Code Llama for local execution. Use your arrow keys to set up the    
model.                                                                                         

[?] Parameter count (smaller is faster, larger is more capable): 7B
 > 7B
   13B
   34B

[?] Quality (smaller is faster, larger is more capable): Small | Size: 2.6 GB, Estimated RAM us[?] Quality (smaller is faster, larger is more capable): Medium | Size: 3.8 GB, Estimated RAM u[?] Quality (smaller is faster, larger is more capable): Small | Size: 2.6 GB, Estimated RAM us[?] Quality (smaller is faster, larger is more capable): Small | Size: 2.6 GB, Estimated RAM us[?] Quality (smaller is faster, larger is more capable): Medium | Size: 3.8 GB, Estimated RAM u[?] Quality (smaller is faster, larger is more capable): Small | Size: 2.6 GB, Estimated RAM usage: 5.1 GBSize: 2.6 GB, Estimated RAM usage: 5.1 GB
 > Small | Size: 2.6 GB, Estimated RAM usage: 5.1 GB
   Medium | Size: 3.8 GB, Estimated RAM usage: 6.3 GB
   Large | Size: 6.7 GB, Estimated RAM usage: 9.2 GB
   See More

[?] Use GPU? (Large models might crash on GPU, but will run more quickly) (Y/n): n

This language model was not found on your system.

Download to `/Users/sas/Library/Application Support/Open Interpreter/models`? 
[?]  (Y/n): n

 Download cancelled. Exiting. 
 
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