From 7d5d8b400b52b8369e7039edafe63e8fd610579b Mon Sep 17 00:00:00 2001 From: Si Zengyu Date: Fri, 28 Feb 2025 23:23:39 +0800 Subject: [PATCH] fix(provider): update url path handling for azure provider (#1443) Co-authored-by: Zengyu --- crates/goose/src/providers/azure.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/goose/src/providers/azure.rs b/crates/goose/src/providers/azure.rs index a35259fb..415d5b9b 100644 --- a/crates/goose/src/providers/azure.rs +++ b/crates/goose/src/providers/azure.rs @@ -64,10 +64,21 @@ impl AzureProvider { let mut base_url = url::Url::parse(&self.endpoint) .map_err(|e| ProviderError::RequestFailed(format!("Invalid base URL: {e}")))?; - base_url.set_path(&format!( - "openai/deployments/{}/chat/completions", - self.deployment_name - )); + // Get the existing path without trailing slashes + let existing_path = base_url.path().trim_end_matches('/'); + let new_path = if existing_path.is_empty() { + format!( + "/openai/deployments/{}/chat/completions", + self.deployment_name + ) + } else { + format!( + "{}/openai/deployments/{}/chat/completions", + existing_path, self.deployment_name + ) + }; + + base_url.set_path(&new_path); base_url.set_query(Some(&format!("api-version={}", self.api_version))); let response: reqwest::Response = self