Table of Contents

Method CreateJsonGrammarFromFields

Namespace
LMKit.TextGeneration.Sampling
Assembly
LM-Kit.NET.dll

CreateJsonGrammarFromFields(IEnumerable<string>, IEnumerable<ElementType>)

Creates a Grammar instance for constrained text generation based on a collection of JSON field names and their corresponding data types. This method generates a grammar that enforces the generation of JSON objects containing the specified fields with the specified data types, ensuring that the output adheres to the defined structure and types.

public static Grammar CreateJsonGrammarFromFields(IEnumerable<string> fieldNames, IEnumerable<ElementType> fieldTypes)

Parameters

fieldNames IEnumerable<string>

A collection of strings representing the names of the JSON fields to include in the grammar. Each string corresponds to a field name that will be enforced in the generated JSON output.

fieldTypes IEnumerable<ElementType>

A collection of ElementType objects representing the data types associated with each JSON field name. The order of types should correspond to the order of field names in fieldNames.

Returns

Grammar

A new Grammar instance that constrains text generation to produce JSON objects with the specified fields and data types.

Exceptions

ArgumentException

Thrown if the fieldNames collection is null or empty.