@@ -40,7 +40,9 @@ class ListAudioModelsResponse(BaseModel):
4040
4141# HACK: returning ListModelsResponse directly causes extra `Model` fields to be omitted
4242@router .get ("/v1/audio/models" , response_model = ListAudioModelsResponse )
43- def list_local_audio_models (executor_registry : ExecutorRegistryDependency ) -> JSONResponse :
43+ def list_local_audio_models (
44+ executor_registry : ExecutorRegistryDependency ,
45+ ) -> JSONResponse :
4446 models : list [Model ] = []
4547 for executor in executor_registry .text_to_speech :
4648 models .extend (list (executor .model_registry .list_local_models ()))
@@ -53,7 +55,9 @@ class ListVoicesResponse(BaseModel):
5355
5456# HACK: returning ListModelsResponse directly causes extra `Model` fields to be omitted
5557@router .get ("/v1/audio/voices" , response_model = ListModelsResponse )
56- def list_local_audio_voices (executor_registry : ExecutorRegistryDependency ) -> JSONResponse :
58+ def list_local_audio_voices (
59+ executor_registry : ExecutorRegistryDependency ,
60+ ) -> JSONResponse :
5761 models : list [KokoroModel | PiperModel ] = []
5862 for executor in executor_registry .text_to_speech :
5963 models .extend (list (executor .model_registry .list_local_models ()))
@@ -77,14 +81,14 @@ def get_local_model(executor_registry: ExecutorRegistryDependency, model_id: Mod
7781# NOTE: without `response_model` and `JSONResponse` extra fields aren't included in the response
7882@router .post ("/v1/models/{model_id:path}" )
7983def download_remote_model (executor_registry : ExecutorRegistryDependency , model_id : ModelId ) -> Response :
80- for executor in executor_registry . all_executors () :
81- if model_id in [ model . id for model in executor . model_registry . list_remote_models ()]:
82- was_downloaded = executor . model_registry . download_model_files_if_not_exist ( model_id )
83- if was_downloaded :
84- return Response ( status_code = 200 , content = f"Model ' { model_id } ' downloaded" )
85- else :
86- return Response ( status_code = 201 , content = f"Model ' { model_id } ' already exists" )
87- raise HTTPException (status_code = 404 , detail = f"Model '{ model_id } ' not found" )
84+ try :
85+ was_downloaded = executor_registry . download_model_by_id ( model_id )
86+ if was_downloaded :
87+ return Response ( status_code = 200 , content = f"Model ' { model_id } ' downloaded" )
88+ else :
89+ return Response ( status_code = 201 , content = f"Model ' { model_id } ' already exists" )
90+ except ValueError as error :
91+ raise HTTPException (status_code = 404 , detail = f"Model '{ model_id } ' not found" ) from error
8892
8993
9094# TODO: document that any model will be deleted regardless if it's supported speaches or not
0 commit comments