This script is used to automate the process of retraining workspaces in your Watson Assistant instance.
This script utilizes the Watson Python SDK to communicate with the Watson Assistant service. The endpoints that are utilized are:
Note that for instances for that have more than 30 workspaces, updating all the workspaces will take time because of the 30 requests / 30 minutes
rate limit. Therefore after every 30 workspaces are updated, the script sleeps for 30 minutes to reset the rate limit window.
- Retraining workspaces may change the behavior of your workspace. IBM makes regular updates to improve the Watson Assistant service, and you can see the latest changes by going to the release notes: https://cloud.ibm.com/docs/assistant?topic=assistant-release-notes#.
- IBM regularly retrains workspaces that are older than 6 months. You can see this policy here: https://cloud.ibm.com/docs/assistant?topic=assistant-skill-auto-retrain
The script uses the endpoints listed above to get the workspaces and intents. Next, the script appends "RETRAINED"
to the description of the first intent returned. This causes a retraining event to occur, and the workspace is retrained. If the workspace does not contain intents, then the entities are retrieved, and the first entity's description is updated to "RETRAINED"
.
python 3.9
pip
conda
(or another virtual environment. The steps shown below are forconda
.)
conda create -n update-workspace python=3.9 -y
conda activate update-workspace
pip install -r requirements.txt
Next, go to this link: https://cloud.ibm.com/apidocs/assistant/assistant-v1?code=python#endpoint-cloud. Copy the URL where your Watson Assistant instance is located and paste it next to URL
in the config.ini
file. Second, grab the API key for your instance and paste it to the API_KEY
field in config.ini
. You don't need to worry about the AUTH_URL
See the example_config.ini
for reference.
cd retrain
python retrain_wksp.py
During the update process, if an error is encountered, the workspace_id
is saved to "retrain_manually.txt"
These workspaces will require you to retrain the workspace manually.