use '%llguidance' as marker to enable llg lark syntax

This commit is contained in:
Michal Moskal 2025-01-25 16:57:28 -08:00
parent f4dc4b89fa
commit afb6cac5ab
3 changed files with 4 additions and 10 deletions

View file

@ -96,7 +96,7 @@ if (LLAMA_LLGUIDANCE)
set(LLGUIDANCE_PATH ${LLGUIDANCE_SRC}/target/release) set(LLGUIDANCE_PATH ${LLGUIDANCE_SRC}/target/release)
ExternalProject_Add(llguidance_ext ExternalProject_Add(llguidance_ext
GIT_REPOSITORY https://github.com/guidance-ai/llguidance GIT_REPOSITORY https://github.com/guidance-ai/llguidance
GIT_TAG 0cbe6b3a6ee72e5726c76f13fe67e21a5895f679 GIT_TAG d7b382916c466e6f26869671b8480229dc930423
PREFIX ${CMAKE_BINARY_DIR}/llguidance PREFIX ${CMAKE_BINARY_DIR}/llguidance
SOURCE_DIR ${LLGUIDANCE_SRC} SOURCE_DIR ${LLGUIDANCE_SRC}
BUILD_IN_SOURCE TRUE BUILD_IN_SOURCE TRUE

View file

@ -992,7 +992,7 @@ public:
std::string json_schema_to_grammar(const json & schema) { std::string json_schema_to_grammar(const json & schema) {
#ifdef LLAMA_USE_LLGUIDANCE #ifdef LLAMA_USE_LLGUIDANCE
return "llg:json:" + schema.dump(); return "%llguidance {}\nstart: %json " + schema.dump();
#else #else
return build_grammar([&](const llama_grammar_builder & callbacks) { return build_grammar([&](const llama_grammar_builder & callbacks) {
auto copy = schema; auto copy = schema;

View file

@ -152,15 +152,9 @@ struct common_sampler * common_sampler_init(const struct llama_model * model, co
lparams.no_perf = params.no_perf; lparams.no_perf = params.no_perf;
struct llama_sampler * grmr; struct llama_sampler * grmr;
if (params.grammar.compare(0, 4, "llg:") == 0) { if (params.grammar.compare(0, 11, "%llguidance") == 0) {
#ifdef LLAMA_USE_LLGUIDANCE #ifdef LLAMA_USE_LLGUIDANCE
auto gp = params.grammar.find(':', 4); grmr = llama_sampler_init_llg(model, "lark", params.grammar.c_str());
if (gp == std::string::npos) {
GGML_ABORT("invalid serialized grammar");
}
auto grm_type = params.grammar.substr(4, gp - 4);
auto grm_data = params.grammar.c_str() + gp + 1;
grmr = llama_sampler_init_llg(model, grm_type.c_str(), grm_data);
#else #else
GGML_ABORT("llguidance (cmake -DLLAMA_LLGUIDANCE=ON) is not enabled"); GGML_ABORT("llguidance (cmake -DLLAMA_LLGUIDANCE=ON) is not enabled");
#endif #endif