From b333b06772c89d96aacb5490d6a219fba7c09cc6 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 12 Feb 2026 20:57:17 +0100 Subject: Engage! --- llama.cpp/common/json-schema-to-grammar.h | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 llama.cpp/common/json-schema-to-grammar.h (limited to 'llama.cpp/common/json-schema-to-grammar.h') diff --git a/llama.cpp/common/json-schema-to-grammar.h b/llama.cpp/common/json-schema-to-grammar.h new file mode 100644 index 0000000..240d642 --- /dev/null +++ b/llama.cpp/common/json-schema-to-grammar.h @@ -0,0 +1,43 @@ +#pragma once + +#include + +#include +#include +#include + +std::string json_schema_to_grammar(const nlohmann::ordered_json & schema, + bool force_gbnf = false); + +class common_schema_converter; + +// Probes a JSON schema to extract information about its structure and type constraints. +class common_schema_info { + std::unique_ptr impl_; + + public: + common_schema_info(); + ~common_schema_info(); + + common_schema_info(const common_schema_info &) = delete; + common_schema_info & operator=(const common_schema_info &) = delete; + common_schema_info(common_schema_info &&) noexcept; + common_schema_info & operator=(common_schema_info &&) noexcept; + + void resolve_refs(nlohmann::ordered_json & schema); + bool resolves_to_string(const nlohmann::ordered_json & schema); +}; + +struct common_grammar_builder { + std::function add_rule; + std::function add_schema; + std::function resolve_refs; +}; + +struct common_grammar_options { + bool dotall = false; +}; + +std::string gbnf_format_literal(const std::string & literal); + +std::string build_grammar(const std::function & cb, const common_grammar_options & options = {}); -- cgit v1.2.3