SatwantKumar / lanarky

FastAPI framework to build production-grade LLM applications
https://lanarky.readthedocs.io/en/latest/
MIT License
0 stars 0 forks source link

Simplify Output of ConversationalRetrievalChain (back-end) #1

Open SatwantKumar opened 1 year ago

SatwantKumar commented 1 year ago

Description: Currently, the ConversationalRetrievalChain provides detailed information about the entire process of question answering, including intermediate stages. This can make it harder to extract the final answer, especially when used in combination with the FAST API call.

Implement a feature to simplify the output of the ConversationalRetrievalChain to deliver only the final answer.

This feature should have the following:

codeautopilot[bot] commented 1 year ago

To simplify the output of the ConversationalRetrievalChain in this file, we need to modify the create_chain() function to streamline the retrieval of relevant documents from the vector database, condensation of the question and chat history into a standalone question, and generation of the response with the final answer. Specifically, we need to remove the verbose=True argument from the ConversationalRetrievalChain constructor to suppress the intermediate stages of the question answering process and only return the final answer. We also need to remove the return_source_documents=True argument to avoid returning the intermediate documents. The modified create_chain() function should look like this:

def create_chain():
    db = FAISS.load_local(
        folder_path="vector_stores/",
        index_name="langchain-python",
        embeddings=OpenAIEmbeddings(),
    )

    question_generator = LLMChain(
        llm=ChatOpenAI(
            temperature=0,
            streaming=True,
        ),
        prompt=CONDENSE_QUESTION_PROMPT,
    )
    doc_chain = load_qa_chain(
        llm=ChatOpenAI(
            temperature=0,
            streaming=True,
        ),
        chain_type="stuff",
    )

    return ConversationalRetrievalChain(
        combine_docs_chain=doc_chain,
        question_generator=question_generator,
        retriever=db.as_retriever(),
        # Remove verbose=True to suppress intermediate stages
        # Remove return_source_documents=True to avoid returning intermediate documents
    )

With these changes, the ConversationalRetrievalChain will only return the final answer, making it easier to extract the answer when used in combination with the FAST API call.


Current plan usage: NaN%


**Have feedback or need help?** Send me an email to [support@codeautopilot.com](mailto:support@codeautopilot.com) - my name is Fábio [Join us on Discord](https://discord.gg/r72ykfvyx7)
daiwuxing commented 1 year ago

I use this code ,but it didn't work ,it still answer me with other question