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:
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.