refactor(ollama): reuse base normalization in session

This commit is contained in:
2025-10-26 01:33:42 +02:00
parent eef0e3dea0
commit 16bc534837
4 changed files with 16 additions and 6 deletions

View File

@@ -2025,6 +2025,10 @@ fn map_reqwest_error(action: &str, err: reqwest::Error) -> Error {
}
}
pub(crate) fn normalize_cloud_base_url(input: Option<&str>) -> std::result::Result<String, String> {
normalize_base_url(input, OllamaMode::Cloud)
}
fn normalize_base_url(
input: Option<&str>,
mode_hint: OllamaMode,

View File

@@ -19,6 +19,7 @@ use crate::mode::Mode;
use crate::model::{DetailedModelInfo, ModelManager};
use crate::oauth::{DeviceAuthorization, DevicePollState, OAuthClient};
use crate::providers::OllamaProvider;
use crate::providers::ollama::normalize_cloud_base_url;
use crate::storage::{SessionMeta, StorageManager};
use crate::tools::{WEB_SEARCH_TOOL_NAME, canonical_tool_name, tool_name_matches};
use crate::types::{
@@ -187,11 +188,17 @@ fn compute_web_search_settings(
return Ok(None);
}
let base_url = provider_config
let raw_base_url = provider_config
.base_url
.as_deref()
.filter(|value| !value.trim().is_empty())
.unwrap_or(OLLAMA_CLOUD_BASE_URL);
.filter(|value| !value.trim().is_empty());
let normalized_base_url = normalize_cloud_base_url(raw_base_url).map_err(|err| {
let display_base = raw_base_url.unwrap_or(OLLAMA_CLOUD_BASE_URL);
Error::Config(format!(
"Invalid Ollama Cloud base_url '{}': {err}",
display_base
))
})?;
let endpoint = provider_config
.extra
@@ -199,7 +206,7 @@ fn compute_web_search_settings(
.and_then(|value| value.as_str())
.unwrap_or("/api/web_search");
let endpoint_url = build_search_url(base_url, endpoint)?;
let endpoint_url = build_search_url(&normalized_base_url, endpoint)?;
let api_key = resolve_web_search_api_key(provider_config)
.or_else(|| env_var_non_empty(OLLAMA_API_KEY_ENV))

View File

@@ -373,7 +373,7 @@ async fn cloud_tool_call_flows_through_web_search() {
#[tokio::test(flavor = "multi_thread")]
async fn cloud_tool_call_accepts_v1_base_url() {
run_cloud_tool_flow("/v1", Some("/web/search"), "/v1/web/search").await;
run_cloud_tool_flow("/v1", Some("/web/search"), "/web/search").await;
}
#[tokio::test(flavor = "multi_thread")]