diff --git a/core/llm/llms/OpenAI-compatible.vitest.ts b/core/llm/llms/OpenAI-compatible.vitest.ts index 402fb7e758..6df5b9abf3 100644 --- a/core/llm/llms/OpenAI-compatible.vitest.ts +++ b/core/llm/llms/OpenAI-compatible.vitest.ts @@ -388,6 +388,8 @@ createOpenAISubclassTests(Kindo, { createOpenAISubclassTests(Azure, { providerName: "azure", + customEmbeddingsUrl: + "https://api.openai.com/v1/openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview", }); createOpenAISubclassTests(Inception, { diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index c65b55dc1a..3faeec32cc 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -705,11 +705,14 @@ class OpenAI extends BaseLLM { ); } - if (this.apiType === "azure") { - return new URL( - `openai/deployments/${this.deployment}/embeddings?api-version=${this.apiVersion}`, - this.apiBase, - ); + if (this.apiType?.includes("azure")) { + const isAzureOpenAI = + this.apiType === "azure-openai" || this.apiType === "azure"; + const path = isAzureOpenAI + ? `openai/deployments/${this.deployment}/embeddings` + : "embeddings"; + const version = this.apiVersion ? `?api-version=${this.apiVersion}` : ""; + return new URL(`${path}${version}`, this.apiBase); } return new URL("embeddings", this.apiBase); } diff --git a/core/llm/llms/OpenAI.vitest.ts b/core/llm/llms/OpenAI.vitest.ts index b07f05b15d..575f6bbc23 100644 --- a/core/llm/llms/OpenAI.vitest.ts +++ b/core/llm/llms/OpenAI.vitest.ts @@ -424,4 +424,38 @@ describe("OpenAI", () => { }, }); }); + + test("_getEmbedEndpoint should construct correct Azure deployment URL", () => { + const openai = new OpenAI({ + apiType: "azure-openai", + apiBase: "https://test.openai.azure.com/", + deployment: "gpt-5.4", + apiVersion: "2024-02-15-preview", + model: "gpt-5.4", + apiKey: "test-key", + }); + + const endpoint = (openai as any)["_getEmbedEndpoint"](); + const url = endpoint.toString(); + + expect(url).toContain("openai/deployments/gpt-5.4/embeddings"); + expect(url).toContain("api-version=2024-02-15-preview"); + }); + + test("_getEmbedEndpoint should not use deployment path for azure-foundry", () => { + const openai = new OpenAI({ + apiType: "azure-foundry", + apiBase: "https://test.services.ai.azure.com/", + apiVersion: "2024-05-01-preview", + model: "text-embedding-ada-002", + apiKey: "test-key", + }); + + const endpoint = (openai as any)["_getEmbedEndpoint"](); + const url = endpoint.toString(); + + expect(url).not.toContain("openai/deployments"); + expect(url).toContain("embeddings"); + expect(url).toContain("api-version=2024-05-01-preview"); + }); });