diff --git a/refact_webgui/webgui/selfhost_fastapi_completions.py b/refact_webgui/webgui/selfhost_fastapi_completions.py index 7019133c..fde7f6aa 100644 --- a/refact_webgui/webgui/selfhost_fastapi_completions.py +++ b/refact_webgui/webgui/selfhost_fastapi_completions.py @@ -311,14 +311,12 @@ def _select_default_lora_if_exists(model_name: str, running_models: List[str]): async def _local_tokenizer(self, model_path: str) -> str: model_dir = Path(env.DIR_WEIGHTS) / f"models--{model_path.replace('/', '--')}" - tokenizer_paths = list(model_dir.rglob("tokenizer.json")) + tokenizer_paths = list(sorted(model_dir.rglob("tokenizer.json"), key=lambda p: p.stat().st_ctime)) if not tokenizer_paths: raise HTTPException(404, detail=f"tokenizer.json for {model_path} does not exist") - if len(tokenizer_paths) > 1: - raise HTTPException(404, detail=f"multiple tokenizer.json for {model_path}") data = "" - async with aiofiles.open(tokenizer_paths[0], mode='r') as f: + async with aiofiles.open(tokenizer_paths[-1], mode='r') as f: while True: if not (chunk := await f.read(1024 * 1024)): break