mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-08-31 17:41:26 +02:00
d9f918d2d0
* add common/json * migrate common * adapt jinja * migrate server * big wip * migrate tests * wip * revert some excessive changes * wip * wip 2 * revert redundant changes * fix server crash * various fixes * fix ci * harden a bit * clean up * rm json-shim * add some comments * rm redundant decl
44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "json.h"
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
std::string json_schema_to_grammar(const common_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<common_schema_converter> 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(common_json & schema);
|
|
bool resolves_to_string(const common_json & schema);
|
|
};
|
|
|
|
struct common_grammar_builder {
|
|
std::function<std::string(const std::string &, const std::string &)> add_rule;
|
|
std::function<std::string(const std::string &, const common_json &)> add_schema;
|
|
std::function<void(common_json &)> 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<void(const common_grammar_builder &)> & cb, const common_grammar_options & options = {});
|