[WIP] Fix Ollama port for default models to check from env before using 11434 - #519
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@claude[agent] fix the CI Checks / Commit Messages and the suggestions from co-pilot |
…11434 Check OLLAMA_BASE_URL, OLLAMA_API_BASE and OLLAMA_HOST before falling back to http://localhost:11434, and reuse the resolved value for the local model, embedder, classifier and attack defaults. Co-authored-by: franconicola <51865029+franconicola@users.noreply.github.com>
7e0ce66 to
33d3989
Compare
Done in 33d3989. Squashed the branch into a single commitizen/gitmoji-compliant commit ( Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #483 by centralizing Ollama endpoint resolution so default model endpoints respect environment variables (instead of always defaulting to http://localhost:11434), and updates callers + docs accordingly.
Changes:
- Add
resolve_ollama_base_url()to compute the Ollama base URL from env (OLLAMA_BASE_URL,OLLAMA_API_BASE,OLLAMA_HOST) with normalization. - Replace hardcoded
http://localhost:11434defaults across router/CLI/attack configs with resolved defaults/constants. - Add unit tests and documentation for non-default Ollama ports.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_config.py | Adds unit tests covering env var precedence and normalization for Ollama base URL resolution. |
| hackagent/router/tracking/category_classifier.py | Uses the centralized default category-classifier endpoint constant instead of hardcoding localhost:11434. |
| hackagent/router/_chat_registration.py | Routes Ollama endpoint normalization through resolve_ollama_base_url() for consistent env-aware defaults. |
| hackagent/config.py | Introduces env-aware Ollama base URL resolution and updates default endpoints to be derived from it. |
| hackagent/cli/commands/scan.py | Makes provider endpoint selection fall back to the centralized Ollama base URL resolver. |
| hackagent/cli/commands/examples.py | Uses resolve_ollama_base_url() for example/preflight/default endpoints instead of hardcoded localhost. |
| hackagent/attacks/techniques/pair/attack.py | Replaces attacker/judge default endpoints with DEFAULT_LOCAL_MODEL_ENDPOINT. |
| hackagent/attacks/techniques/indirect_prompt_injection/config.py | Uses DEFAULT_EMBEDDER_OPENAI_ENDPOINT for embedder endpoint defaults. |
| hackagent/attacks/techniques/indirect_prompt_injection/attack.py | Uses DEFAULT_EMBEDDER_OPENAI_ENDPOINT as the fallback embedder endpoint. |
| hackagent/attacks/techniques/advprefix/config.py | Replaces hardcoded generator/judge endpoints with DEFAULT_LOCAL_MODEL_ENDPOINT. |
| docs/docs/agents/ollama.mdx | Documents env vars and behavior for non-default Ollama ports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Only append the default port for a bare http host (no port, not IPv6). | ||
| # https values are left alone so they keep the implicit 443. | ||
| if scheme == "http" and ":" not in authority and not authority.endswith("]"): | ||
| authority = f"{authority}:{DEFAULT_OLLAMA_PORT}" |
| A value without a scheme defaults to `http://`, and a value without a port | ||
| falls back to `11434`. |
Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.