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

Fix defaultModel undefined error #5071

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Changes from 4 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
25 changes: 19 additions & 6 deletions app/utils/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,25 @@ export function collectModelTableWithDefaultModel(
) {
let modelTable = collectModelTable(models, customModels);
if (defaultModel && defaultModel !== "") {
modelTable[defaultModel] = {
...modelTable[defaultModel],
name: defaultModel,
available: true,
isDefault: true,
};
const [modelName, providerName] = defaultModel.split("@");
if (providerName && providerName != "") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉还是不太严谨:

  1. 首先应该判断defaultModel.includes('@')
  2. 如果是新的配置方式,就判断defaultModel in modelTable,如果在modelTable里面,就设置对应的这一项isDefault=true
  3. 如果是旧的配置方式(实际上这个时候defaultModel就是modelName),走后面的for循环
  4. 在循环中,不应该使用key.startsWith(modelName),应该使用key.split('@').shift() == modelName

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢你的指点,关于

  1. 如果是新的配置方式,就判断defaultModel in modelTable,如果在modelTable里面,就设置对应的这一项isDefault=true

这一点,是否可能存在用户使用了不在modelTable中的provider的情况?我是考虑到可能存在这一点,因此没写defaultModel in modelTable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢你的指点,关于

  1. 如果是新的配置方式,就判断defaultModel in modelTable,如果在modelTable里面,就设置对应的这一项isDefault=true

这一点,是否可能存在用户使用了不在modelTable中的provider的情况?我是考虑到可能存在这一点,因此没写defaultModel in modelTable

好像不会,我们不支持自定义provider,已更正。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以后可能会有计划自定义provider
可能是一种alias的方式,例如都是OpenAI的模式,但是可以同时存在两个openai1 + openai2

但是还是一个构思中的处理方式,还没进入开发阶段

modelTable[defaultModel] = {
...modelTable[defaultModel],
name: modelTable[defaultModel]?.name ?? modelName,
displayName:
modelTable[defaultModel]?.displayName ??
modelName + "(" + providerName + ")",
available: true,
isDefault: true,
};
} else {
for (const key of Object.keys(modelTable)) {
if (modelTable[key].available && key.startsWith(modelName)) {
modelTable[key].isDefault = true;
break;
}
}
}
}
return modelTable;
}
Expand Down
Loading