Appearance
OllamaModel
Ollama runs open-source models locally on your machine. No cloud API key is required — install Ollama, pull a model, then point OllamaModel at your local server.
Local setup
bash
# Install Ollama (macOS/Linux)
curl -fsSL https://ollama.com/install.sh | sh
# Pull a model (downloads weights to ~/.ollama/models)
ollama pull llama3.2
# Verify the server is running (default http://localhost:11434)
ollama listEnvironment variables: OLLAMA_HOST (optional, default http://localhost:11434), OLLAMA_MODEL_NAME
python
import os
from elsai_model.ollama import OllamaModel
model = OllamaModel(
host=os.getenv("OLLAMA_HOST"), # local server; omit for localhost default
model_id=os.getenv("OLLAMA_MODEL_NAME", "llama3.2"),
temperature=0.2,
)
messages = [{"role": "user", "content": "Say hello in one short sentence."}]
response = model.invoke(messages)
print(response.message.content)
for chunk in model.stream_text(messages):
print(chunk, end="", flush=True)Or via the factory (host required; no api_key):
python
from elsai_model import LLM, Provider
model = LLM(
provider=Provider.OLLAMA,
model=os.getenv("OLLAMA_MODEL_NAME", "llama3.2"),
host=os.getenv("OLLAMA_HOST", "http://localhost:11434"),
temperature=0.2,
)Popular local models: llama3.2, mistral, codellama, phi3, gemma2.
See also
- LLM Models overview — install, extras, factory
- LLM factory