mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix: resolve the issue same id component
This commit is contained in:
@@ -21,8 +21,14 @@ function groupModelsByProvider(models) {
|
|||||||
groups[key] = {
|
groups[key] = {
|
||||||
provider: model.provider,
|
provider: model.provider,
|
||||||
models: [],
|
models: [],
|
||||||
|
modelIds: new Set(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The API normally supplies unique models. Ignore a duplicate defensively
|
||||||
|
// so a malformed response cannot produce duplicate React keys.
|
||||||
|
if (groups[key].modelIds.has(model.fullModel)) return groups;
|
||||||
|
groups[key].modelIds.add(model.fullModel);
|
||||||
groups[key].models.push(model);
|
groups[key].models.push(model);
|
||||||
return groups;
|
return groups;
|
||||||
}, {});
|
}, {});
|
||||||
|
|||||||
@@ -32,9 +32,20 @@ export function isValidModel(aliasOrId, modelId) {
|
|||||||
return models.some(m => m.id === modelId);
|
return models.some(m => m.id === modelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy AI_MODELS for backward compatibility
|
// Legacy AI_MODELS for backward compatibility. A model can be declared under
|
||||||
|
// multiple service kinds (for example, Gemini chat and speech-to-text), but
|
||||||
|
// this flat catalog has no kind field. Keep its provider/model identity unique.
|
||||||
|
const seenModelIds = new Set();
|
||||||
|
|
||||||
export const AI_MODELS = Object.entries(MODELS).flatMap(([alias, models]) =>
|
export const AI_MODELS = Object.entries(MODELS).flatMap(([alias, models]) =>
|
||||||
models.map(m => ({ provider: alias, model: m.id, name: m.name }))
|
models
|
||||||
|
.filter((model) => {
|
||||||
|
const modelKey = `${alias}/${model.id}`;
|
||||||
|
if (seenModelIds.has(modelKey)) return false;
|
||||||
|
seenModelIds.add(modelKey);
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.map((model) => ({ provider: alias, model: model.id, name: model.name }))
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getModelKind = (m, fallback = null) => m?.kind || m?.type || fallback;
|
export const getModelKind = (m, fallback = null) => m?.kind || m?.type || fallback;
|
||||||
|
|||||||
Reference in New Issue
Block a user