2016-08-19 2 views
3

마이크로 소프트의 Luis + bot 프레임 워크와 놀아나는 나의 "좋은 타입 제공자가 될 것"이라는 느낌이 들리기 시작했다. 유감스럽게도 유형 제공자는 차별화 된 공용체를 출력 할 수 없습니다. 나는 다음과 같은 뭔가를 기대했다, 그러나 수 없습니다 :Microsoft의 Luis 용 F # Type Provider를 작성하는 좋은 방법은 무엇입니까?

type Luis = LuisProvider<@"LuisId",@"LuisPasskey"> 
let IntentMatcher Intent = 
    match intent with 
    | Luis.Intents.Greeting -> GreetingHandler() 
    | Luis.Intents.SetAlarm title startDate startTime -> AlarmHandler title startDate startTime 
    | _ -> CouldNotUnderstand() 

루이스의 의도와 자신의 매개 변수를 API를 통해 사용할 수있는 모든 수 있습니다 참고로 typeProviderization

그들에게 훌륭한 후보자를 만드는 여기하는 인 예를 들어 C#을 봇에서 핸들러 (I 생각 청소기 될 수 있으며, F 번호에 안전 더 타입) :

public const string Entity_Alarm_Title = "builtin.alarm.title"; 
public const string Entity_Alarm_Start_Time = "builtin.alarm.start_time"; 
public const string Entity_Alarm_Start_Date = "builtin.alarm.start_date"; 
public const string DefaultAlarmWhat = "default"; 

[LuisIntent("builtin.intent.alarm.set_alarm")] 
public async Task SetAlarm(IDialogContext context, LuisResult result) 
{ 
     EntityRecommendation title; 
     if (!result.TryFindEntity(Entity_Alarm_Title, out title)) 
     { 
      title = new EntityRecommendation(type: Entity_Alarm_Title) { Entity = DefaultAlarmWhat }; 
     } 
     EntityRecommendation date; 
     if (!result.TryFindEntity(Entity_Alarm_Start_Date, out date)) 
     { 
      date = new EntityRecommendation(type: Entity_Alarm_Start_Date) { Entity = string.Empty }; 
     } 
     EntityRecommendation time; 
     if (!result.TryFindEntity(Entity_Alarm_Start_Time, out time)) 
     { 
      time = new EntityRecommendation(type: Entity_Alarm_Start_Time) { Entity = string.Empty }; 
     } 
     var parser = new Chronic.Parser(); 
     var span = parser.Parse(date.Entity + " " + time.Entity); 
     if (span != null) 
     { 
      var when = span.Start ?? span.End; 
      var alarm = new Alarm() { What = title.Entity, When = when.Value }; 
      this.alarmByWhat[alarm.What] = alarm; 
      string reply = $"alarm {alarm} created"; 
      await context.PostAsync(reply); 
     } 
     else 
     { 
      await context.PostAsync("could not find time for alarm"); 
     } 
     context.Wait(MessageReceived); 
} 

어쨌든 질문은 : 더 많은 경험 건물 유형 공급자와 사람이 어떻게 할 수에서 좋은 아이디어를 가지고 ac 인 읽을 수있는 DSL을 구조화한다. 빌드가 가능한가?

답변

7

저는 봇 프레임 워크에 익숙하지 않지만, 차별화 된 노동 조합에 대해 언급 할 수 있습니다. 우리는 F # 데이터에서 비슷한 문제에 직면 해 있습니다.

<One name="string" /><Two id="42" /> 사용자 인 경우 One of stringTwo of int으로 구분 된 조합을 제공하는 것이 좋습니다. 그것은 차별 노동 조합으로 아주 우아하지

type Luis = LuisProvider<"LuisId", "LuisPasskey"> 

let intentMatcher (intent:Luis.Intents) = 
    match intent.Greetings, intent.SetAlarm with 
    | Some(), _ -> greetingHandler() 
    | _, Some(title, startDate, startTime) -> alarmHandler title startDate startTime 
    | _ -> couldNotUnderstand() 

Luis.Connect().OnIntent 
|> Observable.subscribe intentMatcher 

:

type OneOrTwo = 
    member One : option<string> 
    member Two : option<int> 

당신은 같은 패턴을 따르고 다음과 같이 보입니다 API 노출 될 수 있습니다 : 우리가 대신 할 것은 우리가 유형을 제공한다는 것입니다 그러나 기술적으로 가능해야합니다. 지금 그것에 대해 생각이 아마 더 좋은 것

type Luis = LuisProvider<"LuisId", "LuisPasskey"> 

let luis = Luis.Connect() 

luis.BuiltIn.Greetings 
|> Observable.add greetingHandler 

luis.BuiltIn.SetAlarm 
|> Observable.add (fun (title, startDate, startTime) -> 
    alarmHandler title startDate startTime) 

을 :

나는 또 다른 별도의 이벤트와 같은 개인의 행동에 대한 핸들러를 노출하는 것입니다 그리고 당신이 뭔가를 쓸 수 있다고 가정 어떤 종류의 용도가 봇 프레임 워크에서 전형적인지에 달려 있습니다.

+0

토마스 당신은 스타입니다! 두 사람의 후자가 완벽하게 보인다 :) –