【问题标题】:Multiple LUIS models from config配置中的多个 LUIS 模型
【发布时间】:2017-06-27 01:41:54
【问题描述】:

我通过属性在 1 个 LUIS 对话框中使用 2 个 LUIS 模型

[LuisModel("model1", "")]    
[LuisModel("model2", "")]
[Serializable]
public class LuisDialog

我需要从配置文件中获取这些模型。 在 Autofac 我只能注册 1

builder.Register(c => new LuisModelAttribute("model1", ""))...

如何从一个配置中设置多个 Luis 模型?

【问题讨论】:

    标签: c# botframework azure-language-understanding


    【解决方案1】:

    我认为这不会起作用,因为 LuisModel 被注入到您正在注册的 LuisService 中(这可能是您配置中的下一行)并且 LuisService 只需要一个模型而不是一个它们的数组。

    我认为这可行的方法是,您应该注册多个LuisService,而不是将模型注册到LuisService,为每个模型定义构造函数的模型参数的值(见this)。

    这样,当您解析基于LuisDialog 的对话框时,它将注入多个ILuisService(请参阅this),因为它已准备好接收一系列服务。

    我还没有尝试过,但你可以看看这样的东西是否有效:

    var model1 = new LuisModelAttribute("model1", "");
    var model2 = new LuisModelAttribute("model2", "");
    
    builder.RegisterType<LuisService>()
           .WithParameter("model", model1)
           .Keyed<ILuisService>(FiberModule.Key_DoNotSerialize)
           .AsImplementedInterfaces()
           .SingleInstance(); or // .InstancePerLifetimeScope()
    
    builder.RegisterType<LuisService>()
           .WithParameter("model", model2)
           .Keyed<ILuisService>(FiberModule.Key_DoNotSerialize)
           .AsImplementedInterfaces()
           .SingleInstance(); or // .InstancePerLifetimeScope()
    

    或者,您可以使用RegisterInstance 并将LuisService 的实例注册到它们的特定模型中。

    【讨论】:

    • 这超出了问题的范围;不知道为什么当问题超出范围时不接受答案。
    猜你喜欢
    • 1970-01-01
    • 2018-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多