2024-03-21 11:50:43 +00:00
|
|
|
#pragma once
|
2024-05-08 21:53:08 +02:00
|
|
|
|
|
|
|
|
#include "ggml.h"
|
|
|
|
|
// Change JSON_ASSERT from assert() to GGML_ASSERT:
|
|
|
|
|
#define JSON_ASSERT GGML_ASSERT
|
2024-03-21 11:50:43 +00:00
|
|
|
#include "json.hpp"
|
|
|
|
|
|
2025-02-01 23:55:32 -08:00
|
|
|
std::string json_schema_to_grammar(const nlohmann::ordered_json & schema,
|
|
|
|
|
bool force_gbnf = false);
|
2025-01-22 09:51:44 +00:00
|
|
|
|
2025-01-30 19:13:58 +00:00
|
|
|
struct common_grammar_builder {
|
2025-01-22 09:51:44 +00:00
|
|
|
std::function<std::string(const std::string &, const std::string &)> add_rule;
|
|
|
|
|
std::function<std::string(const std::string &, const nlohmann::ordered_json &)> add_schema;
|
|
|
|
|
std::function<void(nlohmann::ordered_json &)> resolve_refs;
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-30 19:13:58 +00:00
|
|
|
struct common_grammar_options {
|
|
|
|
|
bool dotall = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::string build_grammar(const std::function<void(const common_grammar_builder &)> & cb, const common_grammar_options & options = {});
|