import hashlib
from collections.abc import Callable
from typing import Any


def generate_key(
        func: Callable,
        args: tuple[Any],
        kwargs: dict[str, Any],
        prefix: str,
        key_format: str
) -> str:
    args_hash = hashlib.md5(repr(args).encode()).hexdigest()
    kwargs_hash = hashlib.md5(repr(kwargs).encode()).hexdigest()
    return key_format.format(
        args_hash=args_hash,
        kwargs_hash=kwargs_hash,
        func_name=func.__name__,
        prefix=prefix
    )
