model.ts 921 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { LLMModel } from "../client/api";
  2. export function collectModelTable(
  3. models: readonly LLMModel[],
  4. customModels: string,
  5. ) {
  6. const modelTable: Record<string, boolean> = {};
  7. // default models
  8. models.forEach((m) => (modelTable[m.name] = m.available));
  9. // server custom models
  10. customModels
  11. .split(",")
  12. .filter((v) => !!v && v.length > 0)
  13. .map((m) => {
  14. if (m.startsWith("+")) {
  15. modelTable[m.slice(1)] = true;
  16. } else if (m.startsWith("-")) {
  17. modelTable[m.slice(1)] = false;
  18. } else modelTable[m] = true;
  19. });
  20. return modelTable;
  21. }
  22. /**
  23. * Generate full model table.
  24. */
  25. export function collectModels(
  26. models: readonly LLMModel[],
  27. customModels: string,
  28. ) {
  29. const modelTable = collectModelTable(models, customModels);
  30. const allModels = Object.keys(modelTable).map((m) => ({
  31. name: m,
  32. available: modelTable[m],
  33. }));
  34. return allModels;
  35. }