Team Ai
Apppublic

andreped/ReferenceBot

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
caching.py28 linesDownload Raw Back to core
1import streamlit as st2from streamlit.runtime.caching.hashing import HashFuncsDict3 4import knowledge_gpt.core.chunking as chunking5import knowledge_gpt.core.embedding as embedding6import knowledge_gpt.core.parsing as parsing7from knowledge_gpt.core.parsing import File8 9 10def file_hash_func(file: File) -> str:11    """Get a unique hash for a file"""12    return file.id13 14 15@st.cache_data(show_spinner=False)16def bootstrap_caching():17    """Patch module functions with caching"""18 19    # Get all substypes of File from module20    file_subtypes = [21        cls for cls in vars(parsing).values() if isinstance(cls, type) and issubclass(cls, File) and cls != File22    ]23    file_hash_funcs: HashFuncsDict = {cls: file_hash_func for cls in file_subtypes}24 25    parsing.read_file = st.cache_data(show_spinner=False)(parsing.read_file)26    chunking.chunk_file = st.cache_data(show_spinner=False, hash_funcs=file_hash_funcs)(chunking.chunk_file)27    embedding.embed_files = st.cache_data(show_spinner=False, hash_funcs=file_hash_funcs)(embedding.embed_files)28