[Core][Bugfix] Accept GGUF model without .gguf extension (#8056)

This commit is contained in:
Isotr0py
2024-09-02 20:43:26 +08:00
committed by GitHub
parent e2b2aa5a0f
commit 4ca65a9763
4 changed files with 23 additions and 5 deletions

View File

@@ -0,0 +1,16 @@
from os import PathLike
from pathlib import Path
from typing import Union
def check_gguf_file(model: Union[str, PathLike]) -> bool:
"""Check if the file is a GGUF model."""
model = Path(model)
if not model.is_file():
return False
elif model.suffix == ".gguf":
return True
with open(model, "rb") as f:
header = f.read(4)
return header == b"GGUF"