如何在具有历史记录的文档上向 Langchain ConversationalRetrievalChain 聊天添加提示?

Mas*_*ion 11 python artificial-intelligence openai-api langchain

Langchain增加了这个功能ConversationalRetrievalChain,用于与历史文档聊天。根据他们的文档ConversationalRetrievalChain我需要传递作为函数指令的提示。我怎样才能通过这个函数调用来实现这一点?

这是代码

qa = ConversationalRetrievalChain.from_llm(OpenAI(temperature=0), vectorstore.as_retriever(), memory=memory)
Run Code Online (Sandbox Code Playgroud)

Rij*_*nto 14

ConversationalRetrievalChain.from_llm()您可以使用参数在方法中传递提示combine_docs_chain_kwargs。请参阅以下示例并参考您提供的示例代码:

qa = ConversationalRetrievalChain.from_llm(
    llm=OpenAI(temperature=0),
    retriever=vectorstore.as_retriever(),
    combine_docs_chain_kwargs={"prompt": prompt}
)
Run Code Online (Sandbox Code Playgroud)

如果您看到来源,则按照您提供的提示combine_docs_chain_kwargs进行操作load_qa_chain()