Artificial Intelligence Forum
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

AI Core SDK Create an Artifact

0 Likes
2,105

I am trying to create an artifact, but response says: Failed to create artifact. Status code: 404
It used to complain about the scenario id, but has not lately

artifact that I am trying to create:
{'name': 'sound-data', 'kind': 'dataset', 'url': 'ai://sound/data', 'description': 'Cutting machine sound clips for defect detection', 'scenario_id': 'sound-scen'}

# Load AICoreServiceKey.json
AICoreServiceKeyFile = r"C:\Users\I840539\testjson\AICoreServiceKey.json"
uua_url, clientid, clientsecret, ai_api_url, token = get_ai_service_key(AICoreServiceKeyFile)

Code:

# Load training_workflow.yaml
training_workflow_file = './files/training_workflow.yaml'
with open(training_workflow_file) as twf:
training_workflow = yaml.safe_load(twf)

print('training_workflow: \n', training_workflow)

# Load scenario id from train_workflow.yaml
scenario_id = training_workflow['metadata']['labels']['scenarios.ai.sap.com/id']
print('scenario_id: ', scenario_id)

# Set the artifact configuration
artifact = {
"name": "sound-data", # Modifiable name
"kind": "dataset",
"url": "ai://rds-ai-core-training-api/data",
"description": "Cutting machine sound clips for defect detection",
"scenario_id": scenario_id
}
print('artifact: \n', artifact)

# Prepare headers with authorization token
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {token}'
}

# Make the POST request to create the artifact
url = f"{ai_api_url}/v2/admin/artifacts"
response = requests.post(url=url, json=artifact, headers=headers)

# Check response status
if response.status_code == 200:
print("Artifact created successfully.")
else:
print(f"Failed to create artifact. Status code: {response.status_code}")
print(f"Error message: {response.text}")

 

1 ACCEPTED SOLUTION
Read only

anurag_batra
Advisor
Advisor
0 Likes
2,001

Hi Robert,

404 Error stands for the server cannot find the requested resource and as per what I can see in your code looks like the URL you are using to create an artifact is wrong instead of {ai_api_url}/v2/admin/artifacts it should be{ai_api_url}/v2/lm/artifacts

View solution in original post

2 REPLIES 2
Read only

anurag_batra
Advisor
Advisor
0 Likes
2,002

Hi Robert,

404 Error stands for the server cannot find the requested resource and as per what I can see in your code looks like the URL you are using to create an artifact is wrong instead of {ai_api_url}/v2/admin/artifacts it should be{ai_api_url}/v2/lm/artifacts

Read only

0 Likes
1,989

Hi, I tried AI Core Client and AI Client, and also AI Client with tht path. The error was from my workflow having an error. I found the error when I checked the status of one of the components, maybe application. In the status json it mentioned that workflow failed, which means the scenario didn't get created. I marked your reply correct, because if that was my issue it would be correct. Thanks.