From da136453d38a15957abf8feffe57f221c88e5607 Mon Sep 17 00:00:00 2001 From: CyberSecurityUP Date: Sat, 14 Nov 2026 12:17:28 -0300 Subject: [PATCH] fix(harness): resolve Ollama 404 by auto-appending /v1 to base URL OLLAMA_BASE_URL without the /v1 suffix produced requests to /chat/completions instead of /v1/chat/completions, causing every Ollama call to 404. Also default to the provider's first listed model when --model ollama: is passed with an empty model name. Closes #52 --- neurosploit-rs/crates/harness/src/models.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/neurosploit-rs/crates/harness/src/models.rs b/neurosploit-rs/crates/harness/src/models.rs index 41db9d0..930d72b 100644 --- a/neurosploit-rs/crates/harness/src/models.rs +++ b/neurosploit-rs/crates/harness/src/models.rs @@ -120,7 +120,13 @@ pub struct ModelRef { impl ModelRef { pub fn parse(s: &str) -> ModelRef { match s.split_once(':') { - Some((p, m)) => ModelRef { provider: p.to_string(), model: m.to_string() }, + Some((p, m)) if !m.is_empty() => ModelRef { provider: p.to_string(), model: m.to_string() }, + Some((p, _)) => { + let model = provider_for(p) + .and_then(|prov| prov.models.first().map(|s| s.to_string())) + .unwrap_or_default(); + ModelRef { provider: p.to_string(), model } + } None => ModelRef { provider: "anthropic".into(), model: s.to_string() }, } } @@ -187,7 +193,11 @@ impl ChatClient { // Allow an env base-URL override (LiteLLM gateway, self-hosted proxies, …). let base = match p.key { "litellm" => std::env::var("LITELLM_BASE_URL").unwrap_or_else(|_| p.base_url.to_string()), - "ollama" => std::env::var("OLLAMA_BASE_URL").unwrap_or_else(|_| p.base_url.to_string()), + "ollama" => { + let raw = std::env::var("OLLAMA_BASE_URL").unwrap_or_else(|_| p.base_url.to_string()); + let trimmed = raw.trim_end_matches('/'); + if trimmed.ends_with("/v1") { raw } else { format!("{trimmed}/v1") } + } "llamacpp" => std::env::var("LLAMACPP_BASE_URL").unwrap_or_else(|_| p.base_url.to_string()), _ => p.base_url.to_string(), };