forked from XiaoMo/ChatGPT-Next-Web
Refactor [Model] [LLM Api] Chaining Model
- [+] refactor(model.ts): change forEach loop to arrow function for readability and consistency - [+] fix(model.ts): mark 'provider' property as optional in modelTable type - [+] fix(model.ts): use optional chaining when assigning provider property in modelTable
This commit is contained in:
parent
8ca525dc7a
commit
e9def2cdc5
@ -10,24 +10,23 @@ export function collectModelTable(
|
||||
available: boolean;
|
||||
name: string;
|
||||
displayName: string;
|
||||
provider: LLMModel["provider"];
|
||||
provider?: LLMModel["provider"]; // Marked as optional
|
||||
}
|
||||
> = {};
|
||||
|
||||
// default models
|
||||
models.forEach(
|
||||
(m) =>
|
||||
(modelTable[m.name] = {
|
||||
models.forEach((m) => {
|
||||
modelTable[m.name] = {
|
||||
...m,
|
||||
displayName: m.name,
|
||||
}),
|
||||
);
|
||||
displayName: m.name, // 'provider' is copied over if it exists
|
||||
};
|
||||
});
|
||||
|
||||
// server custom models
|
||||
customModels
|
||||
.split(",")
|
||||
.filter((v) => !!v && v.length > 0)
|
||||
.map((m) => {
|
||||
.forEach((m) => {
|
||||
const available = !m.startsWith("-");
|
||||
const nameConfig =
|
||||
m.startsWith("+") || m.startsWith("-") ? m.slice(1) : m;
|
||||
@ -35,15 +34,15 @@ export function collectModelTable(
|
||||
|
||||
// enable or disable all models
|
||||
if (name === "all") {
|
||||
Object.values(modelTable).forEach((m) => (m.available = available));
|
||||
}
|
||||
|
||||
Object.values(modelTable).forEach((model) => (model.available = available));
|
||||
} else {
|
||||
modelTable[name] = {
|
||||
name,
|
||||
displayName: displayName || name,
|
||||
available,
|
||||
provider: modelTable[name].provider,
|
||||
provider: modelTable[name]?.provider, // Use optional chaining
|
||||
};
|
||||
}
|
||||
});
|
||||
return modelTable;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user