Allow either "[" or "{" prefix to support JSON grammar with top level arrays (#129)

This commit is contained in:
turboderp 2024-06-04 02:32:39 +02:00 committed by GitHub
parent e889fa3efe
commit dbdcb38ad7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -79,8 +79,11 @@ class ExLlamaV2Grammar:
return
# Allow JSON objects or JSON arrays at the top level
json_prefixes = ["[", "{"]
lmfilter = ExLlamaV2TokenEnforcerFilter(schema_parser, tokenizer)
prefix_filter = ExLlamaV2PrefixFilter(model, tokenizer, "{")
prefix_filter = ExLlamaV2PrefixFilter(model, tokenizer, json_prefixes)
# Append the filters
self.filters.extend([lmfilter, prefix_filter])