json-schema-to-grammar.h 581 B

12345678910111213141516
  1. #pragma once
  2. #include "ggml.h"
  3. // Change JSON_ASSERT from assert() to GGML_ASSERT:
  4. #define JSON_ASSERT GGML_ASSERT
  5. #include "json.hpp"
  6. std::string json_schema_to_grammar(const nlohmann::ordered_json & schema);
  7. struct llama_grammar_builder {
  8. std::function<std::string(const std::string &, const std::string &)> add_rule;
  9. std::function<std::string(const std::string &, const nlohmann::ordered_json &)> add_schema;
  10. std::function<void(nlohmann::ordered_json &)> resolve_refs;
  11. };
  12. std::string build_grammar(const std::function<void(const llama_grammar_builder &)> & cb);