CLI e API
| Comando | Uso |
|---|---|
ollama serve |
avvia il daemon |
ollama pull <m> |
scarica un modello |
ollama run <m> ["prompt"] |
chat interattiva o prompt singolo |
ollama list |
modelli su disco |
ollama ps |
modelli caricati in memoria |
ollama stop <m> |
scarica il modello dalla memoria |
ollama show <m> [--modelfile] |
dettagli o Modelfile |
ollama create <nome> -f Modelfile |
crea un modello derivato |
ollama cp <src> <dst> |
copia/alias |
ollama rm <m> |
elimina dal disco |
Nella chat interattiva: /set parameter num_ctx 16384, /show info, /clear, /bye.
Prompt con input da pipe, utile per far spiegare output di kubectl:
kubectl -n shop-demo describe pod -l app=api | ollama run qwen2.5:7b-instruct "Explain the root cause and the fix. Be concise."kubectl -n shop-demo get events --sort-by=.lastTimestamp | tail -30 | ollama run qwen2.5:7b-instruct "Group these events by root cause."API nativa
Sezione intitolata “API nativa”curl -s http://localhost:11434/api/tags | jq -r '.models[].name'curl -s http://localhost:11434/api/ps | jq '.models[] | {name, size_vram, expires_at}'curl -s http://localhost:11434/api/chat -d '{"model":"qwen2.5:7b-instruct","stream":false,"messages":[{"role":"user","content":"What is a PodDisruptionBudget?"}]}' | jq -r .message.contentcurl -s http://localhost:11434/api/generate -d '{"model":"qwen2.5:7b-instruct","prompt":"Say OK","stream":false,"options":{"num_ctx":8192,"temperature":0}}' | jq -r .responsecurl -s http://localhost:11434/api/show -d '{"model":"qwen2.5:7b-instruct"}' | jq '.details'API OpenAI-compatible
Sezione intitolata “API OpenAI-compatible”curl -s http://localhost:11434/v1/models | jq -r '.data[].id'curl -s http://localhost:11434/v1/chat/completions -H 'Content-Type: application/json' -d '{"model":"qwen2.5:7b-instruct","temperature":0,"messages":[{"role":"system","content":"You are a Kubernetes SRE."},{"role":"user","content":"Why would a Service have no endpoints?"}]}' | jq -r '.choices[0].message.content'Test del tool calling (se il modello lo supporta, la risposta contiene tool_calls):
curl -s http://localhost:11434/v1/chat/completions -H 'Content-Type: application/json' -d '{"model":"qwen2.5:14b-instruct","messages":[{"role":"user","content":"List pods in namespace shop-demo"}],"tools":[{"type":"function","function":{"name":"kubectl_get","description":"Run kubectl get","parameters":{"type":"object","properties":{"resource":{"type":"string"},"namespace":{"type":"string"}},"required":["resource"]}}}]}' | jq '.choices[0].message.tool_calls'Qualsiasi client OpenAI funziona impostando base URL e una API key fittizia:
export OPENAI_API_BASE=http://localhost:11434/v1 OPENAI_BASE_URL=http://localhost:11434/v1 OPENAI_API_KEY=ollama