Skip to content

Commit 9c39f07

Browse files
committed
Build azure openai url
1 parent feb8f87 commit 9c39f07

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/Services/OpenAiService.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,30 @@ export class OpenAiService extends BaseAiService implements IAiApiService {
188188
protected showNoTitleInferredNotification(): void {
189189
this.notificationService.showWarning("Could not infer title. The file name was not changed.");
190190
}
191+
192+
/**
193+
* Override getApiEndpoint to handle Azure OpenAI URLs
194+
*
195+
* OpenAI (default):
196+
* https://api.openai.com/v1/chat/completions
197+
* Azure OpenAI (example)
198+
* https://<instance id>.openai.azure.com/openai/deployments/<deployment id>/chat/completions?api-version=<version>
199+
*/
200+
protected getApiEndpoint(config: Record<string, any>): string {
201+
let endpoint = super.getApiEndpoint(config);
202+
const isAzure = config.url.includes(".openai.azure.com");
203+
204+
if (isAzure) {
205+
endpoint = endpoint.replace("/v1", "");
206+
}
207+
208+
if (config.openaiApiVersion) {
209+
const separator = endpoint.includes("?") ? "&" : "?";
210+
endpoint = `${endpoint}${separator}api-version=${config.openaiApiVersion}`;
211+
}
212+
213+
return endpoint;
214+
}
191215
}
192216

193217
export interface OpenAIStreamPayload {

0 commit comments

Comments
 (0)