Table of Contents

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 = 0

Represents a grammar type for generating JSON objects.

JsonArray = 1

Represents a grammar type useful for generating JSON arrays.

JsonStringArray = 2

Represents a grammar type useful for generating JSON string arrays.

Arithmetic = 3

Represents a grammar type for performing arithmetic operations.

List = 4

Represents a grammar type for generating lists.

Boolean = 5

Generates 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);
Share