Ejemplo n.º 1
0
        /// <summary>
        /// Query the LUIS service using this text.
        /// </summary>
        /// <param name="service">LUIS service.</param>
        /// <param name="text">The query text.</param>
        /// <param name="token">The cancellation token.</param>
        /// <returns>The LUIS result.</returns>
        public static async Task <LuisResult> QueryAsync(this ILuisService service, string text, CancellationToken token)
        {
            var translated = Translate((service as LuisService).model, text);
            var uri        = service.BuildUri(new LuisRequest(query: translated));

            return(await service.QueryAsync(uri, token));
        }
Ejemplo n.º 2
0
 public LuisServiceResult(LuisResult result, IntentRecommendation intent, ILuisService service, ILuisOptions luisRequest = null)
 {
     this.Result      = result;
     this.BestIntent  = intent;
     this.LuisService = service;
     this.LuisRequest = luisRequest;
 }
Ejemplo n.º 3
0
        protected virtual async Task <IDialog <LuisResult> > MakeLuisActionDialog(ILuisService luisService, string contextId, string prompt)
        {
#pragma warning disable CS0618
            return(new LuisActionDialog(luisService, contextId, prompt));

#pragma warning restore CS0618
        }
Ejemplo n.º 4
0
 public AlarmLuisDialog(IAlarmService service, IEntityToType entityToType, ILuisService luis, IClock clock)
     : base(luis)
 {
     SetField.NotNull(out this.service, nameof(service), service);
     SetField.NotNull(out this.entityToType, nameof(entityToType), entityToType);
     SetField.NotNull(out this.clock, nameof(clock), clock);
 }
 public LuisIntentScorable(ILuisService service, ILuisModel model, LuisIntentAttribute intent, IScorable <IResolver, InnerScore> inner)
     : base(inner)
 {
     SetField.NotNull(out this.service, nameof(service), service);
     SetField.NotNull(out this.model, nameof(model), model);
     SetField.NotNull(out this.intent, nameof(intent), intent);
 }
Ejemplo n.º 6
0
 public RecognitionService(ISettings settings, IIntentService intentService, ILuisService luisService, ILogger <RecognitionService> logger)
 {
     _settings      = settings;
     _intentService = intentService;
     _luisService   = luisService;
     _logger        = logger;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Query the LUIS service using this request.
        /// </summary>
        /// <param name="service">LUIS service.</param>
        /// <param name="request">Query request.</param>
        /// <param name="token">Cancellation token.</param>
        /// <returns>LUIS result.</returns>
        public static async Task <LuisResult> QueryAsync(this ILuisService service, LuisRequest request, CancellationToken token)
        {
            service.ModifyRequest(request);
            var uri = service.BuildUri(request);

            return(await service.QueryAsync(uri, token));
        }
Ejemplo n.º 8
0
 public IntelligentSearchController(
     IWebUtilWrapper webUtil,
     ISitecoreDataWrapper dataWrapper,
     IIntelligentSearchSettings settings,
     ISearchService searcher,
     ILuisService luisService,
     ILuisConversationService luisConversationService,
     IAutoSuggestService autoSuggestService,
     ISpeechService speechService,
     IWebSearchService webSearchService,
     IConversationContextFactory conversationContextFactory,
     IMicrosoftCognitiveServicesApiKeys apiKeys)
 {
     WebUtil                    = webUtil;
     DataWrapper                = dataWrapper;
     Settings                   = settings;
     Searcher                   = searcher;
     LuisService                = luisService;
     LuisConversationService    = luisConversationService;
     AutoSuggestService         = autoSuggestService;
     SpeechService              = speechService;
     WebSearchService           = webSearchService;
     ConversationContextFactory = conversationContextFactory;
     ApiKeys                    = apiKeys;
 }
Ejemplo n.º 9
0
        public MessageController(ILuisService luis,
                                 IAnswerService answerService,
                                 IUnknownService issueService,
                                 IRedisCachingProvider redis,
                                 DingTalkHelper ddHelper,
                                 IDepartmentService departmentService,
                                 IPermissionService permissionService,
                                 IConfiguration configuration,
                                 IFeedbackService feedbackService,
                                 IAppSettings settings,
                                 ILogger <MessageController> logger,
                                 KnowledgeMapContext mapContext,
                                 DingDingApprovalService dingDingApprovalService)
        {
            _logger            = logger;
            _settings          = settings;
            _ddHelper          = ddHelper;
            _configuration     = configuration;
            _ddApprovalService = dingDingApprovalService;
            _luis              = luis;
            _answerService     = answerService;
            _issueService      = issueService;
            _departService     = departmentService;
            _redis             = redis;
            _feedbackService   = feedbackService;
            _permissionService = permissionService;
            _httpClient        = HttpClientFactory.Create();

            _mapContext = mapContext;
        }
Ejemplo n.º 10
0
        public static async Task <QueryValueResult> QueryValueFromLuisAsync(
            ILuisService service,
            ILuisAction action,
            string paramName,
            object paramValue,
            CancellationToken token,
            Func <PropertyInfo, IEnumerable <EntityRecommendation>, EntityRecommendation> entityExtractor = null)
        {
            var originalValue = paramValue;

            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            if (string.IsNullOrWhiteSpace(paramName))
            {
                throw new ArgumentNullException(nameof(paramName));
            }

            if (paramValue == null)
            {
                throw new ArgumentNullException(nameof(paramValue));
            }

            var result = await service.QueryAsync(paramValue.ToString(), token);

            var queryIntent = result.Intents.FirstOrDefault();

            if (!Intents.None.Equals(queryIntent.Intent, StringComparison.InvariantCultureIgnoreCase))
            {
                var newIntentName = default(string);
                var newAction     = new LuisActionResolver(action.GetType().Assembly).ResolveActionFromLuisIntent(result, out newIntentName);
                if (newAction != null)
                {
                    return(new QueryValueResult(false)
                    {
                        NewAction = newAction,
                        NewIntent = newIntentName
                    });
                }
            }

            var properties = new List <PropertyInfo> {
                action.GetType().GetProperty(paramName, BindingFlags.Public | BindingFlags.Instance)
            };

            if (!LuisActionResolver.AssignEntitiesToMembers(action, properties, result.Entities, entityExtractor))
            {
                return(new QueryValueResult(AssignValue(action, properties.First(), originalValue)));
            }

            return(new QueryValueResult(true));
        }
Ejemplo n.º 11
0
        public TripleDDialog(ILuisService service = null) : base(service)
        {
            var modelId         = ConfigurationManager.AppSettings.Get("LuisModelId");
            var subscriptionKey = ConfigurationManager.AppSettings.Get("LuisSubscriptionKey");
            var luisAttribute   = new LuisModelAttribute(modelId, subscriptionKey);

            service = new LuisService(luisAttribute);
        }
 public LuisScorable(ILuisService luisService, IDialogTask task, ILogger logger, LuisIntentHandlerDialogFactory luisIntentHandlerFactory)
 {
     this.luisService       = luisService;
     this.luisResults       = new Dictionary <string, LuisResult>();
     this.task              = task;
     this.logger            = logger;
     this.luisIntentFactory = luisIntentHandlerFactory;
 }
Ejemplo n.º 13
0
 public MessagesController(ILuisService luisService)
 {
     if (luisService == null)
     {
         throw new ArgumentNullException(nameof(luisService));
     }
     _luisService = luisService;
 }
Ejemplo n.º 14
0
 public eShopBot(IHttpContextAccessor httpContextAccessor,
                 ILuisService luisService,
                 IDialogFactory dialogFactory)
 {
     host               = httpContextAccessor.HttpContext.Request.AbsoluteHost();
     this.luisService   = luisService;
     this.dialogFactory = dialogFactory;
 }
Ejemplo n.º 15
0
 public AskDayDialog(LuisResult result, ILuisService service)
 {
     if (result == null || service == null)
     {
         throw new ArgumentException("Action chain cannot be null or empty.");
     }
     _result  = result;
     _service = service;
 }
Ejemplo n.º 16
0
 public LuisController(IAnswerService answerService,
                       ILuisService luisService,
                       IDepartmentService departmentService,
                       ILogger <LuisController> logger)
 {
     _departmentService = departmentService;
     _answerService     = answerService;
     _luisService       = luisService;
     _logger            = logger;
 }
Ejemplo n.º 17
0
        public MainPageController()
        {
            _luisService       = new LuisService();
            _getRessources     = new GetRessources();
            _requestWebService = new RequestWebService();
            _listJsonModel     = GetDialogues();
            Device.BeginInvokeOnMainThread(async() => Speech = await AddSpeech("Bonjour, que cherchez vous?"));

            Device.BeginInvokeOnMainThread(async() => await GetFirms());
        }
Ejemplo n.º 18
0
        public CreateAlertDialog(ILuisService luisService)
        {
            _luisService = luisService;
            var waterfallSteps = new WaterfallStep[]
            {
                Process
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
            AddDialog(new TextPrompt(nameof(TextPrompt)));
        }
Ejemplo n.º 19
0
        public GeneralDialog(ILuisService luisService, IIntentService intentService)
        {
            var waterfallSteps = new WaterfallStep[]
            {
                MessageGeneral
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
            _luisService   = luisService;
            _intentService = intentService;
        }
Ejemplo n.º 20
0
        public RootDialog(ILuisService luisService)
        {
            _luisService = luisService;
            var waterfallSteps = new WaterfallStep[]
            {
                InitialProcess,
                FinalProcess
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
            InitialDialogId = nameof(WaterfallDialog);
        }
 public OrchestratorService(
     IAnswersService answersService,
     ILuisService luisService,
     IQnAService qnaService,
     IDialogService dialogService,
     ConversationState conversationState
     )
 {
     _answersService    = answersService;
     _luisService       = luisService;
     _qnaService        = qnaService;
     _dialogService     = dialogService;
     _conversationState = conversationState;
 }
Ejemplo n.º 22
0
        public OleChatController(
            ILuisService luisService,
            ILuisConversationService luisConversationService,
            IWebUtilWrapper webUtil,
            ISitecoreDataWrapper dataWrapper,
            IOleSettings chatSettings,
            ISetupInformationFactory setupFactory,
            ISetupService setupService,
            ISpeechService speechService,
            ISearchService searcher,
            IConversationContextFactory conversationContextFactory,
            ISpellCheckService spellCheckService,
            IIntentProvider intentProvider)
        {
            LuisService             = luisService;
            LuisConversationService = luisConversationService;
            WebUtil       = webUtil;
            DataWrapper   = dataWrapper;
            ChatSettings  = chatSettings;
            SetupFactory  = setupFactory;
            SetupService  = setupService;
            SpeechService = speechService;
            Searcher      = searcher;
            ConversationContextFactory = conversationContextFactory;
            SpellCheckService          = spellCheckService;
            IntentProvider             = intentProvider;
            ThemeManager.GetImage("Office/32x32/man_8.png", 32, 32);

            var lang = WebUtil.GetQueryString("language");

            if (string.IsNullOrWhiteSpace(lang))
            {
                lang = Sitecore.Context.Language.Name;
            }

            var db = WebUtil.GetQueryString("db");

            if (string.IsNullOrWhiteSpace(db))
            {
                db = "master";
            }

            Parameters = new ItemContextParameters()
            {
                Id       = WebUtil.GetQueryString("id"),
                Language = lang,
                Database = db
            };
        }
        public CommandService(ILuisService luis)
        {
            _luis = luis;

            Commands = new List <IBotCommand>()
            {
                new GetWeatherCommand(),
                new TakeTheJokeCommand(),
                new TranslateCommand(),
                new CargoCommand()
            };
            var helpCmd = new HelpCommand(Commands);

            Commands.Add(helpCmd);
        }
Ejemplo n.º 24
0
        public RootDialog(ILuisService luisService, IIntentService intentService)
        {
            _luisService   = luisService;
            _intentService = intentService;
            var waterfallSteps = new WaterfallStep[]
            {
                InitialProcess,
                FinalProcess
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
            AddDialog(new GeneralDialog(luisService, _intentService));

            InitialDialogId = nameof(WaterfallDialog);
        }
Ejemplo n.º 25
0
        public RootDialog(ILuisService luisService, IDataBaseService databaseService)
        {
            _databaseService = databaseService;
            _luisService     = luisService;
            var waterfallSteps = new WaterfallStep[]
            {
                InitialProcess,
                FinalProcess
            };

            AddDialog(new QualificationDialog(_databaseService));
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
            InitialDialogId = nameof(WaterfallDialog);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Construct the LUIS dialog.
        /// </summary>
        /// <param name="service">The LUIS service.</param>
        public LuisDialog(ILuisService service = null)
        {
            if (service == null)
            {
                var type      = this.GetType();
                var luisModel = type.GetCustomAttribute <LuisModelAttribute>(inherit: true);
                if (luisModel == null)
                {
                    throw new Exception("Luis model attribute is not set for the class");
                }

                service = new LuisService(luisModel);
            }

            SetField.NotNull(out this.service, nameof(service), service);
        }
Ejemplo n.º 27
0
 public RootDialog(
     LogInDialog loginDialog,
     SelectSiteDialog selectSiteDialog,
     GetSiteDialog getSiteDialog,
     HelpDialog helpDialog,
     IAuthenticationService authenticationService,
     ILuisService luis,
     IQnAService qnaService) : base(luis)
 {
     _loginDialog           = loginDialog;
     _selectSiteDialog      = selectSiteDialog;
     _getSiteDialog         = getSiteDialog;
     _helpDialog            = helpDialog;
     _authenticationService = authenticationService;
     _qnaService            = qnaService;
 }
Ejemplo n.º 28
0
        public MainDialog(ILuisService luisService, IQnAMakerAIService qnaMakerAIService, UserState userState)
        {
            _luisService       = luisService;
            _qnaMakerAIService = qnaMakerAIService;
            _userState         = userState;

            var waterfallSteps = new WaterfallStep[]
            {
                InitialProcess,
                FinalProcess
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
            InitialDialogId = nameof(WaterfallDialog);
            AddDialog(new CrearLicenciaFuncionamientoDialog());
            AddDialog(new LoginDialog());
        }
Ejemplo n.º 29
0
        // private readonly IDataBaseService _databaseService;

        public RootDialog(ILuisService luisService, StateBotAccessors accessors, IQnAMakerAIService qnaMakerAIService)
        {
            _luisService       = luisService;
            _qnaMakerAIService = qnaMakerAIService;
            // _databaseService = databaseService;

            var waterfallSteps = new WaterfallStep[]
            {
                InitialProcess,
                FinalProcess
            };

            //AddDialog(new QualificationDialog(_databaseService));
            //AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));
            InitialDialogId = nameof(WaterfallDialog);
        }
Ejemplo n.º 30
0
        protected override async Task MessageReceived(IDialogContext context, IAwaitable <IMessageActivity> item)
        {
            try
            {
                var message     = await item;
                var messageText = await GetLuisQueryTextAsync(context, message);

                Trace.TraceInformation(":::::: User Message :::::::>" + messageText);

                if (!string.IsNullOrEmpty(messageText))
                {
                    var tasks   = this.services.Select(s => s.QueryAsync(messageText, context.CancellationToken)).ToArray();
                    var results = await Task.WhenAll(tasks);

                    var winners = from result in results.Select((value, index) => new { value, index })
                                  let resultWinner = BestIntentFrom(result.value)
                                                     where resultWinner != null && (resultWinner.Score > 0.6 || (results[0].Intents.Count == 1 && resultWinner.Score > 0.4)) //<== 가끔 0.6 이하로 걸리는 경우가 있으므로 점수가 0.4 이상인 결과가 하나만 나오는 경우 맞다고 간주.
                                                     select new LuisServiceResult(result.value, resultWinner, this.services[result.index]);

                    var winner = this.BestResultFrom(winners) ?? new LuisServiceResult(results[0], new IntentRecommendation {
                        Intent = "None", Score = 1
                    }, this.services[0]);
                    service = winner.LuisService;
                    await DispatchToIntentHandler(context, item, winner.BestIntent, winner.Result);
                }
                else
                {
                    var intent = new IntentRecommendation()
                    {
                        Intent = string.Empty, Score = 1.0
                    };
                    var result = new LuisResult()
                    {
                        TopScoringIntent = intent
                    };
                    await DispatchToIntentHandler(context, item, intent, result);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceInformation("It is possible that the LUIS appid has changed.");
                Trace.TraceError(ex.Message);
                Trace.TraceError(ex.StackTrace);
            }
        }