Skip to content

Commit

Permalink
# Adding action model to showcase advanced usage options
Browse files Browse the repository at this point in the history
  • Loading branch information
maurok committed Jun 1, 2017
1 parent 0778c0d commit eb63e58
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace LuisActions.Samples
{
using System;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.Cognitive.LUIS.ActionBinding;
using Newtonsoft.Json;

// This sample were added to showcase support to Custom List Entities - default JSON model does not have it

// Refer to 'List Entities' @ https://docs.microsoft.com/en-us/azure/cognitive-services/luis/add-entities

// You can create your own model with an 'AlternativeChoose' intent with utterances
// having a 'List Entity' called 'Alternatives' with the canonical forms defined by the
// 'Alternative' enum - or just can simply create your custom list entity,
// intent and update the intent binding here and custom name/type at fields

public enum Alternative
{
// default (ie. empty choice)
None = 0,

DomainOption1 = 11,
DomainOption2 = 12,
DomainOption3 = 13,

ExternalOption1 = 101,
ExternalOption2 = 102
}

public class RequiredEnumAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
return (int)value > 0;
}
}

[Serializable]
[LuisActionBinding("AlternativeChoose", FriendlyName = "Alternatives Choosing Model Sample")]
public class AlternativesAction : BaseLuisAction
{
[RequiredEnum(ErrorMessage = "Please provide an alternative")]
[LuisActionBindingParam(CustomType = "Alternatives", Order = 1)]
public Alternative FirstAlternative { get; set; }

[Required(ErrorMessage = "Please provide one or more alternatives")]
[LuisActionBindingParam(CustomType = "Alternatives", Order = 2)]
public Alternative[] SecondaryAlternatives { get; set; }

public override Task<object> FulfillAsync()
{
return Task.FromResult((object)JsonConvert.SerializeObject(this));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<Compile Include="GetDataFromPlaceBaseAction.cs" />
<Compile Include="GetTimeInPlaceAction.cs" />
<Compile Include="GetWeatherInPlaceAction.cs" />
<Compile Include="Advanced\AlternativesAction.cs" />
<Compile Include="LocationAttibute.cs" />
<Compile Include="Models\AirportInfo.cs" />
<Compile Include="Models\WeatherInfo.cs" />
Expand Down

0 comments on commit eb63e58

Please sign in to comment.