File tree Expand file tree Collapse file tree 3 files changed +12
-15
lines changed Expand file tree Collapse file tree 3 files changed +12
-15
lines changed Original file line number Diff line number Diff line change 19
19
get_artifact_path ,
20
20
is_valid_ocid ,
21
21
load_config ,
22
- read_file ,
23
22
)
24
23
from ads .aqua .constants import UNKNOWN
25
24
from ads .common import oci_client as oc
@@ -363,18 +362,20 @@ def get_chat_template(self, model_id):
363
362
return chat_template
364
363
365
364
try :
366
- tokenizer_path = f"{ os .path .dirname (artifact_path )} /tokenizer_config.json"
367
- chat_template = read_file (tokenizer_path )
365
+ tokenizer_path = f"{ os .path .dirname (artifact_path )} /artifact"
366
+ chat_template = load_config (
367
+ file_path = tokenizer_path , config_file_name = "tokenizer_config.json"
368
+ )
368
369
except Exception :
369
- pass
370
+ logger .error (
371
+ f"Error reading tokenizer_config.json file for the model: { model_id } "
372
+ )
370
373
371
374
if not chat_template :
372
375
logger .error (
373
376
f"No default chat template is available for the model: { model_id } ."
374
377
)
375
- return chat_template
376
-
377
- return chat_template
378
+ return {"chat_template" : chat_template .get ("chat_template" )}
378
379
379
380
@property
380
381
def telemetry (self ):
Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ def get_artifact_path(custom_metadata_list: List) -> str:
228
228
return UNKNOWN
229
229
230
230
231
- def read_file (file_path : str , ** kwargs ) -> str :
231
+ def read_file (file_path : str , ** kwargs ) -> Union [ str , dict ] :
232
232
try :
233
233
with fsspec .open (file_path , "r" , ** kwargs .get ("auth" , {})) as f :
234
234
return f .read ()
@@ -239,10 +239,7 @@ def read_file(file_path: str, **kwargs) -> str:
239
239
240
240
@threaded ()
241
241
def load_config (file_path : str , config_file_name : str , ** kwargs ) -> dict :
242
- if config_file_name :
243
- artifact_path = f"{ file_path .rstrip ('/' )} /{ config_file_name } "
244
- else :
245
- artifact_path = f"{ file_path .rstrip ('/' )} "
242
+ artifact_path = f"{ file_path .rstrip ('/' )} /{ config_file_name } "
246
243
signer = default_signer () if artifact_path .startswith ("oci://" ) else {}
247
244
config = json .loads (
248
245
read_file (file_path = artifact_path , auth = signer , ** kwargs ) or UNKNOWN_JSON_STR
Original file line number Diff line number Diff line change 14
14
from ads .aqua .common .errors import AquaRuntimeError , AquaValueError
15
15
from ads .aqua .common .utils import (
16
16
get_hf_model_info ,
17
+ is_valid_ocid ,
17
18
list_hf_models ,
18
19
)
19
20
from ads .aqua .extension .base_handler import AquaAPIhandler
@@ -35,7 +36,6 @@ def get(
35
36
url_parse = urlparse (self .request .path )
36
37
paths = url_parse .path .strip ("/" )
37
38
path_list = paths .split ("/" )
38
- print (path_list )
39
39
if paths .startswith ("aqua/model/files" ):
40
40
os_path = self .get_argument ("os_path" , None )
41
41
model_name = self .get_argument ("model_name" , None )
@@ -329,10 +329,9 @@ def get(self, model_id):
329
329
url_parse = urlparse (self .request .path )
330
330
paths = url_parse .path .strip ("/" )
331
331
path_list = paths .split ("/" )
332
- print (path_list )
333
332
if (
334
333
len (path_list ) == 4
335
- and path_list [2 ]. startswith ( "ocid1.datasciencemodel" )
334
+ and is_valid_ocid ( path_list [2 ])
336
335
and path_list [3 ] == "chat_template"
337
336
):
338
337
return self .finish (AquaModelApp ().get_chat_template (model_id ))
You can’t perform that action at this time.
0 commit comments