Enum Grammar.PredefinedGrammar
- Namespace
- LMKit.TextGeneration.Sampling
- Assembly
- LM-Kit.NET.dll
Defines the types of predefined grammar rules available for use in text generation.
public enum Grammar.PredefinedGrammar
Fields
Json = 0Represents a grammar type for generating JSON objects.
JsonArray = 1Represents a grammar type useful for generating JSON arrays.
JsonStringArray = 2Represents a grammar type useful for generating JSON string arrays.
Arithmetic = 3Represents a grammar type for performing arithmetic operations.
List = 4Represents a grammar type for generating lists.
Boolean = 5Generates boolean values (yes/no, true/false).
Examples
The following example shows how to use predefined grammars to constrain output format:
using LMKit.Model;
using LMKit.TextGeneration;
using LMKit.TextGeneration.Sampling;
LM model = LM.LoadFromModelID("gemma3:4b");
var chat = new MultiTurnConversation(model);
// Force the model to output valid JSON.
chat.Grammar = new Grammar(Grammar.PredefinedGrammar.Json);
// Force the model to output a JSON array.
chat.Grammar = new Grammar(Grammar.PredefinedGrammar.JsonArray);
// Force the model to output a boolean value.
chat.Grammar = new Grammar(Grammar.PredefinedGrammar.Boolean);