Pluggability of Cloud Storage
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.
Integration
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.
BaseStorageClass
This BaseStorageClass
class has below methods which are to be implemented mandatorily.
Implementation
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.
Last updated