llama.cpp/common
Joe Eli McIlvain 66c2c93082
grammar : fix JSON Schema for string regex with top-level alt. (#9903)
Prior to this commit, using a JSON Schema containing a string
with `pattern` regular expression that uses top-level alternation
(e.g. `"pattern": "^A|B|C|D$"`) would result in invalid JSON
output from the constrained sampling grammar, because it
ended up creating a grammar rule like this for the string:

```
thing ::= "\"" "A" | "B" | "C" | "D" "\"" space
```

Note that this rule will only match a starting quote for the "A" case,
and will only match an ending quote for the "D" case,
so this rule will always produce invalid JSON when used for sampling
(that is, the JSON will always be lacking the starting quote,
the ending quote, or both).

This was fixed in a simple way by adding parentheses to the
generated rule (for all string pattern rules, to keep it simple),
such that the new generated rule looks like this (correct):

```
thing ::= "\"" ("A" | "B" | "C" | "D") "\"" space
```
2024-10-16 19:03:24 +03:00
..
cmake llama : reorganize source code + improve CMake (#8006) 2024-06-26 18:33:02 +03:00
arg.cpp sampling : add XTC sampler (#9742) 2024-10-15 12:54:55 +02:00
arg.h common : use common_ prefix for common library functions (#9805) 2024-10-10 22:57:42 +02:00
base64.hpp llava : expose as a shared library for downstream projects (#3613) 2023-11-07 00:36:23 +03:00
build-info.cpp.in build : link against build info instead of compiling against it (#3879) 2023-11-02 08:50:16 +02:00
CMakeLists.txt common : reimplement logging (#9418) 2024-09-15 20:46:12 +03:00
common.cpp sampling : add XTC sampler (#9742) 2024-10-15 12:54:55 +02:00
common.h llama : add infill sampler (#9896) 2024-10-15 16:35:33 +03:00
console.cpp console : utf-8 fix for windows stdin (#9690) 2024-09-30 11:23:42 +03:00
console.h gguf : new file format with flexible meta data (beta) (#2398) 2023-08-21 23:07:43 +03:00
json-schema-to-grammar.cpp grammar : fix JSON Schema for string regex with top-level alt. (#9903) 2024-10-16 19:03:24 +03:00
json-schema-to-grammar.h JSON: [key] -> .at(key), assert() -> GGML_ASSERT (#7143) 2024-05-08 21:53:08 +02:00
json.hpp json-schema-to-grammar improvements (+ added to server) (#5978) 2024-03-21 11:50:43 +00:00
log.cpp common : use common_ prefix for common library functions (#9805) 2024-10-10 22:57:42 +02:00
log.h common : use common_ prefix for common library functions (#9805) 2024-10-10 22:57:42 +02:00
ngram-cache.cpp common : use common_ prefix for common library functions (#9805) 2024-10-10 22:57:42 +02:00
ngram-cache.h common : use common_ prefix for common library functions (#9805) 2024-10-10 22:57:42 +02:00
sampling.cpp llama : add infill sampler (#9896) 2024-10-15 16:35:33 +03:00
sampling.h common : use common_ prefix for common library functions (#9805) 2024-10-10 22:57:42 +02:00
stb_image.h common : Update stb_image.h to latest version (#9161) 2024-08-27 08:58:50 +03:00
train.cpp common : reimplement logging (#9418) 2024-09-15 20:46:12 +03:00
train.h sync : ggml (backend v2) (#3912) 2023-11-13 14:16:23 +02:00