Skip to content

Commit e235a30

Browse files
committed
fix azure url query params
1 parent e34d43f commit e235a30

File tree

1 file changed

+24
-5
lines changed
  • packages/openai-adapters/src/apis

1 file changed

+24
-5
lines changed

packages/openai-adapters/src/apis/Azure.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ export class AzureApi extends OpenAIApi {
1616
provider: "openai",
1717
});
1818

19+
const { baseURL, defaultQuery } = this._getAzureBaseURL(azureConfig);
20+
1921
this.openai = new OpenAI({
2022
apiKey: azureConfig.apiKey,
21-
baseURL: this._getAzureBaseURL(azureConfig),
23+
baseURL,
2224
fetch: customFetch(azureConfig.requestOptions),
25+
defaultQuery,
2326
});
2427
}
2528

@@ -32,8 +35,20 @@ export class AzureApi extends OpenAIApi {
3235
return apiType === "azure-openai" || apiType === "azure";
3336
}
3437

35-
private _getAzureBaseURL(config: z.infer<typeof AzureConfigSchema>): string {
36-
const baseURL = new URL(this.apiBase).toString().replace(/\/$/, "");
38+
private _getAzureBaseURL(config: z.infer<typeof AzureConfigSchema>): {
39+
baseURL: string;
40+
defaultQuery: Record<string, string>;
41+
} {
42+
const url = new URL(this.apiBase);
43+
44+
// Copy search params to separate object for OpenAI
45+
const queryParams: Record<string, string> = {};
46+
for (const [key, value] of url.searchParams.entries()) {
47+
queryParams[key] = value;
48+
}
49+
50+
url.pathname = url.pathname.replace(/\/$/, ""); // Remove trailing slash if present
51+
url.search = ""; // Clear original search params
3752

3853
// Default is `azure-openai` in docs, but previously was `azure`
3954
if (this._isAzureOpenAI(config.env?.apiType)) {
@@ -48,11 +63,15 @@ export class AzureApi extends OpenAIApi {
4863
"`env.apiVersion` is a required configuration property for Azure OpenAI",
4964
);
5065
}
66+
url.pathname = `${url.pathname}/openai/deployments/${config.env.deployment}`;
5167

52-
return `${baseURL}/openai/deployments/${config.env.deployment}?api-version=${config.env.apiVersion}`;
68+
queryParams["api-version"] = config.env.apiVersion;
5369
}
5470

55-
return baseURL;
71+
return {
72+
baseURL: url.toString(),
73+
defaultQuery: queryParams,
74+
};
5675
}
5776

5877
/**

0 commit comments

Comments
 (0)