4
1

LM StudioでモデルがダウンロードできなかったのでOllamaを使ってOpen Interpreterを動かしてみた

Last updated at Posted at 2023-12-18

動機

  • Zscalerのようなクラウドセキュリティプラットフォームを利用しているMacBookにてOpen Interpreterをローカルモードで利用したい。
  • 現在Open Interpreterをローカルモードで利用するには、LM Studioが必要とのことであるが、LM StudioのGUIからモデルをダウンロードしようとしたらZscalerの影響のためか(?)ダウンロードできなかった。
  • LM Studioのアプリはプロキシの設定ができない(?)ようなので、Zsaclerを使っているMacだとLM Studio経由でOpen Interpreterを動かすことができない。(Ollamaのモデルはなぜかダウンロードできた)

Open InterpreterでOllamaを使うことはできるのか?

  • 現在のOpen InterpreterはLiteLLMを使ってLLMのAPIを呼び出す。
  • LiteLLMはOllamaをサポートしている。
  • つまり、LM Studioを使わなくてもOpen Interpreterがローカルモードで利用できる(と思う)。

前提

  • Open InterpreterやOllamaは事前にMacへインストールしているものとします。
  • 今回はAppleのM2チップが搭載されたMacBook Air(メモリ24GB)で試しています。
  • ollama pullで使いたいモデルをインストールしているものとします。
    # codellamaをpullする場合
    ollama pull codellama
    

Open Interpreterの起動

ターミナルから以下の通りinterpreterコマンドの--modelollama/codellamaを指定し、--api_basehttp://localhost:11434を指定して実行します。
(Ollamaはデフォルトでポート番号11434を利用します)

interpreter --local --model ollama/codellama --api_base http://localhost:11434

実行例

上記の通りinterpreterをローカルモードで起動すると以下のようなメッセージが表示されます。

▌ Open Interpreter’s local mode is powered by LM Studio.
You will need to run LM Studio in the background.
 1 Download LM Studio from https://lmstudio.ai/ then start it.
 2 Select a language model then click Download.
 3 Click the <-> button on the left (below the chat button).
 4 Select your model at the top, then click Start Server.
Once the server is running, you can begin your conversation below.
▌ Warning: This feature is highly experimental.
▌ Don’t expect gpt-3.5 / gpt-4 level quality, speed, or reliability yet!

試しにプロンプトでWhat is Large Language Model?と質問してみます。

> What is Large Language Model?
  A large language model is a type of artificial intelligence (AI) model that
  is trained on a large corpus of text data to generate language outputs that
  are coherent and natural-sounding. These models can be used for various
  tasks such as language translation, text generation, and language
  understanding.
  Large language models typically consist of multiple layers of neural
  networks that learn from the input data. They use an encoder-decoder
  architecture to process the input text and generate the output text. Some
  key benefits of using large language models include improved performance,
  flexibility, scalability, and improved readability. However, there are also
  challenges associated with using these models, such as training time, data
  requirements, overfitting, and explainability.
  Overall, large language models are powerful tools for generating coherent
  and natural-sounding text outputs. However, it is important to consider the
  trade-offs between these benefits and the challenges that come with using
  them.

...(以下省略)...

LLMの説明をしてくれました。

本当にOllamaを使っているのか確認してみる

アクティビティモニタでOllamaが本当に動いているか確認してみました。

ollama-runner.jpg

上の添付画像は実行時のキャプチャですが、ollama-runnerというOllamaのプロセスが表示されており、% GPUの列が87.4となっています。OllamaがGPUを使って推論しているのがわかります。

また、interpreterコマンドの--modelに存在しないモデル名を指定した場合の挙動を確認してみました。ここでは、以下のようにollama/dummyという存在しないモデル名をセットしてみます。

interpreter --local --model ollama/dummy --api_base http://localhost:11434

Open Interpreter自体は起動しますが、プロンプトで何か質問をしてみると以下のようなエラーが発生しました。

...(省略)... 

Traceback (most recent call last):
  File “/Users/testuser/.pyenv/versions/3.11.5/bin/interpreter”, line 8, in <module>
    sys.exit(start_terminal_interface())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File “/Users/testuser/.pyenv/versions/3.11.5/lib/python3.11/site-packages/interpreter/core/core.py”, line 21, in start_terminal_interface
    start_terminal_interface(self)
  File “/Users/testuser/.pyenv/versions/3.11.5/lib/python3.11/site-packages/interpreter/terminal_interface/start_terminal_interface.py”, line 304, in start_terminal_interface
    interpreter.chat()
  File “/Users/testuser/.pyenv/versions/3.11.5/lib/python3.11/site-packages/interpreter/core/core.py”, line 77, in chat
    for _ in self._streaming_chat(message=message, display=display):
  File “/Users/testuser/.pyenv/versions/3.11.5/lib/python3.11/site-packages/interpreter/core/core.py”, line 92, in _streaming_chat
    yield from terminal_interface(self, message)
  File “/Users/testuser/.pyenv/versions/3.11.5/lib/python3.11/site-packages/interpreter/terminal_interface/terminal_interface.py”, line 115, in terminal_interface
    for chunk in interpreter.chat(message, display=False, stream=True):
  File “/Users/testuser/.pyenv/versions/3.11.5/lib/python3.11/site-packages/interpreter/core/core.py”, line 113, in _streaming_chat
    yield from self._respond()
  File “/Users/testuser/.pyenv/versions/3.11.5/lib/python3.11/site-packages/interpreter/core/core.py”, line 148, in _respond
    yield from respond(self)
  File “/Users/testuser/.pyenv/versions/3.11.5/lib/python3.11/site-packages/interpreter/core/respond.py”, line 115, in respond
    raise Exception(
Exception: {‘error’: “model ‘dummy’ not found, try pulling it first”}
Please make sure LM Studio’s local server is running by following the steps above.
If LM Studio’s local server is running, please try a language model with a different architecture.

上記エラーの最後の方でException: {‘error’: “model ‘dummy’ not found, try pulling it first”}というExceptionが発生していることがわかります。

以上から存在するモデル名を正しく指定すればOllamaで正しく推論処理が動くことがわかりました。

まとめ

  • 簡単ではありますが、Ollamaを使ってOpen Interpreterをローカルモードで実行する方法を紹介しました。
  • OllamaはMacBookでローカルLLMを実践するのに便利ですね。
  • LM Studioのプロキシサーバーの設定方法をご存知の方がいらっしゃったらご教授いただけると幸いです。
    (GitHubのリポジトリで以下のようなイシューがあったので、まだ設定ができない可能性がある?)
    https://github.com/lmstudio-ai/configs/issues/1

参考情報

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