0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ローカルLLMと戯れる

0
Last updated at Posted at 2026-09-16

はじめに

少し前、G検定の勉強をしていて、その周辺知識を調べている際に「ローカルLLM」の存在を知りました。
…というのを最近思い出したので、せっかくなので自分のPCにもローカルLLMを入れてちょっと遊んでみようと思いました。

ChatGPT等では入力した内容が外部のサーバに行って処理されます。
それはそういうものだと納得したうえで利用しているのでいいのですが、どうしても「AIの力を借りたい。だけど外部に情報を入力したくない」ような場面もあると思います。

そういうときに、外部に送信せず自分のローカルPCで完結できる「ローカルLLM」という選択肢もあるのだと知ったときは当時びっくりしました。

導入環境

項目 内容
ディストリビューション Ubuntu (WSL2.0)
ホストOS Windows11
メモリ 32GB
CPU Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz
GPU Intel(R) UHD Graphics 630

手順

Ollamaをインストール

より、Linuxを選択、そのコマンドを使う。
Ollamaの詳細なドキュメントはこちら(上記ページからでもたどれる)。

$ curl -fsSL https://ollama.com/install.sh | sh
>>> Cleaning up old version at /usr/local/lib/ollama
>>> Installing ollama to /usr/local
>>> Downloading ollama-linux-amd64.tar.zst
######################################################################## 100.0%
>>> Creating ollama user...
>>> Adding ollama user to render group...
>>> Adding ollama user to video group...
>>> Adding current user to ollama group...
>>> Creating ollama systemd service...
>>> Enabling and starting ollama service...
Created symlink /etc/systemd/system/default.target.wants/ollama.service → /etc/systemd/system/ollama.service.
>>> The Ollama API is now available at 127.0.0.1:11434.
>>> Install complete. Run "ollama" from the command line.

必要なモジュールがインストールされていない場合、下記のようなエラーメッセージが表示される(表示された)。

ERROR: This version requires zstd for extraction. Please install zstd and try again:
  - Debian/Ubuntu: sudo apt-get install zstd
  - RHEL/CentOS/Fedora: sudo dnf install zstd
  - Arch: sudo pacman -S zstd

その際は、その指示に従って必要なモジュールをインストールした後、再度上記のcurlコマンドを実行すればOK。
今回はUbuntuにインストールしたいので、指示に従い以下のコマンドを実行。

$ sudo apt-get install zstd

Gemma 4を導入

$ ollama pull gemma4:26b
pulling manifest
...
success

実行して完了するまでかなり時間がかかる。
気長に待ちましょう。

導入したgemma4:26bの仕様を確認

$ ollama show gemma4:26b
  Model
    architecture        gemma4
    parameters          25.2B
    context length      262144
    embedding length    2816
    quantization        Q4_K_M
    requires            0.30.0

...

試しにチャットしてみる

せっかくローカルLLMを入れたので、メッセージを送ってみる。
今回は「こんにちは。」と入力。

$ ollama run gemma4
pulling manifest
...
success
>>> こんにちは。
Thinking...
Here's a thinking process that leads to the suggested response:

1.  **Analyze the input:** The input is "こんにちは" (Konnichiwa). This means "Hello" or "Good afternoon" in
Japanese. It is a friendly, neutral greeting.

2.  **Determine the goal:** The response should be appropriate for a greeting, maintaining a friendly, natural,
and polite tone in Japanese.

3.  **Formulate response options (Japanese):**
    *   *Option 1 (Simple Echo):* こんにちは (Konnichiwa). (Too brief, a bit robotic).
    *   *Option 2 (Polite Echo + Inquiry):* こんにちは!何かお手伝いできることはありますか? (Konnichiwa! Nanika
otetsudai dekiru koto wa arimasu ka?) (Hello! Is there anything I can help you with?) - *This is standard AI
practice.*
    *   *Option 3 (Enthusiastic/Warm):* こんにちは!どうされましたか? (Konnichiwa! Dō saremashita ka?) (Hello!
What brings you here? / How can I help?) - *Also very natural.*

4.  **Select the best option:** Option 2 is the most versatile and professional response for an AI chat interface.
It acknowledges the greeting and immediately establishes helpfulness.

5.  **Structure and refine the response (Japanese):**
    *   Start with the greeting: こんにちは!
    *   Offer a warm welcome/readiness statement: いつもご利用ありがとうございます。 (Thank you for always using
me/visiting.) - *Optional but adds polish.*
    *   Ask how to help: 😊何かご質問や、お手伝いできることはありますか? (Do you have any questions or anything I
can help you with?)

6.  **Final Polish (Adding English translation/context for completeness):** Presenting the Japanese response
clearly, and offering a helpful English translation, ensures the user understands the conversational exchange.

7.  **Final Output Generation.** (This leads to the polite, welcoming response provided below.)
...done thinking.

こんにちは!😊

何かご質問や、お手伝いできることはありますか?
お気軽にお話しくださいね。

***
*(Konnichiwa! Nanika go-shitsumon ya, otetsudai dekiru koto wa arimasu ka? Okigaru ni ohanashi kudasai ne.)*

*(Hello! Do you have any questions, or is there anything I can help you with? Please feel free to talk to me.)*

>>> Send a message (/? for help)

けっこう時間がかかるものの、Gemmaからのメッセージが返ってきた。
いい感じのグラボを積んでいたらもっとスムーズに出力されるのだとは思う。

また、出力までの思考の過程もコマンドライン上に表示された。
Thinking...から...done thinking.までの部分が該当。
これについては、思考部分を出さないようにするオプションコマンドがあるのかもしれないが、よく分かっていない。

バックグラウンド

以下のコマンドから、Ollamaがlocalhost上で動作していて、メッセージのやり取りをしていることを確認できる。

$ curl http://localhost:11434
Ollama is running

チャットを閉じる

>>> /bye

ローカルサーバを停止させる

$ sudo systemctl stop ollama

これにより、ローカルサーバが停止される。

$ curl http://localhost:11434
curl: (7) Failed to connect to localhost port 11434: Connection refused

ターミナルを閉じて、再度WSLを起動してollama run gemma4を実行すると再度チャットできるようになった。

おわりに

以前から興味があったローカルLLMの環境を作って、軽く動かしてみました。
自分のPCのスペック的に(特にGPU)足りてない部分もあるせいか、レスポンスには時間がかかりますが、「外部のサーバを介さず、ローカル内でやり取りが完結する」という体験をできたのは良かったなと思います。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?