gen-docs.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "common.h"
  2. #include <fstream>
  3. #include <string>
  4. // Export usage message (-h) to markdown format
  5. static void export_md(std::string fname, llama_example ex) {
  6. std::ofstream file(fname, std::ofstream::out | std::ofstream::trunc);
  7. gpt_params params;
  8. auto options = gpt_params_parser_init(params, ex);
  9. file << "| Argument | Explanation |\n";
  10. file << "| -------- | ----------- |\n";
  11. for (auto & opt : options) {
  12. file << "| `";
  13. // args
  14. for (const auto & arg : opt.args) {
  15. if (arg == opt.args.front()) {
  16. file << arg;
  17. if (opt.args.size() > 1) file << ", ";
  18. } else {
  19. file << arg << (arg != opt.args.back() ? ", " : "");
  20. }
  21. }
  22. // value hint
  23. if (opt.value_hint) {
  24. std::string md_value_hint(opt.value_hint);
  25. string_replace_all(md_value_hint, "|", "\\|");
  26. file << " " << md_value_hint;
  27. }
  28. if (opt.value_hint_2) {
  29. std::string md_value_hint_2(opt.value_hint_2);
  30. string_replace_all(md_value_hint_2, "|", "\\|");
  31. file << " " << md_value_hint_2;
  32. }
  33. // help text
  34. std::string md_help(opt.help);
  35. string_replace_all(md_help, "\n", "<br/>");
  36. string_replace_all(md_help, "|", "\\|");
  37. file << "` | " << md_help << " |\n";
  38. }
  39. }
  40. int main(int, char **) {
  41. export_md("autogen-main.md", LLAMA_EXAMPLE_MAIN);
  42. export_md("autogen-server.md", LLAMA_EXAMPLE_SERVER);
  43. return 0;
  44. }