OllamaをインストールしてローカルLLMを試す
ローカルLLMを試したときの覚書。
Gemini 3.5 Flashと対話。
環境: Mac mini 2024 メモリ24GB, Tahoe 26.5
Ollamaの詳細は前の記事を参考に。
参考: ローカルLLMを簡単構築できるOllamaとは?
1. Ollama(オラマ)のインストール
公式にある通り下記コマンドを実行。
参考: Download Ollama on macOS
% curl -fsSL https://ollama.com/install.sh | sh
確認。
% ollama --version
ollama version is 0.24.0
Ollama サーバーの起動確認。
% lsof -nP -iTCP:11434 -sTCP:LISTEN
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEollama 1107 daiki 4u IPv4 0x2344cb061504ec77 0t0 TCP 127.0.0.1:11434 (LISTEN)
動作確認。
% curl http://127.0.0.1:11434/api/tags
{"models":[]}%
2. モデル「gemma4(ジェマ4)」を試す
利用可能なモデルは公式サイトで確認。
参考: https://ollama.com/library
gemma4を試してみる。
参考: Gemma 4 モデルの概要 | Google AI for Developers
% ollama run gemma4:e4b
プロンプトが入力できるので試してみる。
「/bye」で終了する。
インストールされたモデル一覧。
% ollama list
NAME ID SIZE MODIFIEDgemma4:e4b c6eb396dbd59 9.6 GB 2 minutes ago
モデルの詳細表示。
% ollama show gemma4:e4b
Modelarchitecture gemma4parameters 8.0Bcontext length 131072embedding length 2560quantization Q4_K_Mrequires 0.20.0CapabilitiescompletionvisionaudiotoolsthinkingParameterstemperature 1top_k 64top_p 0.95LicenseApache LicenseVersion 2.0, January 2004...
3.WindowsからLAN内のローカルLLMへ問合せ
Mac miniのGUIデスクトップのステータスバーに表示されているOllamaをクリックして、Settings...を選択。
「Expose Ollama to the network」をオンにする。
Listenしているポートを確認。
% lsof -nP -iTCP:11434 -sTCP:LISTEN
ollama 1876 daiki 3u IPv6 0x14ab69f659091ae0 0t0 TCP *:11434 (LISTEN)
WindowsのPowerShareからOllamaへ利用できるモデルを問い合わせ。
> curl.exe http://macmini2024:11434/v1/models
{"object":"list","data":[{"id":"gemma4:e4b","object":"model","created":1780292637,"owned_by":"library"}]}
gemma4へ問い合わせ実行。
> curl.exe http://macmini2024:11434/api/chat -H "Content-Type: application/json" -d '{"model":"gemma4:e4b","messages":[{"role":"user","content":"日本語で短く自己紹介してください"}],"stream":false}'
{"model":"gemma4:e4b","created_at":"2026-06-02T00:37:10.189361Z","message":{"role":"assistant","content":"こんにちは。\n\n私はAIアシスタントです。お話し相手になったり、何かを知りたいことについてお答えしたり、文章作成のお手伝いをしたりすることができます。\n\n何かお手伝いできることがありましたら、何でもお気軽にお申し付けください。どうぞよろしくお願いします!","thinking":"Thinking Process:\n\n1. **Analyze the Request:** The user asks for a short self-introduction in Japanese (\"日本語で短く自己紹介してください\").\n2. **Determine the Persona:** The response must be delivered from the perspective of an AI (specifically, a large language model).\n3. **Identify Key Components of an AI Introduction (in Japanese):**\n * Greeting (挨拶): Hello.\n * Name/Identity (名前/正体): I am a language model. (Optional: State the name, if appropriate, but general identity is safer.)\n * Purpose/Function (役割): What can I do? (Answer questions, write text, chat, etc.)\n * Availability/Attitude (姿勢): I am ready to help.\n4. **Drafting the Content (Internal Japanese Draft):**\n * *Greeting:* こんにちは。 (Kon'nichiwa.)\n * *Identity:* 私はAIです。 (Watashi wa AI desu.)\n * *Function:* あなたのお手伝いをします。質問に答えますし、文章を書くこともできます。 (Anata no otetsudai o shimasu. Shitsumon ni kotaemasu shi, bunshō o kaku koto mo dekimasu.)\n * *Call to Action:* 何かあれば、気軽に声をかけてください。 (Nani ka areba, kigaru ni koe o kakete kudasai.)\n5. **Refining and Condensing (Making it natural and polite - Keigo appropriate for a general setting):** Combine these elements into a smooth, polite, and brief response.\n\n * *Target Tone:* Polite, helpful, clear, and concise.\n\n6. **Final Japanese Output Selection:** (This is the selected response.)"},"done":true,"done_reason":"stop","total_duration":11873438000,"load_duration":3505205834,"prompt_eval_count":23,"prompt_eval_duration":110705292,"eval_count":448,"eval_duration":8099928278}
次はGemini, GPT, Gemma4などを簡単に切り替えて使える仕組みを考える。