MCPcopy Index your code
hub / github.com/ChatGPTNextWeb/NextChat / collectModelTable

Function collectModelTable

app/utils/model.ts:51–136  ·  view source on GitHub ↗
(
  models: readonly LLMModel[],
  customModels: string,
)

Source from the content-addressed store, hash-verified

49}
50
51export function collectModelTable(
52 models: readonly LLMModel[],
53 customModels: string,
54) {
55 const modelTable: Record<
56 string,
57 {
58 available: boolean;
59 name: string;
60 displayName: string;
61 sorted: number;
62 provider?: LLMModel["provider"]; // Marked as optional
63 isDefault?: boolean;
64 }
65 > = {};
66
67 // default models
68 models.forEach((m) => {
69 // using <modelName>@<providerId> as fullName
70 modelTable[`${m.name}@${m?.provider?.id}`] = {
71 ...m,
72 displayName: m.name, // 'provider' is copied over if it exists
73 };
74 });
75
76 // server custom models
77 customModels
78 .split(",")
79 .filter((v) => !!v && v.length > 0)
80 .forEach((m) => {
81 const available = !m.startsWith("-");
82 const nameConfig =
83 m.startsWith("+") || m.startsWith("-") ? m.slice(1) : m;
84 let [name, displayName] = nameConfig.split("=");
85
86 // enable or disable all models
87 if (name === "all") {
88 Object.values(modelTable).forEach(
89 (model) => (model.available = available),
90 );
91 } else {
92 // 1. find model by name, and set available value
93 const [customModelName, customProviderName] = getModelProvider(name);
94 let count = 0;
95 for (const fullName in modelTable) {
96 const [modelName, providerName] = getModelProvider(fullName);
97 if (
98 customModelName == modelName &&
99 (customProviderName === undefined ||
100 customProviderName === providerName)
101 ) {
102 count += 1;
103 modelTable[fullName]["available"] = available;
104 // swap name and displayName for bytedance
105 if (providerName === "bytedance") {
106 [name, displayName] = [displayName, modelName];
107 modelTable[fullName]["name"] = name;
108 }

Callers 4

collectModelsFunction · 0.85
isModelAvailableInServerFunction · 0.85

Calls 2

getModelProviderFunction · 0.85
customProviderFunction · 0.85

Tested by

no test coverage detected