1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ローカルネットワークで使えるオフライン ChatGPT を作る ~ gpt-oss と OpenWebUI を使って

Posted at

完成画面

qiita_gptoss20b.png

ローカルネットワークの Ubuntu のワークステーションにサーバーを立てて、他のユーザーがブラウザから使える GUI を作る。
基本は公式サイトに倣いつつ、サーバー特有の設定を多少行う。

Ollama のインストール + gpt-oss を導入

公式サイト

  • Ollama をインストール
    • curl -fsSL https://ollama.com/install.sh | sh
  • gpt-oss をインストール
    • 20B model の場合は ollama pull gpt-oss:20b
    • 120B model の場合は ollama pull gpt-oss:120b だが、60 GB 以上あるのに注意
  • 試しに CUI で動作確認
    USER@ubuntu-server:~$ ollama run gpt-oss:20b
    >>> あなたは誰ですか?
    Thinking...
    The user asks: "あなたは誰ですか?" in Japanese. They ask: "Who are you?" We respond as ChatGPT: a language model.
    Should be polite. Provide explanation. Also mention cannot claim personal identity. Should be concise.
    ...done thinking.
    
    私はOpenAIが開発した大規模言語モデル、ChatGPTです。
    インターネット上の大量のテキストを学習しており、質問に対して情報を提供したり、会話を楽しんだりすることができます。
    
    個人的な経験や感情は持っていませんので、あくまでプログラムとしての回答になります。
    
  • 応答が速い!

Docker のセットアップ

  • Docker のインストール

公式サイト

  • 公式サイトのシェルコマンドをそのままコピペする
    # Add Docker's official GPG key:
    sudo apt-get update
    sudo apt-get install ca-certificates curl
    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc
    
    # Add the repository to Apt sources:
    echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
      $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
      sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update
    
    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    
  • Docker の post-installation steps
    • https://docs.docker.com/engine/install/linux-postinstall/
    • Manage Docker as a non-root user
      • sudo groupadd docker
        • groupadd: group 'docker' already exists らしいので不要だった
      • sudo usermod -aG docker $USER
      • newgrp docker
    • docker の自動起動
      sudo systemctl enable docker.service
      sudo systemctl enable containerd.service
      
  • Ollama の外部アクセスの許可
    • sudo systemctl edit ollama
    • 以下を記入すべき場所に追記
      [Service]
            Environment="OLLAMA_HOST=0.0.0.0:11434"
      
    • 再起動
      • sudo systemctl daemon-reload
      • sudo systemctl restart ollama

OpenWebUI で GUI を作成

公式サイト

  • https://docs.openwebui.com/
  • Open WebUI Bundled with Ollama, For CPU Only のコマンドに、--add-host=host.docker.internal:host-gatewayを追加して実行
    • docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v ollama:/root/.ollama -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:ollama
    • ローカルで動かすだけなら公式通りで大丈夫そう
  • OpenWebUI へブラウザからアクセス
  • アカウント作成
  • Admin Settings > Connections で Base URL:http://host.docker.internal:11434 に設定
  • 新規ユーザー登録の許可
    • Admin Settings > General > Authentication で Default User Role: user, Enable New Signups
  • 新規ユーザーのモデルアクセス
    • Admin Settings > Models > gpt-oss:20b > Visibility: Public
    • Admin Settings > Users > Groups > Default
    • Model Access 等を全部 ON

おわりに

  • OpenWebUI によって、履歴の管理やファイルのアップロードを、ChatGPT と同様に使えて嬉しい
  • ネットワーク内の人が各自ユーザー登録して使えるシステムも、会社や研究室で使える
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?