LUISGen is a tool for generating a strongly typed C# class or typescript interface to make consuming LUIS output easier. This enables build-time error checking and intellisense against the entities which are defined in your LUIS application model.
This tool depends on having DotNet Core SDK 2.1 installed on your system.
LUISGen is a .NET Core Tool and can be installed directly using .NET Core command line:
dotnet tool install -g LUISGen
This NPM package is a simple wrapper around the dotnet tool install command.
npm install -g luisgen
The LUISGen tool generates a strongly typed class for the intents and entities which are defined in your LUIS application model.
To generate from a saved model .JSON file you invoke from the CLI like this:
LUISGen <AppNameLUISExport.json> [-cs|-ts] CLASSNAME -o PATH
If a .JSON file is not passed in, LUISGen can assume that the JSON is being piped in via stdin if you add an --stdin
parameter. This
allows you to use the LUIS CLI tool to export your
application model and pipe it directly into the LUISGen tool like this:
luis export version --appId {luisAppId} --versionId {versionId} --authoringKey {authoringKey}
| luisgen --stdin [-cs|-ts] CLASSNAME -o PATH
NOTE: The LUIS CLI tool can be installed with the npm command:
npm install -g luis-apis
At least one of -cs
or -ts
must be supplied:
-
-cs {CLASSNAME}
- Generates C# class file including namespace. Default is Luis.APPNAME if no class name is specified. -
-ts {CLASSNAME}
- Generates Typescript interface descriptions. Default is APPNAME if no class name is specified.
-o PATH
specifies the output path to the generated files. Default value is
the directory where the export file is located.
Call your LuisRecognizer
instance supplying the type to .Recognize
:
var result = recognizer.Recognize<CLASSNAME>("hi", CancellationToken.None);
The variable will be strongly typed LUIS result.
- Add the
.ts
file to your project. - Call your
LuisRecognizer
instance and type the returned result with your class.
let app : CLASSNAME = await recognizer.recognize(context);
The callback value app will be a strongly typed LUIS result.