Closed openmenta closed 1 year ago
Yes, we should move to the new st.cache_data
and st.cache_resource
caching commands as st.cache
will be deprecated in the future.
hi, is there any solution regards the error above?
error solved by changing the st.cache() to st.cache_data() without the parameters
In utils.py if I change the decorator right before def embed_docs(docs: List[Document]) -> VectorStore:
to st.cache_data()
, I get a
UnhashableParamError: Cannot hash argument 'docs' (of type builtins.list) in 'embed_docs'.
To address this, you can tell Streamlit not to hash this argument by adding a leading underscore to the argument's name in the function signature:
How did you fix this?
In utils.py if I change the decorator right before
def embed_docs(docs: List[Document]) -> VectorStore:
tost.cache_data()
, I get aUnhashableParamError: Cannot hash argument 'docs' (of type builtins.list) in 'embed_docs'. To address this, you can tell Streamlit not to hash this argument by adding a leading underscore to the argument's name in the function signature:
How did you fix this?
Spoke too soon. This is how I fixed it.
#@st.cache(allow_output_mutation=True, show_spinner=False)
@st.cache_data()
def embed_docs(_docs: List[Document]) -> VectorStore:
"""Embeds a list of Documents and returns a FAISS index"""
docsp = _docs
if not st.session_state.get("OPENAI_API_KEY"):
raise AuthenticationError(
"Enter your OpenAI API key in the sidebar. You can get a key at"
" https://platform.openai.com/account/api-keys."
)
else:
# Embed the chunks
embeddings = OpenAIEmbeddings(
openai_api_key=st.session_state.get("OPENAI_API_KEY")
) # type: ignore
index = FAISS.from_documents(docsp, embeddings)
return index
Should I change st.cache and st.experimental_memo? When I try with st.cache_data raises an error for an unexpected argument: "allow_output_mutation=True"