Dengan menggunakan Ollama dan Open WebUI, kita dapat membangun chatbot AI mirip dengan chat.openai.com secara lokal.
Prerequisites
Server Ubuntu/Debian dengan spesifikasi minimum.
- 4 CPUs
- 8 GB RAM
- 160 GB Storage
Install Ollama
Untuk menginstall Ollama, Anda dapat menjalankan skrip berikut.
curl -fsSL https://ollama.com/install.sh | sh
Terdapat language models yang bisa digunakan seperti contoh berikut.
Model | Parameters | Size | Download |
---|---|---|---|
Llama 3 | 8B | 4.7GB | ollama run llama3 |
Llama 3 | 70B | 40GB | ollama run llama3:70b |
Phi 3 Mini | 3.8B | 2.3GB | ollama run phi3 |
Phi 3 Medium | 14B | 7.9GB | ollama run phi3:medium |
Gemma | 2B | 1.4GB | ollama run gemma:2b |
Gemma | 7B | 4.8GB | ollama run gemma:7b |
Mistral | 7B | 4.1GB | ollama run mistral |
Moondream 2 | 1.4B | 829MB | ollama run moondream |
Neural Chat | 7B | 4.1GB | ollama run neural-chat |
Starling | 7B | 4.1GB | ollama run starling-lm |
Code Llama | 7B | 3.8GB | ollama run codellama |
Llama 2 Uncensored | 7B | 3.8GB | ollama run llama2-uncensored |
LLaVA | 7B | 4.5GB | ollama run llava |
Solar | 10.7B | 6.1GB | ollama run solar |
Untuk download dan menginstall language models gunakan perintah.
ollama run llama2
Jika ingin menghapus language models gunakan perintah.
ollama rm llama2
Install Open WebUI
Ada 2 cara yang dapat digunakan untuk menginstall Open WebUI yaitu:
- Manual
- Docker
Pada tutorial ini kita akan mencoba menginstall Open WebUI dengan Docker. Jadi pastikan server telah terinstall Docker.
curl -fsSL https://get.docker.com | sh
Selanjutnya setting port ollama agar listen ke IP 0.0.0.0
agar dapat diakses oleh Open WebUI.
systemctl edit ollama
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Kemudian install Open WebUI.
docker run -d -p 3000:8080 \
--add-host=host.docker.internal:host-gateway \
-v open-webui:/app/backend/data \
--name open-webui \
--restart always ghcr.io/open-webui/open-webui:main
Jika Ollama terinstall di server yang berbeda.
docker run -d -p 3000:8080 \
-e OLLAMA_BASE_URL=https://example.com \
-v open-webui:/app/backend/data \
--name open-webui \
--restart always ghcr.io/open-webui/open-webui:main
Untuk menginstall Open WebUI dengan dukungan GPU Nvidia.
docker run -d -p 3000:8080 \
--gpus all \
--add-host=host.docker.internal:host-gateway \
-v open-webui:/app/backend/data \
--name open-webui \
--restart always ghcr.io/open-webui/open-webui:cuda
Setelah Open WebUI berjalan, Anda dapat mengaksesnya melalui http://IP:3000
Sign up menggunakan email.
Jika sudah berhasil login, pilih model yang telah diinstall sebelumnya.
Lalu Anda dapat mengirimkan pesan untuk pengetesan.
Add you own model
Anda dapat memodifikasi language models yang tersedia pada library Ollama.
Buat file model, kemudian tambahkan baris berikut.
nano mario-model
FROM gemma:7b
# The higher the number, the more creative are the answers
PARAMETER temperature 1
# If set to "0", the model will not consider any previous context or conversation history when generating responses. Each input is treated independently.
# If you set a high number such as "4096", the model will consider previous context or conversation history when generating responses. "4096" is the number of tokens that will be considered.
PARAMETER num_ctx 4096
# Set what "personality" the chat assistant should have in the responses. You can set "who" the chat assistant should respond as and in which style.
SYSTEM """
You are Mario from Super Mario Bros. Answer as Mario, the assistant, only.
"""
Buat model dengan menjalankan perintah berikut.
ollama create mario -f ./mario-model
List model untuk memastikan model baru sudah dibuat.
# ollama list
NAME ID SIZE MODIFIED
mario:latest 07d289089444 5.0 GB About a minute ago
gemma:7b a72c7f4d0a15 5.0 GB About an hour ago
Jika model berhasil dibuat, Anda sudah bisa menggunakannya di Open WebUI.
Referensi: