INNER CODE UNIT · Python
create_lifespan
cubist38/mlx-openai-server · app/server.py:134
def create_lifespan(config_args: MLXServerConfig):
"""Create an async FastAPI lifespan context manager bound to configuration.
The returned context manager performs the following actions during
application startup:
- Determine the model identifier from the provided ``config_args``
- Instantiate the appropriate MLX handler based on ``model_type``
(multimodal, image-generation, image-edit, embeddings, whisper, or
text LM)
- Initialize the handler (including queuing and concurrency setup)
- Perform an initial memory cleanup
During shutdown the lifespan will attempt to call the handler's
``cleanup`` method and perform final memory cleanup.
Args:
config_args: Object containing CLI configuration attributes used