You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.5 KiB

11 months ago
  1. // Perplexity does not provide a simple REST API to get models,
  2. // so we have a table which we copy from their documentation
  3. // https://docs.perplexity.ai/edit/model-cards that we can
  4. // then parse and get all models from in a format that makes sense
  5. // Why this does not exist is so bizarre, but whatever.
  6. // To run, cd into this directory and run `node parse.mjs`
  7. // copy outputs into the export in ../models.js
  8. // Update the date below if you run this again because Perplexity added new models.
  9. // Last Collected: Jan 23, 2025
  10. // UPDATE: Jan 23, 2025
  11. // The table is no longer available on the website, but Perplexity has deprecated the
  12. // old models so now we can just update the chat_models.txt file with the new models
  13. // manually and then run this script to get the new models.
  14. import fs from "fs";
  15. function parseChatModels() {
  16. const models = {};
  17. const tableString = fs.readFileSync("chat_models.txt", { encoding: "utf-8" });
  18. const rows = tableString.split("\n").slice(2);
  19. rows.forEach((row) => {
  20. let [model, _, contextLength] = row
  21. .split("|")
  22. .slice(1, -1)
  23. .map((text) => text.trim());
  24. model = model.replace(/`|\s*\[\d+\]\s*/g, "");
  25. const maxLength = Number(contextLength.replace(/[^\d]/g, ""));
  26. if (model && maxLength) {
  27. models[model] = {
  28. id: model,
  29. name: model,
  30. maxLength: maxLength,
  31. };
  32. }
  33. });
  34. fs.writeFileSync(
  35. "chat_models.json",
  36. JSON.stringify(models, null, 2),
  37. "utf-8"
  38. );
  39. return models;
  40. }
  41. parseChatModels();