🤖

ollamaで自分のようなbotを作る_1. Dockerの公式イメージを動かしてみる

2024/04/23に公開

Ollamaを使えばローカルでLLMを動かせるらしい。
自分に関するデータはいくらでもあるので、
それらを突っ込むことで自分のようなbotを作れないかと思い立った。
https://ollama.com/

ローカルでOllamaを起動してモデルを動かす

DockerでOllamaを動かせるので公式imageをpullしてローカルで動かしてみる。

Ollama is now available as an official Docker image
https://ollama.com/blog/ollama-is-now-available-as-an-official-docker-image

Ollamaが使えるモデルは色々ある。
今回はMetaが開発した商用可能なLLM「llama2」を試してみる。

docker pull ollama/ollama
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
$ docker exec -it 8d7a588dcbee bash
root@8d7a588dcbee:/# ollama run llama2

実行すると pulling manifestでモデルをダウンロードし始めた。
ダウンロードは結構待つ。結果、10分前後待った。

ダウンロードが完了すると以下のような表示になる。PCが唸っている。熱い。

root@8d7a588dcbee:/# ollama run llama2
pulling manifest
pulling 8934d96d3f08... 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 3.8 GB
pulling 8c17c2ebb0ea... 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 7.0 KB
pulling 7c23fb36d801... 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 4.8 KB
pulling 2e0493f67d0c... 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏   59 B
pulling fa304d675061... 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏   91 B
pulling 42ba7f8a01dd... 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏  557 B
verifying sha256 digest
writing manifest
removing any unused layers
success

とりあえず適当な質問を投げてみる。
「空はなぜ青い?」への返答に15分くらいかかる。めちゃめちゃ遅い。このPCだと限界か。
このままでは使い物にならなさそう。

>>> 空はなぜ青い?
The question "空はなぜ青い?" can be translated to English as "Why is the sky blue?"

There are a few reasons why the sky appears blue:

1. Rayleigh scattering: When sunlight enters Earth's atmosphere, it encounters tiny molecules of gases such as nitrogen and oxygen. These molecules scatter the light in all directions, but they
scatter shorter (blue)

一度停止させた後に、再度実行するとすぐ入力受付状態になった。
英語だとちょっとだけ早いかも。

root@8d7a588dcbee:/# ollama run llama2
>>> please introduce yourself.
Hello! My name is LLaMA, I'm a large language model trained by a team of researcher at Meta AI. My primary

とりあえず起動することはできた。

起動までに参考にした記事

さまざまなチャットAIを簡単にローカル環境で動かせるアプリ「Ollama」の公式Dockerイメージが登場
https://gigazine.net/news/20231021-ollama-docker/

Discussion