diff --git a/backend/windmill-common/src/ai_providers.rs b/backend/windmill-common/src/ai_providers.rs index 48b2ef8281..b156002dc8 100644 --- a/backend/windmill-common/src/ai_providers.rs +++ b/backend/windmill-common/src/ai_providers.rs @@ -39,8 +39,8 @@ impl AIProvider { region: Option, db: &DB, ) -> Result { - // If a base URL is provided in the resource, use it - if let Some(base_url) = resource_base_url { + // If a base URL is provided in the resource, use it (ignore empty strings) + if let Some(base_url) = resource_base_url.filter(|s| !s.is_empty()) { return Ok(base_url); } @@ -74,29 +74,25 @@ impl AIProvider { AIProvider::TogetherAI => Ok("https://api.together.xyz/v1".to_string()), AIProvider::Anthropic => Ok("https://api.anthropic.com/v1".to_string()), AIProvider::Mistral => Ok("https://api.mistral.ai/v1".to_string()), - p @ (AIProvider::CustomAI | AIProvider::AzureOpenAI) => { - if let Some(base_url) = resource_base_url { - Ok(base_url) - } else { - Err(Error::BadRequest(format!( - "{:?} provider requires a base URL in the resource", - p - ))) - } - } + p @ (AIProvider::CustomAI | AIProvider::AzureOpenAI) => Err(Error::BadRequest( + format!("{:?} provider requires a base URL in the resource", p), + )), AIProvider::AWSBedrock => { #[cfg(feature = "bedrock")] { Ok(format!( "https://bedrock-runtime.{}.amazonaws.com", - region.unwrap_or_else(|| "us-east-1".to_string()) + region + .filter(|s| !s.is_empty()) + .unwrap_or_else(|| "us-east-1".to_string()) )) } #[cfg(not(feature = "bedrock"))] { let _ = region; Err(Error::BadRequest( - "AWS Bedrock support is not enabled. Build with 'bedrock' feature.".to_string() + "AWS Bedrock support is not enabled. Build with 'bedrock' feature." + .to_string(), )) } }