Ollama Installation: Local LLM Running Guide
Ollama installation, running local LLM models (Llama 3, Mistral, Gemma), API usage, model management, GPU acceleration and Docker deployment.
LocalAI Docker installation, OpenAI API compatible self-hosted AI service, text generation, image creation, speech synthesis, embedding and model management guide.
LocalAI is an open-source, self-hosted AI API server that is fully compatible with the OpenAI API. It combines all AI capabilities including text generation, image creation, speech synthesis, speech recognition and embedding in a single service. Its ability to run in CPU mode without a GPU is one of its biggest advantages.
LocalAI is a drop-in replacement that replicates the OpenAI API format exactly. You can redirect your existing applications using the OpenAI SDK to LocalAI by simply changing the base URL. Key features:
| Component | CPU Mode | GPU Mode |
|---|---|---|
| RAM | 8 GB+ | 16 GB+ |
| Disk | 20 GB | 50 GB+ |
| GPU | Not required | 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 provides easy model installation with its model gallery system:
# List available models
curl http://localhost:8080/models/available
# Load model (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"
}'
# List loaded models
curl http://localhost:8080/v1/models
# Download GGUF model file
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"
Create a model configuration file:
# 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": "You are a helpful assistant."},
{"role": "user", "content": "What is Docker Compose?"}
],
"temperature": 0.7,
"max_tokens": 512
}'
curl http://localhost:8080/v1/embeddings \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-ada-002",
"input": "Server security best practices"
}'
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": "Hello, I am the LocalAI speech synthesis engine.",
"voice": "alloy"
}' --output speech.mp3
Directly usable with the OpenAI Python SDK:
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": "You are a Linux expert."},
{"role": "user", "content": "How to install Nginx?"}
],
max_tokens=1024
)
print(response.choices[0].message.content)
# Embedding
embedding = client.embeddings.create(
model="text-embedding-ada-002",
input="Docker container management"
)
print(f"Embedding dimension: {len(embedding.data[0].embedding)}")
You can run multiple models simultaneously:
# 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
# Environment variables
export THREADS=8 # CPU thread count
export CONTEXT_SIZE=4096 # Context window
export GPU_LAYERS=35 # Layers loaded to GPU
export PARALLEL_REQUESTS=true # Parallel request support
# With Docker
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
Run your own OpenAI-compatible AI API with LocalAI on REXE servers. Get high-performance inference with our GPU servers.
LocalAI replicates the OpenAI API format exactly. The same endpoints and request formats are used. The difference is that models run on your own server and your data never leaves. Applications using the OpenAI SDK can switch to LocalAI by simply changing the base URL.
Yes, one of LocalAI's biggest advantages is its ability to run in CPU mode. Quantized models in GGUF format run at reasonable speeds on CPU. However, GPU provides much faster response times.
LocalAI supports GGUF (llama.cpp), GGML, PyTorch, Safetensors and ONNX formats. The most commonly used format is GGUF, which provides low memory consumption.
Yes, LocalAI provides an OpenAI-compatible /v1/embeddings endpoint. You can create text vectors with embedding models like all-MiniLM-L6-v2 and use them in RAG (Retrieval Augmented Generation) applications.
Yes, you can define multiple model configurations in the config directory. Each model is accessible from the API with a different name. Models serve in parallel as long as there is sufficient RAM/VRAM.
Yes, LocalAI supports image generation through the /v1/images/generations endpoint with Stable Diffusion integration. It also supports speech recognition with Whisper and speech synthesis with TTS.
Ollama installation, running local LLM models (Llama 3, Mistral, Gemma), API usage, model management, GPU acceleration and Docker deployment.
Open WebUI installation with Docker, Ollama integration, user management, RAG (document querying), model management, custom prompts and multi-user support.
NVIDIA driver installation, CUDA toolkit, nvidia-container-toolkit, model serving with vLLM, GPU monitoring and AI model deployment with Docker guide.