Ollama Local LLM Skill
Interact with locally-running Ollama models via a single unified script.
Prerequisites
Ollama must be running locally. Start with ollama serve or via the Ollama desktop app. Default endpoint: http://localhost:11434. Override with OLLAMA_HOST env var.
Quick Start
All commands use the same script with subcommands:
python skills/ollama/scripts/ollama_api.py [--timeout 300] <command> [options]
Outputs are written to output/ under the current working directory.
Commands
List Models
python skills/ollama/scripts/ollama_api.py list
Pull a Model
python skills/ollama/scripts/ollama_api.py pull --model qwen3:8b
python skills/ollama/scripts/ollama_api.py pull --model llama3.2
Show Model Info
python skills/ollama/scripts/ollama_api.py show --model qwen3:8b
Generate (Text Completion)
python skills/ollama/scripts/ollama_api.py generate \
--model qwen3:8b \
--prompt "Explain backlinks in SEO" \
--system "You are an SEO expert" \
--temperature 0.7 \
--num-predict 500
From file:
python skills/ollama/scripts/ollama_api.py generate \
--model qwen3:8b \
--prompt-file data/processed/prompt.txt
Chat Completion
python skills/ollama/scripts/ollama_api.py chat \
--model qwen3:8b \
--messages '[{"role":"user","content":"What is SEO?"}]' \
--temperature 0.7
With system message:
python skills/ollama/scripts/ollama_api.py chat \
--model qwen3:8b \
--messages '[{"role":"system","content":"You are an SEO expert"},{"role":"user","content":"Explain keyword clustering"}]'
From file:
python skills/ollama/scripts/ollama_api.py chat \
--model qwen3:8b \
--messages-file data/processed/conversation.json
With structured JSON output:
python skills/ollama/scripts/ollama_api.py chat \
--model qwen3:8b \
--messages '[{"role":"user","content":"List 3 SEO tools"}]' \
--format json
Bulk Chat (JSONL)
Process multiple requests from a JSONL file:
python skills/ollama/scripts/ollama_api.py chat-bulk \
--model qwen3:8b \
--messages-file prompts.jsonl \
--rate-limit 30
JSONL format:
{"messages":[{"role":"user","content":"Analyze: seo tools"}],"id":"kw_001"}
{"messages":[{"role":"user","content":"Analyze: backlinks"}],"id":"kw_002"}
Embeddings
Requires an embedding model (e.g. nomic-embed-text, mxbai-embed-large). Pull one first:
python skills/ollama/scripts/ollama_api.py pull --model nomic-embed-text
Then generate embeddings:
python skills/ollama/scripts/ollama_api.py embed \
--model nomic-embed-text \
--input "What is search engine optimization?"
From file (one text per line):
python skills/ollama/scripts/ollama_api.py embed \
--model nomic-embed-text \
--input-file texts.txt
Delete a Model
python skills/ollama/scripts/ollama_api.py delete --model llama3.2
Generation Options
Available for generate, chat, and chat-bulk:
| Flag | Description |
|---|---|
--temperature |
Sampling temperature (0-2) |
--top-p |
Nucleus sampling |
--top-k |
Top-k sampling |
--num-predict |
Max tokens to generate |
--num-ctx |
Context window size |
--seed |
Random seed for reproducibility |
--repeat-penalty |
Repetition penalty |
--stop |
Comma-separated stop sequences |
Output Format
All commands return JSON to stdout:
{
"output_files": ["output/ollama_generate_...json"],
"summary": "Generated 150 tokens in 2.3s with qwen3:8b",
"response": "First 500 chars of response...",
"stats": { "model": "qwen3:8b", "eval_count": 150, "total_duration_s": 2.3 }
}
Error Handling
If Ollama is not running, the script exits with code 1 and prints:
{"error": "Cannot connect to Ollama. Is it running? Start with: ollama serve"}