From 066c595ed71e54d7bce374fa984bf69dfa28cefb Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Wed, 25 Jun 2025 15:44:20 -0700 Subject: [PATCH] test: azure pathname --- .../openai-adapters/src/test/main.test.ts | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/packages/openai-adapters/src/test/main.test.ts b/packages/openai-adapters/src/test/main.test.ts index 1d68a7782..2c8d779b9 100644 --- a/packages/openai-adapters/src/test/main.test.ts +++ b/packages/openai-adapters/src/test/main.test.ts @@ -173,4 +173,80 @@ describe("Configuration", () => { "https://api.example.com", ); }); + + it("should configure Azure OpenAI client with root URL and trailing slash", () => { + const azure = constructLlmApi({ + provider: "azure", + apiKey: "sk-xxx", + apiBase: "https://test-azure-openai.azure.com/", + env: { + deployment: "gpt-4.1", + apiType: "azure-openai", + apiVersion: "2023-05-15", + }, + }); + + // The Azure client modifies the baseURL to include the deployment + expect((azure as OpenAIApi).openai.baseURL).toBe( + "https://test-azure-openai.azure.com/openai/deployments/gpt-4.1", + ); + expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx"); + }); + + it("should configure Azure OpenAI client with path and trailing slash", () => { + const azure = constructLlmApi({ + provider: "azure", + apiKey: "sk-xxx", + apiBase: "https://test-azure-openai.azure.com/v1/", + env: { + deployment: "gpt-4.1", + apiType: "azure-openai", + apiVersion: "2023-05-15", + }, + }); + + // The Azure client modifies the baseURL to include the deployment + expect((azure as OpenAIApi).openai.baseURL).toBe( + "https://test-azure-openai.azure.com/v1/openai/deployments/gpt-4.1", + ); + expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx"); + }); + + it("should configure Azure OpenAI client with root URL and no trailing slash", () => { + const azure = constructLlmApi({ + provider: "azure", + apiKey: "sk-xxx", + apiBase: "https://test-azure-openai.azure.com", + env: { + deployment: "gpt-4.1", + apiType: "azure-openai", + apiVersion: "2023-05-15", + }, + }); + + // The Azure client modifies the baseURL to include the deployment + expect((azure as OpenAIApi).openai.baseURL).toBe( + "https://test-azure-openai.azure.com/openai/deployments/gpt-4.1", + ); + expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx"); + }); + + it("should configure Azure OpenAI client with path and no trailing slash", () => { + const azure = constructLlmApi({ + provider: "azure", + apiKey: "sk-xxx", + apiBase: "https://test-azure-openai.azure.com/v1", + env: { + deployment: "gpt-4.1", + apiType: "azure-openai", + apiVersion: "2023-05-15", + }, + }); + + // The Azure client modifies the baseURL to include the deployment + expect((azure as OpenAIApi).openai.baseURL).toBe( + "https://test-azure-openai.azure.com/v1/openai/deployments/gpt-4.1", + ); + expect((azure as OpenAIApi).openai.apiKey).toBe("sk-xxx"); + }); });