class Llamero::BaseGrammar

Overview

A base class for grammars. Grammars are the expected responses syntax from the LLM. Using a grammar can significantly help improve the consistency of the structured responses while saving on context window tokens.

To create a grammar, inherit from this class and define properties on the child class. All properties will be automatically converted to a grammar syntax. Any properties that use a non-primitive type must inherit from Llamero::BaseGrammar as well.

This class defines the necessary methods for rendering a JSON serializable object into a grammar syntax that can be provided to the LLM at run-time or output to a file.

Included Modules

Direct Known Subclasses

Defined in:

grammars/base_grammar.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(pull : JSON::PullParser) #

[View source]

Class Method Detail

def self.get_grammar_output_for_object : IO #

[View source]

Instance Method Detail

def to_grammar_file(is_root_object : Bool = true) : IO #

Creates the grammar in a format that can be saved into a .gbnf file


[View source]