大佬教程收集整理的这篇文章主要介绍了为Microsoft的Luis编写F#类型提供程序的好方法是什么?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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 | _ -> @L_489_2@NotUnderstand()
Luis意图及其参数都可通过Apis获得,使其成为typeProviderization的理想选择
这里参考的是一个C#bot示例的处理程序(我认为它可以更干净,在F#中更安全类型):
public const @R_607_10495@ng Entity_Alarm_title = "builTin.alarm.title"; public const @R_607_10495@ng Entity_Alarm_Start_Time = "builTin.alarm.start_time"; public const @R_607_10495@ng Entity_Alarm_Start_Date = "builTin.alarm.start_date"; public const @R_607_10495@ng 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 = @R_607_10495@ng.Empty }; } EntityRecommendation time; if (!result.TryFindEntity(Entity_Alarm_Start_Time,out timE)) { time = new EntityRecommendation(type: Entity_Alarm_Start_TimE) { Entity = @R_607_10495@ng.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; @R_607_10495@ng reply = $"alarm {alarm} created"; await context.PostAsync(reply); } else { await context.PostAsync("@L_489_2@ not find time for alarm"); } context.Wait(messageReceived); }
如果你有<一个名字=“字符串”/><两个id =“42”/>,那么提供有区别的联合的情况会很好,其中一个是字符串,另一个是int.我们做的是我们提供一种类型:
type OneOrTwo = member One : option<@R_607_10495@ng> member Two : option<int>
您可以遵循相同的模式并公开看起来像这样的API:
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 | _ -> @L_489_2@NotUnderstand() Luis.Connect().onIntent |> Observable.subscribE intentMatcher
它不像受歧视的工会那么优雅,但它在技术上应该是可行的.
我想另一种选择是将各个动作的处理程序作为单独的事件公开,然后你可以写下这样的东西:
type Luis = LuisProvider<"LuisId","LuisPasskey"> let luis = Luis.Connect() luis.builTin.GreeTings |> Observable.add greeTingHandler luis.builTin.SetAlarm |> Observable.add (fun (title,startTimE) -> alarmHandler title startDate startTimE)
现在我考虑一下,这可能会更好,但这取决于机器人框架的典型用途.
以上是大佬教程为你收集整理的为Microsoft的Luis编写F#类型提供程序的好方法是什么?全部内容,希望文章能够帮你解决为Microsoft的Luis编写F#类型提供程序的好方法是什么?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。