wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为Microsoft的Luis编写F#类型提供程序的好方法是什么?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

玩微软的Luis bot框架,我的“这将成为一个好的类型提供者”的感觉开始刺痛.不幸的是,类型提供者不能输出有区别的联盟.我希望做类似以下的事情,但这是不可能的: type Luis = LuisProvider<@"luisId",@"luisPasskey"> let IntentMatcher Intent = match intent with | Luis.Intents
玩微软的Luis bot框架,我的“这将成为一个好的类型提供者”的感觉开始刺痛.不幸的是,类型提供者不能输出有区别的联盟.我希望做类似以下的事情,但这是不可能的

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);
}

无论如何,问题是:有没有更多建立类型提供者经验的人对我如何构建一个实际可行构建的可读dsl有任何好的想法吗?

解决方法

我对机器人框架并不是特别熟悉,但我可以对有区别的工会发表评论 – 我们在F#数据中遇到了类似的问题.

如果你有<一个名字=“字符串”/><两个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,请注明来意。