简体   繁体   中英

How to export automatically the content of an assistant in the new user experience of Watson Assistant?

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 ?

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.

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

Sample: Export skill

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

显示数据的 UI 图片可以找到以填写代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM