Reputation: 21
In the new user experience you can download content of an assistant manually in JSON format. However, I need to do it automatically.
I'm able to export/download the content of a workspace by using get_workspace method with export=True by using V1 of the API. However, in the new user experience where I built an action skills based chat bot, I can't get the workspace id which is required for this method. Is there other option or some workaround to download the assistant's content in the new user experience?
Upvotes: 0
Views: 400
Reputation: 9359
As Brian mentioned the API is available now, but the documentation isn't up to date. There will also be further updates which will likely make easier (again no official date).
At the moment the export only exports the "Draft".
import requests
from time import sleep
import json
username = 'apikey'
password = '<API_KEY>'
service_instance = '<SERVICE_URL>'
assistant_id = '<ASSISTANT_ID>'
version = '2021-11-27'
url = f'{service_instance}/v2/assistants/{assistant_id}/skills_export?version={version}'
max_tries = 3
skill = None
while max_tries > 0:
data = requests.get(url, auth=(username, password)).json()
if 'assistant_skills' in data:
skill = data['assistant_skills'][0]
break
if 'error' in data:
print(data)
break
sleep(5)
print(f'Retrying {max_tries}...')
max_tries = max_tries - 1
if skill is not None:
filename = f"{skill['name'].replace(' ', '-')}-action.json"
print(f"Skill downloaded: {filename}")
with open(filename, 'w') as file:
file.write(json.dumps(skill, indent=2))
The related fields can be gotten from the environment settings (click cog on Draft).
Upvotes: 0
Reputation: 636
You can now import/export skills now in the new user experience using these APIs:
https://cloud.ibm.com/apidocs/assistant/assistant-v2#exportskills https://cloud.ibm.com/apidocs/assistant/assistant-v2#importskills
Note that these are not currently supported in the SDKs but they should get picked up in the next release.
Upvotes: 1