From 71af2628eb8d791070fc2b4818f6f46c9068c962 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Tue, 9 Jul 2024 00:32:18 +0800 Subject: [PATCH 1/3] hotfix: old AZURE_URL config error: "DeploymentNotFound". #4945 #4930 --- app/api/common.ts | 25 +++++++++++++++++++++++++ app/utils/model.ts | 10 ++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index b2fae6df24f..5223646d264 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -66,6 +66,31 @@ export async function requestOpenai(req: NextRequest) { "/api/azure/", "", )}?api-version=${azureApiVersion}`; + + // Forward compatibility: + // if display_name(deployment_name) not set, and '{deploy-id}' in AZURE_URL + // then using default '{deploy-id}' + if (serverConfig.customModels) { + const modelName = path.split("/")[1]; + let realDeployName = ""; + serverConfig.customModels + .split(",") + .filter((v) => !!v && !v.startsWith("-") && v.includes(modelName)) + .forEach((m) => { + const [fullName, displayName] = m.split("="); + const [_, providerName] = fullName.split("@"); + if (providerName === "azure" && !displayName) { + const [_, deployId] = serverConfig.azureUrl.split("deployments/"); + if (deployId) { + realDeployName = deployId; + } + } + }); + if (realDeployName) { + console.log("[Replace with DeployId", realDeployName); + path = path.replaceAll(modelName, realDeployName); + } + } } const fetchUrl = `${baseUrl}/${path}`; diff --git a/app/utils/model.ts b/app/utils/model.ts index 249987726ad..0b160f1013b 100644 --- a/app/utils/model.ts +++ b/app/utils/model.ts @@ -47,10 +47,16 @@ export function collectModelTable( (model) => (model.available = available), ); } else { - // 1. find model by name(), and set available value + // 1. find model by name, and set available value + const [customModelName, customProviderName] = name.split("@"); let count = 0; for (const fullName in modelTable) { - if (fullName.split("@").shift() == name) { + const [modelName, providerName] = fullName.split("@"); + if ( + customModelName == modelName && + (customProviderName === undefined || + customProviderName === providerName) + ) { count += 1; modelTable[fullName]["available"] = available; if (displayName) { From 34ab37f31e1fe968c86a4ddc8421a1bfe6a20a27 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Tue, 9 Jul 2024 00:47:35 +0800 Subject: [PATCH 2/3] update CUSTOM_MODELS config for Azure mode. --- README.md | 4 ++++ README_CN.md | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index c77d2023c97..2cac1088a6b 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ Specify OpenAI organization ID. ### `AZURE_URL` (optional) > Example: https://{azure-resource-url}/openai/deployments/{deploy-name} +> if you config deployment name in `CUSTOM_MODELS`, you can remove `{deploy-name}` in `AZURE_URL` Azure deploy url. @@ -245,6 +246,9 @@ To control custom models, use `+` to add a custom model, use `-` to hide a model User `-all` to disable all default models, `+all` to enable all default models. +For Azure: use `modelName@azure=deploymentName` to customize model name and deployment name. +> Example: `+gpt-3.5-turbo@azure=gpt35` will show option `gpt35(Azure)` in model list. + ### `DEFAULT_MODEL` (optional) Change default model diff --git a/README_CN.md b/README_CN.md index 970ecdef2f9..c6cbf653978 100644 --- a/README_CN.md +++ b/README_CN.md @@ -95,6 +95,7 @@ OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填 ### `AZURE_URL` (可选) > 形如:https://{azure-resource-url}/openai/deployments/{deploy-name} +> 如果你已经在`CUSTOM_MODELS`中参考`displayName`的方式配置了{deploy-name},那么可以从`AZURE_URL`中移除`{deploy-name}` Azure 部署地址。 @@ -156,6 +157,10 @@ anthropic claude Api Url. 用来控制模型列表,使用 `+` 增加一个模型,使用 `-` 来隐藏一个模型,使用 `模型名=展示名` 来自定义模型的展示名,用英文逗号隔开。 +在Azure的模式下,支持使用`modelName@azure=deploymentName`的方式配置模型名称和部署名称(deploy-name) +> 示例:`+gpt-3.5-turbo@azure=gpt35`这个配置会在模型列表显示一个`gpt35(Azure)`的选项 + + ### `DEFAULT_MODEL` (可选) 更改默认模型 From 6ac9789a1c4065c19cdd1bab7a808fbc54c0b1a2 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Tue, 9 Jul 2024 12:16:37 +0800 Subject: [PATCH 3/3] hotfix --- app/store/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/store/config.ts b/app/store/config.ts index 4b0a34f4f08..1eaafe12b1d 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -49,7 +49,7 @@ export const DEFAULT_CONFIG = { modelConfig: { model: "gpt-3.5-turbo" as ModelType, - providerName: "Openai" as ServiceProvider, + providerName: "OpenAI" as ServiceProvider, temperature: 0.5, top_p: 1, max_tokens: 4000,