question

Ines-1299 avatar image
0 Votes"
Ines-1299 asked Ines-1299 published

Error tutorial of MR and Azure 303: Natural language understanding (LUIS) - Object reference not set to an instance of an object



I followed the tutorial of MR and Azure 303: Natural language understanding (LUIS) https://docs.microsoft.com/en-us/windows/mixed-reality/develop/unity/tutorials/mr-azure-303
In the end, I ended up getting an error on Unity that says

'"Luis Request Exception Message: Object reference not set to an instance of an object
UnityEngine.Debug:Log(Object)
<SubmitRequestToLuis>d__6:MoveNext() (at Assets/Scripts/LuisManager.cs:76)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)"

I am using a newer version of Unity, could that be the problem ?

My messages are actually showing up on the LUIS portal, so i dont think there's a problem with the endpoint link.


This is the full luisManager code



 using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using UnityEngine;
 using UnityEngine.Networking;
    
 public class LuisManager : MonoBehaviour
 {
     public static LuisManager instance;
    
     //Substitute the value of luis Endpoint with your own End Point
    
     string luisEndpoint = "https://luisinestest.cognitiveservices.azure.com/luis/prediction/v3.0/apps/6d954c3f-9063-4567-8bd8-196a6d1f3171/slots/production/predict?subscription-key=271f533a70fc45dba93d0b4fd8fc2842&verbose=true&show-all-intents=true&log=true&query=";
    
     [Serializable] //this class represents the LUIS response
     public class AnalysedQuery
     {
         public TopScoringIntentData topScoringIntent;
         public EntityData[] entities;
         public string query;
     }
    
     // This class contains the Intent LUIS determines 
     // to be the most likely
     [Serializable]
     public class TopScoringIntentData
     {
         public string intent;
         public float score;
     }
    
     // This class contains data for an Entity
     [Serializable]
     public class EntityData
     {
         public string entity;
         public string type;
         public int startIndex;
         public int endIndex;
         public float score;
     }
    
     private void Awake()
     {
         // allows this class instance to behave like a singleton
         instance = this;
     }
    
     /// <summary>
     /// Call LUIS to submit a dictation result.
     /// The done Action is called at the completion of the method.
     /// </summary>
     public IEnumerator SubmitRequestToLuis(string dictationResult, Action done)
     {
         string queryString = string.Concat(Uri.EscapeDataString(dictationResult));
    
         using (UnityWebRequest unityWebRequest = UnityWebRequest.Get(luisEndpoint + queryString))
         {
             yield return unityWebRequest.SendWebRequest();
    
             if (unityWebRequest.isNetworkError || unityWebRequest.isHttpError)
             {
                 Debug.Log(unityWebRequest.error);
             }
             else
             {
                 try
                 {
                     AnalysedQuery analysedQuery = JsonUtility.FromJson<AnalysedQuery>(unityWebRequest.downloadHandler.text);
    
                     //analyse the elements of the response 
                     AnalyseResponseElements(analysedQuery);
                 }
                 catch (Exception exception)
                 {
                     Debug.Log("Luis Request Exception Message: " + exception.Message);
                 }
             }
    
             done();
             yield return null;
         }
     }
    
    
     private void AnalyseResponseElements(AnalysedQuery aQuery)
     {
         string topIntent = aQuery.topScoringIntent.intent;
    
         // Create a dictionary of entities associated with their type
         Dictionary<string, string> entityDic = new Dictionary<string, string>();
    
         foreach (EntityData ed in aQuery.entities)
         {
             entityDic.Add(ed.type, ed.entity);
         }
    
         // Depending on the topmost recognized intent, read the entities name
         switch (aQuery.topScoringIntent.intent)
         {
             case "ChangeObjectColor":
                 string targetForColor = null;
                 string color = null;
    
                 foreach (var pair in entityDic)
                 {
                     if (pair.Key == "target")
                     {
                         targetForColor = pair.Value;
                     }
                     else if (pair.Key == "color")
                     {
                         color = pair.Value;
                     }
                 }
    
                 Behaviours.instance.ChangeTargetColor(targetForColor, color);
                 break;
    
             case "ChangeObjectSize":
                 string targetForSize = null;
                 foreach (var pair in entityDic)
                 {
                     if (pair.Key == "target")
                     {
                         targetForSize = pair.Value;
                     }
                 }
    
                 if (entityDic.ContainsKey("upsize") == true)
                 {
                     Behaviours.instance.UpSizeTarget(targetForSize);
                 }
                 else if (entityDic.ContainsKey("downsize") == true)
                 {
                     Behaviours.instance.DownSizeTarget(targetForSize);
                 }
                 break;
         }
     }
    
       
 }


azure-language-understandingazure-dtl-automation
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Ines-1299 I have posted a comment on the same issue that was posted on different thread. This looks like an issue on the MR for windows where the code in the document is outdated. We would need to debug the response from LUIS and update the code accordingly.


0 Votes 0 ·

0 Answers