Files
MemoryBear/app/core/rag/graphrag/utils.py
2025-11-30 18:22:17 +08:00

20 lines
578 B
Python

import xxhash
from app.aioRedis import aio_redis_set, aio_redis_get
def get_llm_cache(llmnm, txt, history, genconf):
hasher = xxhash.xxh64()
hasher.update((str(llmnm)+str(txt)+str(history)+str(genconf)).encode("utf-8"))
k = hasher.hexdigest()
bin = aio_redis_get(k)
if not bin:
return None
return bin
def set_llm_cache(llmnm, txt, v, history, genconf):
hasher = xxhash.xxh64()
hasher.update((str(llmnm)+str(txt)+str(history)+str(genconf)).encode("utf-8"))
k = hasher.hexdigest()
aio_redis_set(k, v.encode("utf-8"), 24 * 3600)