Setting up CI/CD
Setting up CI/CD
Even though developing a contextual assistant is different from developing traditional software, you should still follow software development best practices. Setting up a Continuous Integration (CI) and Continuous Deployment (CD) pipeline ensures that incremental updates to your bot are improving it, not harming it.
- Overview: Continuous Integration (CI) is the practice of merging in code changes frequently and automatically testing changes as they are committed. Continuous Deployment (CD) means automatically deploying integrated changes to a staging or production environment. Together, they allow you to make more frequent improvements to your assistant and efficiently test and deploy those changes.
Continuous Integration (CI)
The best way to improve an assistant is with frequent incremental updates. No matter how small a change is, you want to be sure that it doesn’t introduce new problems or negatively impact the performance of your assistant.
It is usually best to run CI checks on merge/pull requests or on commit. Most tests are quick enough to run on every change. However, you can choose to run more resource-intensive tests only when certain files have been changed or when some other indicator is present.
Validate Data and Stories
Data validation verifies that there are no mistakes or major inconsistencies in your domain file, NLU data, or story data.
rasa data validate --fail-on-warnings --max-history <max_history>
If data validation results in errors, training a model will also fail.
Train a Model
rasa train
Training a model verifies that your NLU pipeline and policy configurations are valid and trainable, and it provides a model to use for test conversations.
Test the Assistant
Testing your trained model on test conversations is the best way to have confidence in how your assistant will act in certain situations.
rasa test --stories tests/conversation_tests.md --fail-on-prediction-errors
The --fail-on-prediction-errors flag ensures the test will fail if any test conversation fails.
Compare NLU Performance
If you’ve made significant changes to your NLU training data, you should run a full NLU evaluation.
rasa test nlu --cross-validation
Test Action Code
The approach used to test your action code will depend on how it is implemented. For example, if you connect to external APIs, it is recommended to write unit tests to ensure that those APIs respond as expected to common inputs.
Continuous Deployment (CD)
To get improvements out to your users frequently, you will want to automate as much of the deployment process as possible.
Deploy your Rasa Model
If you ran end-to-end tests in your CI pipeline, you’ll already have a trained model. You can set up your CD pipeline to upload the trained model to your Rasa server if the CI results are satisfactory.
curl -k -F "model=@models/my_model.tar.gz" "https://example.rasa.com/api/projects/default/models?api_token={your_api_token}"
Deploy your Action Server
You can automate the building and uploading of a new image for your action server to an image repository for each update to your action code.
Example CI/CD pipelines
As examples, see the CI/CD pipelines for Sara and Carbon Bot. Both use Github Actions as a CI/CD tool.
👋 I can help you get started with Rasa and answer your technical questions.