Ollama Integration Guide¶
CodeOptiX supports local Ollama models, allowing you to run evaluations without API keys! โ Now working correctly - generates code and provides proper security evaluations.
๐ฏ Why Ollama?¶
- โ No API key required - Perfect for open-source users
- โ Privacy-friendly - All processing happens locally
- โ Free to use - No cloud costs
- โ Works offline - No internet connection needed
- โ Flexible models - Choose from many open-source models
โ Recent Updates¶
CodeOptiX now works correctly with Ollama! Recent fixes ensure:
- โ Proper code generation (not conversational responses)
- โ Accurate security evaluations (detects real issues)
- โ Meaningful scores (not always 100%)
- โ Full evaluation pipeline support
๐ Try the Demo¶
Test the Ollama integration with our interactive demo:
This demo shows Ollama generating code, detecting security issues, and providing proper evaluation scores.
๐ฆ Installation¶
Step 1: Install Ollama¶
Visit https://ollama.com and install Ollama for your platform:
# macOS
brew install ollama
# Linux
curl -fsSL https://ollama.com/install.sh | sh
# Windows
# Download from https://ollama.com/download
Step 2: Start Ollama Service¶
This starts the Ollama service on http://localhost:11434 (default).
Step 3: Pull a Model¶
Pull a model you want to use:
# Recommended models for CodeOptiX
ollama pull llama3.1:8b # Fast, efficient (4.9 GB)
ollama pull qwen3:8b # Alternative 8B model (5.2 GB)
ollama pull gpt-oss:120b # Large, powerful (65 GB)
ollama pull gpt-oss:20b # Medium model (13 GB)
ollama pull llama3.2:3b # Lightweight (2.0 GB)
See available models:
๐ Quick Start¶
Basic Usage¶
With Configuration File¶
Create ollama-config.yaml:
adapter:
llm_config:
provider: ollama
model: llama3.1:8b # Or gpt-oss:120b, qwen3:8b, etc.
# No api_key needed!
evaluation:
scenario_generator:
num_scenarios: 2
use_bloom: false
behaviors:
insecure-code:
enabled: true
Run:
codeoptix eval \
--agent basic \
--behaviors insecure-code \
--config ollama-config.yaml \
--llm-provider ollama
โ๏ธ Configuration¶
In Config File¶
Via Environment Variable¶
Custom Ollama URL¶
By default, Ollama runs on http://localhost:11434. To use a different URL:
export OLLAMA_BASE_URL=http://localhost:11434
# Or use a remote Ollama instance
export OLLAMA_BASE_URL=http://remote-server:11434
๐ Available Models¶
Recommended Models¶
| Model | Size | Speed | Quality | Use Case |
|---|---|---|---|---|
llama3.2:3b | 2.0 GB | โกโกโกโก | โญโญโญโญ | Best for CodeOptiX - Fast, reliable code generation |
llama3.1:8b | 4.9 GB | โกโกโก | โญโญโญ | Good balance, works well |
qwen3:8b | 5.2 GB | โกโกโก | โญโญโญ | Alternative 8B model |
gpt-oss:20b | 13 GB | โกโก | โญโญโญโญ | High quality, slower |
gpt-oss:120b | 65 GB | โก | โญโญโญโญโญ | Best quality, requires powerful hardware |
List Available Models¶
Pull a Model¶
๐ก Usage Examples¶
Example 1: Try the Interactive Demo โญ¶
See Ollama working in action:
This demo shows code generation, security evaluation, and proper scoring.
Example 2: Basic Evaluation¶
Example 3: With Custom Config¶
codeoptix eval \
--agent basic \
--behaviors insecure-code \
--config examples/configs/ollama-insecure-code.yaml \
--llm-provider ollama
Example 4: Multiple Behaviors¶
Example 5: Verbose Output¶
Example 6: CI/CD Integration¶
# .github/workflows/codeoptix.yml
name: CodeOptiX Check
on: [pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Ollama
run: |
curl -fsSL https://ollama.com/install.sh | sh
ollama pull llama3.1:8b
- name: Install CodeOptiX
run: pip install codeoptix
- name: Run CodeOptiX
run: |
codeoptix ci \
--agent basic \
--behaviors insecure-code \
--llm-provider ollama \
--fail-on-failure
๐ง Troubleshooting¶
Ollama Not Running¶
Error: Failed to contact Ollama at http://localhost:11434
Solution:
Model Not Found¶
Error: Model not available
Solution:
Connection Timeout¶
Error: Timeout when calling Ollama
Solution: - Large models (like gpt-oss:120b) may take longer - CodeOptiX uses a 300-second timeout by default - Ensure you have enough RAM for the model - Try a smaller model if timeouts persist
Custom Port¶
If Ollama is running on a different port:
๐ Ollama vs Cloud Providers¶
| Feature | Ollama | Cloud Providers |
|---|---|---|
| API Key | โ Not required | โ Required |
| Cost | โ Free | โ ๏ธ Pay per use |
| Privacy | โ Local only | โ ๏ธ Data sent externally |
| Internet | โ Works offline | โ Requires connection |
| Setup | โ ๏ธ Install Ollama | โ Just API key |
| Models | โ ๏ธ Limited to local | โ Many options |
| Speed | โ ๏ธ Depends on hardware | โ Fast (cloud) |
Choose Ollama if: - You want privacy - You want to avoid API costs - You have sufficient local compute - You want to work offline
Choose Cloud Providers if: - You need the latest models - You don't have local compute - You need maximum speed - You're okay with API costs
โ ๏ธ Known Limitations¶
Evolution Support¶
- Limited support for
codeoptix evolve: The evolution feature uses GEPA optimization, which requires processing very long prompts. Ollama may fail with timeouts on complex evolution tasks. - Recommendation: Use cloud providers (OpenAI, Anthropic, Google) for full evolution capabilities.
Performance Considerations¶
- Large models (e.g.,
gpt-oss:120b) require significant RAM and may be slow on consumer hardware - Evolution tasks are computationally intensive and may not complete reliably with Ollama
For advanced features like evolution, consider cloud providers or contact us for tailored enterprise solutions.
๐ Next Steps¶
๐ Issues?¶
If you encounter problems:
- Check Troubleshooting above
- Verify Ollama is running:
ollama list - Check model is pulled:
ollama list - Open an issue on GitHub