utils.py 396 B

12345678910111213141516
  1. from os import PathLike
  2. from pathlib import Path
  3. from typing import Union
  4. def check_gguf_file(model: Union[str, PathLike]) -> bool:
  5. """Check if the file is a GGUF model."""
  6. model = Path(model)
  7. if not model.is_file():
  8. return False
  9. elif model.suffix == ".gguf":
  10. return True
  11. with open(model, "rb") as f:
  12. header = f.read(4)
  13. return header == b"GGUF"