bha-Search / app /document_identity.py
vomebook's picture
Refactor API modules and optimize runtime image
aa0a3e7 verified
Raw
History Blame Contribute Delete
574 Bytes
import hashlib
import json
from typing import Any
def content_hash(source: dict[str, Any]) -> str:
value = {
"article": source.get("article") or {},
"title": source.get("title"),
"publication_name": source.get("publication_name"),
"publication_author": source.get("publication_author"),
"publication_type": source.get("publication_type"),
"source_files": source.get("source_files") or [],
}
return hashlib.sha256(json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()).hexdigest()