Method CreateJsonGrammarFromTextFields
- Namespace
- LMKit.TextGeneration.Sampling
- Assembly
- LM-Kit.NET.dll
CreateJsonGrammarFromTextFields(IEnumerable<string>)
Creates a Grammar instance for constrained text generation based on a collection of JSON text field names. This method generates a grammar that enforces the generation of JSON objects containing the specified fields with string values, ensuring that the output adheres to the defined structure.
public static Grammar CreateJsonGrammarFromTextFields(IEnumerable<string> fields)
Parameters
fields
IEnumerable<string>A collection of strings representing the names of the JSON text fields. Each string corresponds to a field name in the JSON structure that will be enforced by the grammar.
Returns
- Grammar
A new Grammar instance that constrains text generation to produce JSON objects with the specified text fields.
Exceptions
- ArgumentException
Thrown if the
fields
collection is null or empty.