- Load the model from your local disk (see Load Model from Disk)
- Fetch the model from your own HTTP server (see Load Model from Server)
- Fetch the model from cloud storage like S3 (see Load Model from Cloud)
Load Model from Disk
By default, models will be loaded from your local disk. You can specify the path to your model with the--model parameter:
--model argument, Rasa will look for models in the models/ directory. The two following calls
will load the same model:
Load Model from Server
You can configure the Rasa server to regularly fetch a model from a server and deploy it.How to Configure Rasa
You can configure the HTTP server to fetch models from another URL by adding it to yourendpoints.yml:
endpoints.yml
url for a zipped model every wait_time_between_pulls
seconds.
If you want to pull the model only when starting up the server, you can set the time
between pulls to null:
endpoints.yml
How to Configure Your Server
Rasa will send aGET request to the URL you specified in the
endpoints.yml, e.g. http://my-server.com/models/default in the above examples.
You can use any URL.
The GET request will contain an If-None-Match header that contains the
model hash of the last model it downloaded. An example request from Rasa Open
Source to your server would look like this:
GET request should be one of these:
- a status code of
200, a zipped Rasa Model and set theETagheader in the response to the hash of the model. - a status code of
304and an empty response if theIf-None-Matchheader of the request matches the model you want your server to return.
If-None-Match and ETag headers for caching. Setting
the headers will avoid re-downloading the same model over and over, saving
bandwidth and compute resources.
Load Model from Cloud
You can also configure the Rasa server to fetch your model from a remote storage by indicating theremote-storage CLI
option when starting the Rasa server. This allows you to retrieve your models from a cloud storage service like Amazon S3,
Google Cloud Storage, or Azure Storage.
Ensure you always specify the model name with the --model parameter
when running the Rasa server, for example:
--model
parameter. Alternatively, you can also provide the environment variable REMOTE_STORAGE_PATH and point to a sub folder
within your bucket: note that this latter method is deprecated and will be removed in the next 4.0 major release.
- Amazon S3,
- Google Cloud Storage,
- Azure Storage and
- custom implementations for Other Remote Storages.
Amazon S3 Storage
Amazon S3 is supported using theboto3 package which is already included in Rasa.
For Rasa to be able to authenticate and download the model, you need to set up an authentication method:
- use the required AWS access environment variables:
AWS_ACCESS_KEY_ID: environment variable containing your AWS S3 access key IDAWS_SECRET_ACCESS_KEY: environment variable containing your AWS S3 secret access key
- if you are running Rasa on an AWS service like EC2, you can use an IAM role with the necessary permissions to access the S3 bucket. The IAM role should include the following permissions:
AWS_DEFAULT_REGION: environment variable specifying the region of your AWS S3 bucketBUCKET_NAME: environment variable specifying the S3 bucketAWS_ENDPOINT_URL: The complete URL to use for the AWS S3 requests. You need to specify a complete URL (including the “http/https” scheme). For example, you could use one of the Amazon S3 endpoints documented for the region you are using. If you are using a custom endpoint, you can specify it here. Note that by setting the bucket name toBUCKET_NAMEenvironment variable, you should not provide the bucket or object URL toAWS_ENDPOINT_URL.
remote-storage option set to aws:
Google Cloud Storage
Google Cloud Storage (GCS) is supported using thegoogle-cloud-storage package
which is already included in Rasa.
If you are running Rasa on Google App Engine or Compute Engine, the auth
credentials are already set up (for the GCS in the same project). In this case,
you can skip setting any additional environment variables.
If you are running locally or on a machine outside of GAE or GCE you need to
provide the authentication details to Rasa manually:
- Check out the GCS documentation to create a service account key.
- Set an environment variable called
GOOGLE_APPLICATION_CREDENTIALSto the path of a service account key file with access to your GCS. - Set an environment variable called
BUCKET_NAMEto the name of your GCS bucket.
remote-storage option set to gcs:
Azure Storage
Azure Storage is supported using theazure-storage-blob package
which is already included in Rasa.
For Rasa to be able to authenticate and download the model, you need to set the
following environment variables before running any command requiring the storage:
AZURE_CONTAINER: environment variable containing your azure container nameAZURE_ACCOUNT_NAME: environment variable containing your azure account nameAZURE_ACCOUNT_KEY: environment variable containing your account key
remote-storage option set to azure:
Other Remote Storages
If you want to use any other Cloud Storage, you can provide your own python implementation of therasa.core.persistor.Persistor class, which must inherit
from the Persistor interface. This allows you to implement your own logic for
retrieving and persisting models to your remote storage.
We recommend you add your custom persistor module to the root of the assistant project before starting the Rasa
server, so that Rasa can find your custom persistor class. For example, this is how your project structure could look like:
remote-storage option set to
the module path of your persistor implementation:
-v option:
Persistor Interface
ThePersistor interface requires you to implement the following methods:
Example Persistor Implementations
Here are some example custom implementations of thePersistor interface for the following remote storage types:
JFrog Artifactory
You can use the JFrog Artifactory as a remote storage for your models. To use it, you can implement thePersistor interface:
my_custom_persistor.py
remote-storage option set to your custom persistor class.
For example, if you have implemented the above custom persistor class called JFrogArtifactoryPersistor in a module my_custom_persistor.py, you can run the Rasa server like this:
Sonatype Nexus Repository
You can use the Sonatype Nexus Repository as a remote storage for your models. To use it, you can implement thePersistor interface:
my_custom_persistor.py
remote-storage option set to your custom persistor class.
For example, if you have implemented the above custom persistor class called SonatypeNexusRepositoryPersistor in a module my_custom_persistor.py, you can run the Rasa server like this:
Save Model To Cloud
New in 3.10You can now also save models to cloud after training.
It is useful to provide a fixed model name while pushing model to remote storage, as you can refer the same name while
downloading and running the rasa bot. If no fixed model name is provided, rasa will generate a model name and upload it
to remote storage.
- Amazon S3,
- Google Cloud Storage,
- Azure Storage and
- custom implementations for Other Remote Storages.
--out parameter during training, along with the --remote-storage option:
--out parameter is not specified, the model will be uploaded to the default /models directory in the cloud storage bucket.