Pluggability of Cloud Storage
Last updated
Last updated
In this guide, we will learn how to plugin a new cloud storage wrapper by extending the BaseStorageClass
interface.
You can seamlessly leverage it within existing Sakhi API workflows with minimal code changes.
Cloud storage is used for storing the response generated from LLM which is then converted to audio format using a translation util. Link of the audio response files will be used by clients connecting to sakhi-api-service for playing the response.
This BaseStorageClass
class has below methods which are to be implemented mandatorily.
Method/Property | Description | Required/Optional |
---|---|---|
Let's say we create a YourStorageClass
class inheriting from BaseStorageClass.
The class needs to implement the following methods __init__, upload_to_storage and generate_public_url.
Add the necessary environment variables to .env
file. BUCKET_TYPE
is to be defined mandatorily.
Now go to the 'storage' folder and create your plugin: your_cloud.py
Go to the 'storage' folder and update __init__.py
with the module lookup entry for "YourBucketClass" and also for TYPE_CHECKING.
Modify env_manager.py
to import YourStorageClass
and add a mapping for YourStorageClass
in the self.indexes
dictionary.
This setup ensures that YourBucketClass
can be instantiated based on specific environment variables, effectively integrating it into the environment management system. The self.indexes
the dictionary now includes a mapping where "your_cloud"
corresponds to the "YourBucketClass"
class and uses "BUCKET_TYPE"
as the environment key.
__init__
Used to instantiate the storage account client
Required
upload_to_storage
Takes name of the file to be uploaded
Required
generate_public_url
Takes name of the file for which the public url is to be generated
Required