def extract_commit_hash(
    resolved_dir: str, regex_commit_hash: t.Pattern[str]
) -> str | None:
    """
    Extracts the commit hash from a resolved filename toward a cache file.
    modified from https://github.com/huggingface/transformers/blob/0b7b4429c78de68acaf72224eb6dae43616d820c/src/transformers/utils/hub.py#L219
    """

    resolved_dir = str(Path(resolved_dir).as_posix()) + "/"
    search = re.search(r"snapshots/([^/]+)/", resolved_dir)

    if search is None:
        return None

    commit_hash = search.groups()[0]
    return commit_hash if regex_commit_hash.match(commit_hash) else None
Extracts the commit hash from a resolved filename toward a cache file.
modified from https://github.com/huggingface/transformers/blob/0b7b4429c78de68acaf72224eb6dae43616d820c/src/transformers/utils/hub.py#L219
src/bentoml/_internal/frameworks/utils/transformers.py