ConversationalRetrievalChain new_question only from the question_generator only for retrieval and not for combine_docs_chain #5499
Answered
by
ARSblithe212
lucasiscovici
asked this question in
Q&A
-
Hello and thank you for this amazing library. Here we :
1/ It's possible to allow to call the question_generator event if the chat_history_str is empty ? 2/ It's possible to not use the new_question in the combine_docs_chain call ? Thanks in advance def _call(
self,
inputs: Dict[str, Any],
run_manager: Optional[CallbackManagerForChainRun] = None,
) -> Dict[str, Any]:
_run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager()
question = inputs["question"]
get_chat_history = self.get_chat_history or _get_chat_history
chat_history_str = get_chat_history(inputs["chat_history"])
if chat_history_str:
callbacks = _run_manager.get_child()
new_question = self.question_generator.run(
question=question, chat_history=chat_history_str, callbacks=callbacks
)
else:
new_question = question
docs = self._get_docs(new_question, inputs)
new_inputs = inputs.copy()
new_inputs["question"] = new_question
new_inputs["chat_history"] = chat_history_str
answer = self.combine_docs_chain.run(
input_documents=docs, callbacks=_run_manager.get_child(), **new_inputs
)
if self.return_source_documents:
return {self.output_key: answer, "source_documents": docs}
else:
return {self.output_key: answer} |
Beta Was this translation helpful? Give feedback.
Answered by
ARSblithe212
Jun 1, 2023
Replies: 1 comment
-
you can realize your chain, rewrite the _call function。 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lucasiscovici
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can realize your chain, rewrite the _call function。