mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-08 06:46:56 +08:00
feat: close #3187 use CUSTOM_MODELS to control model list
This commit is contained in:
40
app/utils/model.ts
Normal file
40
app/utils/model.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { LLMModel } from "../client/api";
|
||||
|
||||
export function collectModelTable(
|
||||
models: readonly LLMModel[],
|
||||
customModels: string,
|
||||
) {
|
||||
const modelTable: Record<string, boolean> = {};
|
||||
|
||||
// default models
|
||||
models.forEach((m) => (modelTable[m.name] = m.available));
|
||||
|
||||
// server custom models
|
||||
customModels
|
||||
.split(",")
|
||||
.filter((v) => !!v && v.length > 0)
|
||||
.map((m) => {
|
||||
if (m.startsWith("+")) {
|
||||
modelTable[m.slice(1)] = true;
|
||||
} else if (m.startsWith("-")) {
|
||||
modelTable[m.slice(1)] = false;
|
||||
} else modelTable[m] = true;
|
||||
});
|
||||
return modelTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate full model table.
|
||||
*/
|
||||
export function collectModels(
|
||||
models: readonly LLMModel[],
|
||||
customModels: string,
|
||||
) {
|
||||
const modelTable = collectModelTable(models, customModels);
|
||||
const allModels = Object.keys(modelTable).map((m) => ({
|
||||
name: m,
|
||||
available: modelTable[m],
|
||||
}));
|
||||
|
||||
return allModels;
|
||||
}
|
Reference in New Issue
Block a user