Blaizzy / fastmlx

FastMLX is a high performance production ready API to host MLX models.
Other
159 stars 12 forks source link

Implement Error Handling for Unsupported Model Types #10

Open Blaizzy opened 2 months ago

Blaizzy commented 2 months ago

Description:

We need to improve our application's error handling by catching requests for unsupported model types and returning informative error responses. This will help users quickly understand when they're trying to use a model type that our system doesn't support.

Objective:

Create a mechanism to check if a requested model type is supported, and if not, return a clear error response.

Tasks:

  1. Create a list or set of supported model types in config.py.
  2. Implement a function to check if a given model type is supported.
  3. Modify the model loading or request handling process to use this check.
  4. Create a custom exception for unsupported model types.
  5. Update the API to catch this exception and return an appropriate HTTP response.

Example Implementation:

# In utils.py
MODELS= { "lm": ["gpt2", "bert", "t5", "llama"], "vlm": ["llava"]}

# In utils.py
from fastapi import HTTPException

class UnsupportedModelTypeError(Exception):
    pass

def is_supported_model_type(model_type: str) -> bool:
    return model_type.lower() in MODELS

def check_model_type(model_type: str) -> None:
    if not is_supported_model_type(model_type):
        raise UnsupportedModelTypeError(f"Model type '{model_type}' is not supported")

# In main.py or wherever model loading occurs
from fastapi import HTTPException

@app.post("/v1/load_model")
async def load_model(model_type: str, model_name: str):
    try:
        check_model_type(model_type)
        # Proceed with model loading
    except UnsupportedModelTypeError as e:
        raise HTTPException(status_code=400, detail=str(e))

Guidelines:

Resources:

Definition of Done:

We're looking forward to your contribution! This feature will greatly improve the user experience by providing clear feedback when unsupported model types are requested. If you have any questions or need clarification, please don't hesitate to ask in the comments. Good luck!