Method CreateJsonGrammarFromJsonScheme
- Namespace
- LMKit.TextGeneration.Sampling
- Assembly
- LM-Kit.NET.dll
CreateJsonGrammarFromJsonScheme(string)
Creates a Grammar instance for constrained text generation based on a provided JSON schema. This method generates a grammar that enforces the generation of JSON structures conforming to the specified schema, ensuring that the output adheres to the defined structure and data types.
public static Grammar CreateJsonGrammarFromJsonScheme(string json)
Parameters
json
stringA string containing a JSON schema that defines the structure, fields, and data types of the JSON data. The schema is used to create a grammar that constrains the text generation to produce outputs matching the schema.
Returns
- Grammar
A new Grammar instance that constrains text generation to produce JSON outputs conforming to the provided schema.
Exceptions
- ArgumentException
Thrown if the
json
string is null, empty, or not a valid JSON schema.