File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -1064,4 +1064,12 @@ def get_hf_model_info(repo_id: str) -> ModelInfo:
1064
1064
raise format_hf_custom_error_message (err ) from err
1065
1065
1066
1066
1067
+ @cached (cache = TTLCache (maxsize = 1 , ttl = timedelta (hours = 5 ), timer = datetime .now ))
1068
+ def list_hf_models (query :str ) -> List [str ]:
1069
+ try :
1070
+ models = HfApi ().list_models (model_name = query ,task = "text-generation" )
1071
+ return [model .id for model in models if model .disabled is None ]
1072
+ except HfHubHTTPError as err :
1073
+ raise format_hf_custom_error_message (err ) from err
1074
+
1067
1075
Original file line number Diff line number Diff line change 9
9
10
10
from ads .aqua .common .decorator import handle_exceptions
11
11
from ads .aqua .common .errors import AquaRuntimeError , AquaValueError
12
- from ads .aqua .common .utils import get_hf_model_info
12
+ from ads .aqua .common .utils import get_hf_model_info , list_hf_models
13
13
from ads .aqua .extension .base_handler import AquaAPIhandler
14
14
from ads .aqua .extension .errors import Errors
15
15
from ads .aqua .model import AquaModelApp
@@ -177,6 +177,31 @@ def _find_matching_aqua_model(model_id: str) -> Optional[AquaModelSummary]:
177
177
178
178
return None
179
179
180
+
181
+
182
+ @handle_exceptions
183
+ def get (self ,* args , ** kwargs ):
184
+ """
185
+ Finds a list of matching models from hugging face based on query string provided from users.
186
+
187
+ Parameters
188
+ ----------
189
+ query (str): The Hugging Face model name to search for.
190
+
191
+ Returns
192
+ -------
193
+ List[AquaModelSummary]
194
+ Returns the matching AquaModelSummary object if found, else None.
195
+ """
196
+
197
+ query = self .get_argument ("query" ,default = None )
198
+ if not query :
199
+ raise HTTPError (400 ,Errors .MISSING_REQUIRED_PARAMETER .format ("query" ))
200
+ models = list_hf_models (query )
201
+ return self .finish ({"models" :models })
202
+
203
+
204
+
180
205
@handle_exceptions
181
206
def post (self , * args , ** kwargs ):
182
207
"""Handles post request for the HF Models APIs
You can’t perform that action at this time.
0 commit comments