Closed kyteinsky closed 1 month ago
Attention: Patch coverage is 0%
with 7 lines
in your changes missing coverage. Please review.
Project coverage is 94.65%. Comparing base (
1bcd2b9
) to head (ca87be0
).
@kyteinsky should we merge this?
hey, I was working on your (and Andrey's) proposed solution to have a key in the models dict itself. It works like this. Is it too complex?
class ModelConfig(dict):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def __setitem__(self, key, value):
if key == "path":
config["loader"]["hf_model_path"] = value
service.load_config(config)
save_config_file(config)
super().__setitem__(key, value)
# download models if "model_name" key is present in the config
models_to_fetch = None
cache_dir = os.getenv("APP_PERSISTENT_STORAGE", "models/")
if "model_name" in config["loader"]:
models_to_fetch = { config["loader"]["model_name"]: ModelConfig({ "cache_dir": cache_dir }) }
@asynccontextmanager
async def lifespan(_: FastAPI):
set_handlers(
fast_api_app=APP,
enabled_handler=enabled_handler,
models_to_fetch=models_to_fetch,
)
t = BackgroundProcessTask()
t.start()
yield
I like it, it looks very nice :)
Models downloaded wrt
models_to_fetch
dict have the output path of the downloaded model files in the "path" key for each model.