Skip to content

Commit 5295802

Browse files
authored
Merge pull request #4953 from ConnectAI-E/hotfix/azure-deployment-notfound
hotfix: old AZURE_URL config error: "DeploymentNotFound". #4945 #4930
2 parents 7218f13 + 6ac9789 commit 5295802

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ Specify OpenAI organization ID.
181181
### `AZURE_URL` (optional)
182182

183183
> Example: https://{azure-resource-url}/openai/deployments/{deploy-name}
184+
> if you config deployment name in `CUSTOM_MODELS`, you can remove `{deploy-name}` in `AZURE_URL`
184185
185186
Azure deploy url.
186187

@@ -245,6 +246,9 @@ To control custom models, use `+` to add a custom model, use `-` to hide a model
245246

246247
User `-all` to disable all default models, `+all` to enable all default models.
247248

249+
For Azure: use `modelName@azure=deploymentName` to customize model name and deployment name.
250+
> Example: `+gpt-3.5-turbo@azure=gpt35` will show option `gpt35(Azure)` in model list.
251+
248252
### `DEFAULT_MODEL` (optional)
249253

250254
Change default model

README_CN.md

+5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填
9595
### `AZURE_URL` (可选)
9696

9797
> 形如:https://{azure-resource-url}/openai/deployments/{deploy-name}
98+
> 如果你已经在`CUSTOM_MODELS`中参考`displayName`的方式配置了{deploy-name},那么可以从`AZURE_URL`中移除`{deploy-name}`
9899
99100
Azure 部署地址。
100101

@@ -156,6 +157,10 @@ anthropic claude Api Url.
156157
157158
用来控制模型列表,使用 `+` 增加一个模型,使用 `-` 来隐藏一个模型,使用 `模型名=展示名` 来自定义模型的展示名,用英文逗号隔开。
158159

160+
在Azure的模式下,支持使用`modelName@azure=deploymentName`的方式配置模型名称和部署名称(deploy-name)
161+
> 示例:`+gpt-3.5-turbo@azure=gpt35`这个配置会在模型列表显示一个`gpt35(Azure)`的选项
162+
163+
159164
### `DEFAULT_MODEL` (可选)
160165

161166
更改默认模型

app/api/common.ts

+25
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,31 @@ export async function requestOpenai(req: NextRequest) {
6666
"/api/azure/",
6767
"",
6868
)}?api-version=${azureApiVersion}`;
69+
70+
// Forward compatibility:
71+
// if display_name(deployment_name) not set, and '{deploy-id}' in AZURE_URL
72+
// then using default '{deploy-id}'
73+
if (serverConfig.customModels) {
74+
const modelName = path.split("/")[1];
75+
let realDeployName = "";
76+
serverConfig.customModels
77+
.split(",")
78+
.filter((v) => !!v && !v.startsWith("-") && v.includes(modelName))
79+
.forEach((m) => {
80+
const [fullName, displayName] = m.split("=");
81+
const [_, providerName] = fullName.split("@");
82+
if (providerName === "azure" && !displayName) {
83+
const [_, deployId] = serverConfig.azureUrl.split("deployments/");
84+
if (deployId) {
85+
realDeployName = deployId;
86+
}
87+
}
88+
});
89+
if (realDeployName) {
90+
console.log("[Replace with DeployId", realDeployName);
91+
path = path.replaceAll(modelName, realDeployName);
92+
}
93+
}
6994
}
7095

7196
const fetchUrl = `${baseUrl}/${path}`;

app/store/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const DEFAULT_CONFIG = {
4949

5050
modelConfig: {
5151
model: "gpt-3.5-turbo" as ModelType,
52-
providerName: "Openai" as ServiceProvider,
52+
providerName: "OpenAI" as ServiceProvider,
5353
temperature: 0.5,
5454
top_p: 1,
5555
max_tokens: 4000,

app/utils/model.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ export function collectModelTable(
4747
(model) => (model.available = available),
4848
);
4949
} else {
50-
// 1. find model by name(), and set available value
50+
// 1. find model by name, and set available value
51+
const [customModelName, customProviderName] = name.split("@");
5152
let count = 0;
5253
for (const fullName in modelTable) {
53-
if (fullName.split("@").shift() == name) {
54+
const [modelName, providerName] = fullName.split("@");
55+
if (
56+
customModelName == modelName &&
57+
(customProviderName === undefined ||
58+
customProviderName === providerName)
59+
) {
5460
count += 1;
5561
modelTable[fullName]["available"] = available;
5662
if (displayName) {

0 commit comments

Comments
 (0)