Model environments help configure behavior based on deployment stage (e.g., production vs. staging). You can access the environment details via kwargs
in the Model
class.
1. Retrieve Environment Variables
Access the environment in __init__
:
def __init__(self, **kwargs):
self._environment = kwargs["environment"]
Use environment variables in the load
function:
def load(self):
if self._environment.get("name") == "production":
# Production setup
self.setup_sentry()
self.setup_logging(level="INFO")
self.load_production_weights()
else:
# Default setup for staging or development deployments
self.setup_logging(level="DEBUG")
self.load_default_weights()
Why use this?
- Customize logging levels
- Load environment-specific model weights
- Enable monitoring tools (e.g., Sentry)
Responses are generated using AI and may contain mistakes.