Beispiel #1
0
        /// <summary>
        /// Handles the intent logic.
        /// </summary>
        /// <param name="intent">The LuisResult containing the detected intent.</param>
        /// <returns>A list of actions for Robbie to execute, based on the provided intent.</returns>
        private async Task <IList <IAction> > HandleIntent(LuisResult intent)
        {
            // todo: UpdateEmotions shouldn't always happen. Preferably move to Intent.HandleIntent or in it's actionclass
            if (!currentIdentityPersonId.Equals(AnonymousPersonId))
            {
                await UpdateEmotion();

                var experienceProfile = await GetClientForCurrentUser().GetExperienceProfile();

                if (experienceProfile.OnsiteBehavior.ActiveProfiles?.Length > 0 && experienceProfile.OnsiteBehavior.ActiveProfiles[0].PatternMatches?.Length > 0)
                {
                    // todo: log profile card to events, just debugging purposes
                    var patternName     = experienceProfile.OnsiteBehavior.ActiveProfiles?[0].PatternMatches?[0].PatternName;
                    var matchPercentage = experienceProfile.OnsiteBehavior.ActiveProfiles?[0].PatternMatches?[0].MatchPercentage;
                    ReportEvent("behaviour", $"{patternName} {matchPercentage}");

                    // todo: get profile, just for debugging purposes
                    // ReSharper disable once UnusedVariable
                    var profile = await GetClientForCurrentUser().GetProfile();
                }
            }

            // create intent handler after intent has been returned and retrieve all actions that are tied to this intent
            var handler = new IntentHandler(intent, GetClientForCurrentUser());
            var actions = await handler.HandleIntent();

            return(actions);
        }
Beispiel #2
0
        /// <summary>
        /// Find an appropriate intent handler and use it to process the incoming intent.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="lambdaContext"></param>
        /// <returns></returns>
        public override SkillResponse HandleRequest(SkillRequest request, ILambdaContext lambdaContext)
        {
            IntentRequest intentRequest = request.Request as IntentRequest;

            lambdaContext.Logger.LogLine("Request Intent: " + intentRequest.Intent.Name);

            IntentHandler handler = CustomIntentHandlers.Find(x => x.IsHandlerForIntent(intentRequest.Intent));

            if (handler != null)
            {
                // Custom handler
                return(handler.HandleIntent(intentRequest.Intent, request.Session, lambdaContext));
            }
            else if (SupportedIntents.Contains(intentRequest.Intent.Name))
            {
                // Otherwise we have a story intent
                return(Story.CreateResponse(intentRequest.Intent, request.Session, lambdaContext));
            }
            else
            {
                // Otherwise we have no way of dealing with this intent
                lambdaContext.Logger.LogLine("No intent handler found");
                return(ResponseBuilder.Empty());
            }
        }
Beispiel #3
0
        protected virtual async Task MessageReceived(IDialogContext context, IAwaitable <Message> item)
        {
            if (this.handlerByIntent == null)
            {
                this.handlerByIntent = new Dictionary <string, IntentHandler>(GetHandlersByIntent());
            }

            var message     = await item;
            var messageText = await GetLuisQueryTextAsync(context, message);

            var luisRes = await this.service.QueryAsync(messageText);

            var intent = BestIntentFrom(luisRes);

            IntentHandler handler = null;

            if (intent == null || !this.handlerByIntent.TryGetValue(intent.Intent, out handler))
            {
                handler = this.handlerByIntent[string.Empty];
            }

            if (handler != null)
            {
                await handler(context, luisRes);
            }
            else
            {
                var text = $"No default intent handler found.";
                throw new Exception(text);
            }
        }
Beispiel #4
0
        protected override async Task <string> ClassifyDialog(ITurnContext context)
        {
            if (Result == null)
            {
                // Is initialization ..
                return(null);
            }

            // Find TopIntent
            var topIntent = Result?.GetTopScoringIntent();

            // If classification is too bad, set to none.
            topIntent = (topIntent?.Item2 ?? 0) < 0.3 ? ("None", 1) : topIntent;

            bool contains = IntentHandler.TryGetValue(topIntent?.Item1?.ToLower(), out string handler);

            if (contains)
            {
                // Default handler
                return(handler);
            }
            else if (topIntent?.Item1?.ToLower()?.StartsWith("st_") ?? false)
            {
                // Smalltalk
                return(nameof(SingleStepSmalltalk <IBot4Dialog, BotServices>));
            }
            else
            {
                await SendMessage($"I did not found anything for {topIntent?.Item1}", context);
            }
            return(null);
        }
Beispiel #5
0
        protected virtual async Task MessageReceived(IDialogContext context, IAwaitable <Message> item)
        {
            if (this.handlerByIntent == null)
            {
                this.handlerByIntent = LuisDialog.EnumerateHandlers(this).ToDictionary(kv => kv.Key, kv => kv.Value);
            }

            var message = await item;
            var luisRes = await this.service.QueryAsync(message.Text);

            var maximum = luisRes.Intents.Max(t => t.Score ?? 0);
            var intent  = luisRes.Intents.FirstOrDefault(i => { var curScore = i.Score ?? 0; return(curScore == maximum); });

            IntentHandler handler = null;

            if (intent == null || !this.handlerByIntent.TryGetValue(intent.Intent, out handler))
            {
                handler = this.handlerByIntent[string.Empty];
            }

            if (handler != null)
            {
                await handler(context, luisRes);
            }
            else
            {
                var text = $"No default intent handler found.";
                throw new Exception(text);
            }
        }
Beispiel #6
0
        protected virtual async Task MessageReceived(IDialogContext context, IAwaitable <Message> item)
        {
            if (this.handlerByIntent == null)
            {
                this.handlerByIntent = new Dictionary <string, IntentHandler>(GetHandlersByIntent());
            }

            var message     = await item;
            var messageText = await GetLuisQueryTextAsync(context, message);

            var tasks  = this.services.Select(s => s.QueryAsync(messageText)).ToArray();
            var winner = this.BestResultFrom(await Task.WhenAll(tasks));

            IntentHandler handler = null;

            if (winner == null || !this.handlerByIntent.TryGetValue(winner.BestIntent.Intent, out handler))
            {
                handler = this.handlerByIntent[string.Empty];
            }

            if (handler != null)
            {
                await handler(context, winner?.Result);
            }
            else
            {
                var text = $"No default intent handler found.";
                throw new Exception(text);
            }
        }
Beispiel #7
0
	void Start() {
		mainCam = Camera.main;
		targetTracker = gameObject.GetComponentInChildren<EnemyTargeting> ();
        weapon = gameObject.GetComponentInChildren<Weapon>();
        intentHandler = new IntentHandler();
        currentState = State.Passive;
        potentialState = State.Passive;
	}
 void Awake()
 {
     Growthbeat.GetInstance().Initialize(applicationId, credentialId);
     IntentHandler.GetInstance().AddNoopIntentHandler();
     IntentHandler.GetInstance().AddUrlIntentHandler();
     IntentHandler.GetInstance().AddCustomIntentHandler("GrowthbeatComponent", "HandleCustomIntent");
     GrowthLink.GetInstance().Initialize(applicationId, credentialId);
     GrowthPush.GetInstance().RequestDeviceToken(senderId, environment);
     Growthbeat.GetInstance().Start();
 }
Beispiel #9
0
        private void LoadIntentHandlers()
        {
            var handler = new Dictionary <string, string>
            {
                // Mappings from intent (lower case) to dialogs. As ID we've used the names of the classes
                { "None".ToLower(), nameof(NoneDialog) },
                { "Echo".ToLower(), nameof(EchoDialog) },
                // Special Smalltalks
                { "ST_Greeting".ToLower(), nameof(GreetingDialog) }
            };

            handler.Keys.ToList().ForEach(k => IntentHandler.Add(k, handler[k]));
        }
 public Enemy.Action InterpretIntent(float patience, IntentHandler.Intent intent)
 {
     switch (intent) //Switch is based on what the player action is
     {
         case IntentHandler.Intent.INTENT_ATTACK_LIGHT:
             if (Random.Range(1, 10) >= agility) //If greater than agility, block
             {
                 return Enemy.Action.BLOCK;
             }
             else
             {
                 break;
             }
         case IntentHandler.Intent.INTENT_STRAFE:
             if (patience > 50)
             {
                 return Enemy.Action.STRAFE;
             }
             else
             {
                 break;
             }
         case IntentHandler.Intent.INTENT_RETREAT:
             return Enemy.Action.CHARGE;
         case IntentHandler.Intent.INTENT_APPROACH:
             if (patience < 60)
             {
                 return Enemy.Action.BLOCK;
             }
             else
             {
                 return Enemy.Action.CHARGE;
             }
         case IntentHandler.Intent.INTENT_ATTACK_STRONG:
             if (Random.Range(1, 10) >= agility) //If greater than agility, block
             {
                 return Enemy.Action.BLOCK;
             }
             else
             {
                 break;
             }
     }
     return Enemy.Action.IDLE;
 }
Beispiel #11
0
 internal static extern void AndroidPlatformConfiguration_SetOptionalIntentHandlerForUI(
     HandleRef self,
     /* from(AndroidPlatformConfiguration_IntentHandler_t) */ IntentHandler intent_handler,
     /* from(void *) */ IntPtr intent_handler_arg);
Beispiel #12
0
 internal static extern void AndroidPlatformConfiguration_SetOptionalIntentHandlerForUI(HandleRef self, IntentHandler intent_handler, IntPtr intent_handler_arg);
        private static async Task <ResultType> VerifyTusVersionIfApplicable(ContextAdapter context, IntentHandler intentHandler)
        {
            // Options does not require a correct tus resumable header.
            if (intentHandler.Intent == IntentType.GetOptions)
            {
                return(ResultType.ContinueExecution);
            }

            var tusResumableHeader = context.Request.GetHeader(HeaderConstants.TusResumable);

            if (tusResumableHeader == HeaderConstants.TusResumableValue)
            {
                return(ResultType.ContinueExecution);
            }

            context.Response.SetHeader(HeaderConstants.TusResumable, HeaderConstants.TusResumableValue);
            context.Response.SetHeader(HeaderConstants.TusVersion, HeaderConstants.TusResumableValue);
            await context.Response.Error(HttpStatusCode.PreconditionFailed, $"Tus version {tusResumableHeader} is not supported. Supported versions: {HeaderConstants.TusResumableValue}");

            return(ResultType.StopExecution);
        }
 private static Models.Concatenation.FileConcat GetFileConcatenationFromIntentHandler(IntentHandler intentHandler)
 {
     return(intentHandler is ConcatenateFilesHandler concatFilesHandler ? concatFilesHandler.UploadConcat.Type : null);
 }
 internal static extern void AndroidPlatformConfiguration_SetOptionalIntentHandlerForUI(
     HandleRef self,
      /* from(AndroidPlatformConfiguration_IntentHandler_t) */ IntentHandler intent_handler,
      /* from(void *) */ IntPtr intent_handler_arg);
Beispiel #16
0
    public void handlePlayerIntent(IntentHandler.Intent intent)
    {

        Action action = intentInterpreter.InterpretIntent(patience, intent);

        if (action == Action.LIGHT_ATTACK) { //If the AI decides to do a light attack, reset the patience because it attacked.
            lightAttack(player.transform); //Do a light attack
            ResetPatience(); //Reset patience to 0
            defend(false); //Stop the AI from defending
        }
        if (action == Action.BLOCK)
        { //Blocks the attack. True for blocking, false to stop.
            defend(true);
        }
        if (action == Action.STRAFE)
        { //Is a placeholder for dodge. 1 or -1 to decide direction, 0 to not strafe. (Fix that soon? (TM))
            strafe(player.transform, player.h);
        }
        else
        {
            strafe(player.transform, 0);
        }
        if (action == Action.IDLE)
        { //Sets to Idle & disables all other movement
            defend(false);
        }
        if (action == Action.CHARGE)
        {
            dash(player.transform);
        }
    }