Anil-matcha / ChatPDF

Chat with any PDF. Easily upload the PDF documents you'd like to chat with. Instant answers. Ask questions, extract information, and summarize documents with AI. Sources included.
https://www.thesamur.ai/?utm_source=github&utm_medium=link&utm_campaign=github_chatpdf
MIT License
1.38k stars 213 forks source link

How the response from ChatGPT is written in the UI? #7

Open smith-co opened 1 year ago

smith-co commented 1 year ago

I see you have an input field with a callback process_input:

st.text_input("Message", key="user_input", disabled=not is_openai_api_key_set(), on_change=process_input)

This callback process_input is:

def process_input():
    if st.session_state["user_input"] and len(st.session_state["user_input"].strip()) > 0:
        user_text = st.session_state["user_input"].strip()
        with st.session_state["thinking_spinner"], st.spinner(f"Thinking"):
            query_text = st.session_state["pdfquery"].ask(user_text)

        st.session_state["messages"].append((user_text, True))
        st.session_state["messages"].append((query_text, False))

Here you are only writing the response from the model into the st.session_state["messages"]. How the response is getting written the to the UI?

Will appreciate if you can please add an explanation. Thanks.