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;
|
available: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
provider: LLMModel["provider"];
|
provider?: LLMModel["provider"]; // Marked as optional
|
||||||
}
|
}
|
||||||
> = {};
|
> = {};
|
||||||
|
|
||||||
// default models
|
// default models
|
||||||
models.forEach(
|
models.forEach((m) => {
|
||||||
(m) =>
|
modelTable[m.name] = {
|
||||||
(modelTable[m.name] = {
|
|
||||||
...m,
|
...m,
|
||||||
displayName: m.name,
|
displayName: m.name, // 'provider' is copied over if it exists
|
||||||
}),
|
};
|
||||||
);
|
});
|
||||||
|
|
||||||
// server custom models
|
// server custom models
|
||||||
customModels
|
customModels
|
||||||
.split(",")
|
.split(",")
|
||||||
.filter((v) => !!v && v.length > 0)
|
.filter((v) => !!v && v.length > 0)
|
||||||
.map((m) => {
|
.forEach((m) => {
|
||||||
const available = !m.startsWith("-");
|
const available = !m.startsWith("-");
|
||||||
const nameConfig =
|
const nameConfig =
|
||||||
m.startsWith("+") || m.startsWith("-") ? m.slice(1) : m;
|
m.startsWith("+") || m.startsWith("-") ? m.slice(1) : m;
|
||||||
@ -35,15 +34,15 @@ export function collectModelTable(
|
|||||||
|
|
||||||
// enable or disable all models
|
// enable or disable all models
|
||||||
if (name === "all") {
|
if (name === "all") {
|
||||||
Object.values(modelTable).forEach((m) => (m.available = available));
|
Object.values(modelTable).forEach((model) => (model.available = available));
|
||||||
}
|
} else {
|
||||||
|
|
||||||
modelTable[name] = {
|
modelTable[name] = {
|
||||||
name,
|
name,
|
||||||
displayName: displayName || name,
|
displayName: displayName || name,
|
||||||
available,
|
available,
|
||||||
provider: modelTable[name].provider,
|
provider: modelTable[name]?.provider, // Use optional chaining
|
||||||
};
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return modelTable;
|
return modelTable;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user