sample: add nil check for grammar

This commit is contained in:
ParthSareen 2025-04-03 11:37:51 -07:00
parent 106592820d
commit ad9791da2e

View File

@ -171,6 +171,9 @@ type Grammar struct {
func NewGrammar(vocab *model.Vocabulary, grammarStr string) (*Grammar, error) {
grammar := llama.InitGrammarChain(grammarStr)
if grammar == nil {
return nil, errors.New("sample: failed to initialize grammar")
}
for _, s := range vocab.Values {
id := vocab.Encode(s)
grammar.AddSymbol(s, uint32(id))