mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-23 04:09:49 +00:00
fix(models): store provider custom models by provider scope
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
function modelType(model) {
|
||||
return model?.kind || model?.type || "llm";
|
||||
}
|
||||
|
||||
export function getProviderCustomModelRows({
|
||||
customModels = [],
|
||||
modelAliases = {},
|
||||
providerAlias,
|
||||
builtInModels = [],
|
||||
type = "llm",
|
||||
includeLegacyAliases = true,
|
||||
}) {
|
||||
const builtInIds = new Set(builtInModels.map((model) => model.id));
|
||||
const seenFullModels = new Set();
|
||||
const rows = [];
|
||||
|
||||
for (const model of customModels) {
|
||||
if (!model?.id || model.providerAlias !== providerAlias) continue;
|
||||
const rowType = modelType(model);
|
||||
if (type && rowType !== type) continue;
|
||||
if (builtInIds.has(model.id)) continue;
|
||||
|
||||
const fullModel = `${providerAlias}/${model.id}`;
|
||||
if (seenFullModels.has(fullModel)) continue;
|
||||
seenFullModels.add(fullModel);
|
||||
rows.push({
|
||||
id: model.id,
|
||||
name: model.name || model.id,
|
||||
fullModel,
|
||||
source: "custom",
|
||||
type: rowType,
|
||||
});
|
||||
}
|
||||
|
||||
if (!includeLegacyAliases) return rows;
|
||||
|
||||
const prefix = `${providerAlias}/`;
|
||||
for (const [alias, fullModel] of Object.entries(modelAliases || {})) {
|
||||
if (typeof fullModel !== "string" || !fullModel.startsWith(prefix)) continue;
|
||||
const id = fullModel.slice(prefix.length);
|
||||
if (!id || builtInIds.has(id) || seenFullModels.has(fullModel)) continue;
|
||||
|
||||
seenFullModels.add(fullModel);
|
||||
rows.push({
|
||||
id,
|
||||
alias,
|
||||
fullModel,
|
||||
source: "legacyAlias",
|
||||
type: type || "llm",
|
||||
});
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
Reference in New Issue
Block a user