

AI Core SDK Create an Artifact
source link: https://community.sap.com/t5/artificial-intelligence-and-machine-learning/ai-core-sdk-create-an-artifact/td-p/13601441
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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}")
</div
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK