mmz-001 / knowledge_gpt

Accurate answers and instant citations for your documents.
https://knowledgegpt.streamlit.app/
MIT License
1.58k stars 729 forks source link

Deprecated functions #20

Closed openmenta closed 1 year ago

openmenta commented 1 year ago

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"

mmz-001 commented 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.

David2265 commented 1 year ago

hi, is there any solution regards the error above?

David2265 commented 1 year ago

error solved by changing the st.cache() to st.cache_data() without the parameters

swamichandra commented 1 year ago

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?

swamichandra commented 1 year ago

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?

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