File size: 921 Bytes
f0499d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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;
}