common: utils to split / join / repeat strings (from json converter) (#11342)

* Factor string_join, string_split, string_repeat into common

* json: refactor to surface a versatile builder

* Update common.cpp
This commit is contained in:
Olivier Chafik 2025-01-22 09:51:44 +00:00 committed by GitHub
parent 3e3357fd77
commit a94f3b2727
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 90 additions and 64 deletions

View file

@ -5,4 +5,12 @@
#define JSON_ASSERT GGML_ASSERT
#include "json.hpp"
std::string json_schema_to_grammar(const nlohmann::ordered_json& schema);
std::string json_schema_to_grammar(const nlohmann::ordered_json & schema);
struct llama_grammar_builder {
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;
};
std::string build_grammar(const std::function<void(const llama_grammar_builder &)> & cb);