1
0

gen-docs.cpp 1.5 KB

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