Update common.ts

This commit is contained in:
Richard C Lim 2025-02-02 17:50:25 -05:00 committed by GitHub
parent 0e8062ce07
commit 97b6eaa38a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -49,6 +49,7 @@ const isAzure = req.nextUrl.pathname.includes("azure/deployments") || Boolean(se
); );
if (isAzure) { if (isAzure) {
console.log("[Original Path]", req.nextUrl.pathname); // Log initial path
// const isAIFoundation = serverConfig.azureUrl?.includes(".models.ai.azure.com"); // const isAIFoundation = serverConfig.azureUrl?.includes(".models.ai.azure.com");
const azureApiVersion = const azureApiVersion =
req?.nextUrl?.searchParams?.get("api-version") || req?.nextUrl?.searchParams?.get("api-version") ||
@ -57,19 +58,21 @@ const isAzure = req.nextUrl.pathname.includes("azure/deployments") || Boolean(se
if (isAIFoundation) { if (isAIFoundation) {
// For AI Foundation models, use direct path without deployments // For AI Foundation models, use direct path without deployments
// failed to work. path = "chat/completions"; // failed to work. path = "chat/completions";
path = req.nextUrl.pathname path = "chat/completions";
/* path = req.nextUrl.pathname
.replace("/api/azure/openai/", "") .replace("/api/azure/openai/", "")
.replace("/deployments/", "") .replace("/deployments/", "")
.split("/") .split("/")
.slice(-2) .slice(-2)
.join("/"); .join("/");
*/
} else { } else {
baseUrl = baseUrl.split("/deployments").shift() as string; baseUrl = baseUrl.split("/deployments").shift() as string;
path = `${req.nextUrl.pathname.replaceAll( path = `${req.nextUrl.pathname.replaceAll(
"/api/azure/", "/api/azure/",
"", "",
)}?api-version=${azureApiVersion}`; )}?api-version=${azureApiVersion}`;
console.log("[Azure OpenAI Path]", path);
// Forward compatibility: // Forward compatibility:
// if display_name(deployment_name) not set, and '{deploy-id}' in AZURE_URL // if display_name(deployment_name) not set, and '{deploy-id}' in AZURE_URL
// then using default '{deploy-id}' // then using default '{deploy-id}'