Empty string response after request to import a Conversational Language Understanding project

Zhaoyi Zhu 21 Reputation points
2024-10-29T08:55:17.9633333+00:00

Greetings,

I am following the the following Azure Guide to import a project in Azure AI Language. https://learn.microsoft.com/en-us/azure/ai-services/language-service/conversational-language-understanding/how-to/fail-over#import-to-a-new-project

The document states "Upon a successful request, the API response will contain an operation-location header with a URL you can use to check the status of the import job." However, as I receive response code 202, the response content is ''. And from Language Studio, the expected project is not seen.

My code is pasted here

os.environ["LS_CONVERSATIONS_ENDPOINT"] = "{my-endpoint}"
os.environ['LS_CONVERSATIONS_KEY'] = "{my-key}"

# Import project
azure_endpoint = os.environ.get("LS_CONVERSATIONS_ENDPOINT")
azure_key = os.environ.get("LS_CONVERSATIONS_KEY")
project_name = 'training-assistant'
API_VERSION = "2023-04-01"
LS_PROJECT_URL =  f"{azure_endpoint}/language/authoring/analyze-conversations/projects/{project_name}/:import?api-version={API_VERSION}"

header = {
    "Ocp-Apim-Subscription-Key": azure_key,
}

file_path = "{path to the following json file}\\training-assistant-project.json"

with open(file_path, 'r') as file:
    data = json.load(file)

response = requests.post(LS_PROJECT_URL, headers=header, json=data)
response.content

file_path is pointing to the following file.


{
  "projectFileVersion":"2023-04-01",
  "stringIndexType":"Utf16CodeUnit",
  "metadata":{
     "projectKind":"Conversation",
     "settings":{
        "confidenceThreshold":0.7
     },
     "projectName":"training-assistant",
     "multilingual":true,
     "description":"Trying out CLU",
     "language":"en-us"
  },
  "assets":{
     "projectKind":"Conversation",
     "intents":[
        {
           "category":"CalculateTime"
        }
     ],
     "entities":[
		{           
			"category":"LastXActivity"
        }
     ],
     "utterances":[
        {"text": "What is the longest time did I run at one go?","dataset": "Train","intent": "CalculateTime","entities": []},
        {"text": "How long did I run for the last run?","dataset": "Train","intent": "CalculateTime","entities": [{"category": "LastXActivity","offset": 28,"length": 8}]}
        
     ]
  }
}
Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
421 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. santoshkc 9,485 Reputation points Microsoft Vendor
    2024-10-29T14:39:41.7966667+00:00

    Hi @Zhaoyi Zhu,

    Thank you for reaching out to Microsoft Q&A forum!

    I tried to repro the scenario with the following Python code and JSON file.

    import os
    import json
    import requests
    
    os.environ["LS_CONVERSATIONS_ENDPOINT"] = "ENDPOINT>"
    os.environ['LS_CONVERSATIONS_KEY'] = "<KEY>"
    
    # Import project
    azure_endpoint = os.environ.get("LS_CONVERSATIONS_ENDPOINT")
    azure_key = os.environ.get("LS_CONVERSATIONS_KEY")
    project_name = 'training-assistant'
    API_VERSION = "2023-04-01"
    LS_PROJECT_URL = f"{azure_endpoint}/language/authoring/analyze-conversations/projects/{project_name}/:import?api-version={API_VERSION}"
    
    header = {
        "Ocp-Apim-Subscription-Key": azure_key,
    }
    
    file_path = r"C:\Users\XXXXXXX\lang.json" # Provide your file path
    
    with open(file_path, 'r') as file:
        data = json.load(file)
    
    # Debug: Print the data being sent
    print(json.dumps(data, indent=2))
    
    response = requests.post(LS_PROJECT_URL, headers=header, json=data)
    
    # Check if the request was accepted
    if response.status_code == 202:
        print("Import request accepted. Checking status...")
    
        # Debug: Print response headers
        print("Response Headers:", response.headers)
    
        # Use the correct header to get the operation location
        operation_location = response.headers.get("operation-location")
        if not operation_location:
            print("No operation-location header found in the response.")
        else:
            while True:
                # Check the operation status
                status_response = requests.get(operation_location, headers=header)
                status_code = status_response.status_code
    
                if status_code == 200:
                    status_data = status_response.json()
                    print("Operation Status:", status_data)
                    break
                elif status_code == 202:
                    print("Still processing... waiting for 5 seconds.")
                    time.sleep(5)  # Wait before checking again
                else:
                    print("Error checking status:", status_response.text)
                    break
    else:
        print("Error:", response.text)
    

    JSON file:

    {
      "projectFileVersion": "2023-04-01",
      "stringIndexType": "Utf16CodeUnit",
      "metadata": {
        "projectKind": "Conversation",
        "settings": {
          "confidenceThreshold": 0.7
        },
        "projectName": "training-assistant",
        "multilingual": true,
        "description": "Trying out CLU",
        "language": "en-us"
      },
      "assets": {
        "projectKind": "Conversation",
        "intents": [
          {
            "category": "CalculateTime"
          }
        ],
        "entities": [
          {
            "category": "LastXActivity"
          }
        ],
        "utterances": [
          {
            "text": "What is the longest time did I run at one go?",
            "dataset": "Train",
            "intent": "CalculateTime",
            "entities": []
          },
          {
            "text": "How long did I run for the last run?",
            "dataset": "Train",
            "intent": "CalculateTime",
            "entities": [
              {
                "category": "LastXActivity",
                "offset": 28,
                "length": 8
              }
            ]
          }
        ]
      }
    }
    

    Project reflected in the Language Studio:User's image

    I hope this helps. Still if you face any errors, do let us know will try to figure out the issue or escalate this to the concerned team.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.