Ollama Kurulumu: Yerel LLM Çalıştırma Rehberi
Ollama kurulumu, yerel LLM modelleri çalıştırma (Llama 3, Mistral, Gemma), API kullanımı, model yönetimi, GPU hızlandırma ve Docker ile deployment.
LocalAI Docker kurulumu, OpenAI API uyumlu self-hosted AI servisi, metin üretimi, görsel oluşturma, ses sentezi, embedding ve model yönetimi rehberi.
LocalAI, OpenAI API ile tam uyumlu, self-hosted çalışan açık kaynaklı bir AI API sunucusudur. Metin üretimi, görsel oluşturma, ses sentezi, ses tanıma ve embedding gibi tüm AI yeteneklerini tek bir serviste birleştirir. GPU olmadan da CPU modunda çalışabilmesi en büyük avantajlarından biridir.
LocalAI, OpenAI API formatını birebir taklit eden bir drop-in replacement'tır. Mevcut OpenAI SDK kullanan uygulamalarınızı sadece base URL değiştirerek LocalAI'ya yönlendirebilirsiniz. Temel özellikleri:
| Bileşen | CPU Modu | GPU Modu |
|---|---|---|
| RAM | 8 GB+ | 16 GB+ |
| Disk | 20 GB | 50 GB+ |
| GPU | Gerekli değil | NVIDIA 8 GB+ VRAM |
| OS | Linux/macOS | Linux (CUDA) |
| Docker | 24.0+ | 24.0+ + nvidia-container-toolkit |
docker run -d \
--name localai \
-p 8080:8080 \
-v localai_models:/build/models \
localai/localai:latest-cpu
docker run -d \
--name localai \
--gpus all \
-p 8080:8080 \
-v localai_models:/build/models \
localai/localai:latest-gpu-nvidia-cuda-12
version: '3.8'
services:
localai:
image: localai/localai:latest-gpu-nvidia-cuda-12
container_name: localai
ports:
- "8080:8080"
volumes:
- localai_models:/build/models
- ./config:/build/config
environment:
- THREADS=4
- CONTEXT_SIZE=4096
- GALLERIES=[{"name":"model-gallery","url":"github:mudler/LocalAI/gallery/index.yaml@master"}]
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/readyz"]
interval: 30s
timeout: 10s
retries: 3
volumes:
localai_models:
LocalAI, model gallery sistemi ile kolay model kurulumu sağlar:
# Mevcut modelleri listele
curl http://localhost:8080/models/available
# Model yükleme (Llama 3)
curl http://localhost:8080/models/apply -d '{
"id": "huggingface://TheBloke/Llama-2-7B-Chat-GGUF/llama-2-7b-chat.Q4_K_M.gguf",
"name": "llama-3"
}'
# Yüklü modelleri listele
curl http://localhost:8080/v1/models
# GGUF model dosyasını indirme
wget -O models/mistral-7b-instruct.gguf \
"https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/resolve/main/mistral-7b-instruct-v0.2.Q4_K_M.gguf"
Model yapılandırma dosyası oluşturun:
# config/mistral.yaml
name: mistral
backend: llama-cpp
parameters:
model: mistral-7b-instruct.gguf
temperature: 0.7
top_p: 0.9
top_k: 40
context_size: 4096
threads: 4
gpu_layers: 35
template:
chat_message: |
[INST] {{.Input}} [/INST]
chat: |
{{.Input}}
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "llama-3",
"messages": [
{"role": "system", "content": "Sen yardımcı bir asistansın."},
{"role": "user", "content": "Docker compose nedir?"}
],
"temperature": 0.7,
"max_tokens": 512
}'
curl http://localhost:8080/v1/embeddings \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-ada-002",
"input": "Sunucu güvenliği en iyi uygulamalar"
}'
curl http://localhost:8080/v1/images/generations \
-H "Content-Type: application/json" \
-d '{
"model": "stablediffusion",
"prompt": "a futuristic server room, neon lights",
"size": "512x512"
}'
curl http://localhost:8080/v1/audio/transcriptions \
-F "model=whisper-1" \
-F "file=@audio.mp3"
curl http://localhost:8080/v1/audio/speech \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "Merhaba, ben LocalAI ses sentezi motoruyum.",
"voice": "alloy"
}' --output speech.mp3
OpenAI Python SDK ile doğrudan kullanılabilir:
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8080/v1",
api_key="not-needed"
)
# Chat completion
response = client.chat.completions.create(
model="llama-3",
messages=[
{"role": "system", "content": "Sen bir Linux uzmanısın."},
{"role": "user", "content": "Nginx nasıl kurulur?"}
],
max_tokens=1024
)
print(response.choices[0].message.content)
# Embedding
embedding = client.embeddings.create(
model="text-embedding-ada-002",
input="Docker container yönetimi"
)
print(f"Embedding boyutu: {len(embedding.data[0].embedding)}")
Birden fazla modeli aynı anda çalıştırabilirsiniz:
# config/models.yaml
- name: llama-3
backend: llama-cpp
parameters:
model: llama-3-8b.gguf
context_size: 4096
gpu_layers: 35
- name: mistral
backend: llama-cpp
parameters:
model: mistral-7b-instruct.gguf
context_size: 4096
gpu_layers: 35
- name: embedding
backend: llama-cpp
embeddings: true
parameters:
model: all-MiniLM-L6-v2.gguf
# Ortam değişkenleri
export THREADS=8 # CPU thread sayısı
export CONTEXT_SIZE=4096 # Context window
export GPU_LAYERS=35 # GPU'ya yüklenen katman sayısı
export PARALLEL_REQUESTS=true # Paralel istek desteği
# Docker ile
docker run -d \
--name localai \
--gpus all \
-p 8080:8080 \
-e THREADS=8 \
-e CONTEXT_SIZE=4096 \
-v localai_models:/build/models \
localai/localai:latest-gpu-nvidia-cuda-12
server {
listen 443 ssl;
server_name ai.example.com;
ssl_certificate /etc/letsencrypt/live/ai.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ai.example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
client_max_body_size 50M;
}
}
REXE sunucularında LocalAI ile OpenAI uyumlu kendi AI API'nizi çalıştırabilirsiniz. GPU sunucularımız ile yüksek performanslı inference elde edin.
LocalAI, OpenAI API formatını birebir taklit eder. Aynı endpoint'ler ve istek formatları kullanılır. Fark, modellerin kendi sunucunuzda çalışması ve verilerinizin dışarı çıkmamasıdır. Mevcut OpenAI SDK kullanan uygulamalar sadece base URL değiştirerek LocalAI'ya geçebilir.
Evet, LocalAI'nın en büyük avantajlarından biri CPU modunda çalışabilmesidir. GGUF formatındaki quantize modeller CPU'da makul hızda çalışır. Ancak GPU ile çok daha hızlı yanıt süreleri elde edilir.
LocalAI; GGUF (llama.cpp), GGML, PyTorch, Safetensors ve ONNX formatlarını destekler. En yaygın kullanılan format, düşük bellek tüketimi sağlayan GGUF'tur.
Evet, LocalAI OpenAI uyumlu /v1/embeddings endpoint'i sunar. all-MiniLM-L6-v2 gibi embedding modelleri ile metin vektörleri oluşturabilir ve RAG (Retrieval Augmented Generation) uygulamalarında kullanabilirsiniz.
Evet, config dizininde birden fazla model yapılandırması tanımlayabilirsiniz. Her model farklı bir isimle API'den erişilebilir. Yeterli RAM/VRAM olduğu sürece modeller paralel olarak hizmet verir.
Evet, LocalAI Stable Diffusion entegrasyonu ile /v1/images/generations endpoint'i üzerinden görsel üretimi destekler. Ayrıca Whisper ile ses tanıma ve TTS ile ses sentezi de yapılabilir.
Ollama kurulumu, yerel LLM modelleri çalıştırma (Llama 3, Mistral, Gemma), API kullanımı, model yönetimi, GPU hızlandırma ve Docker ile deployment.
Open WebUI kurulumu Docker ile, Ollama entegrasyonu, kullanıcı yönetimi, RAG (belge sorgulama), model yönetimi, özel promptlar ve çoklu kullanıcı desteği.
NVIDIA sürücü kurulumu, CUDA toolkit, nvidia-container-toolkit, vLLM ile model serving, GPU monitoring ve Docker ile AI model deployment rehberi.