Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: old AZURE_URL config error: "DeploymentNotFound". #4945 #4930 #4953

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 部署地址。

Expand Down Expand Up @@ -156,6 +157,10 @@ anthropic claude Api Url.

用来控制模型列表,使用 `+` 增加一个模型,使用 `-` 来隐藏一个模型,使用 `模型名=展示名` 来自定义模型的展示名,用英文逗号隔开。

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


### `DEFAULT_MODEL` (可选)

更改默认模型
Expand Down
25 changes: 25 additions & 0 deletions app/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
2 changes: 1 addition & 1 deletion app/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions app/utils/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ export function collectModelTable(
(model) => (model.available = available),
lloydzhou marked this conversation as resolved.
Show resolved Hide resolved
);
} 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) {
Expand Down
Loading