Skip to content

Utils

dict_hash(dictionary: Dict[str, Any]) -> str

Hash dictionary using MD5. Used in step caching; steps are cached based on the signature.

Source code in ragfoundry/processing/utils.py
def dict_hash(dictionary: Dict[str, Any]) -> str:
    """
    Hash dictionary using MD5. Used in step caching; steps are cached based on the signature.
    """
    dhash = hashlib.md5()
    encoded = json.dumps(dictionary, sort_keys=True).encode()
    dhash.update(encoded)
    return dhash.hexdigest()

is_jsonable(x)

Test if input is JSON-serializable.

Source code in ragfoundry/processing/utils.py
def is_jsonable(x):
    """
    Test if input is JSON-serializable.
    """
    try:
        json.dumps(x)
        return True
    except (TypeError, OverflowError):
        return False