langflow
langflow copied to clipboard
RetrievalQAWithSourcesChain error with run method
Describe the bug
I am getting the following error:
{'detail': "error: run
not supported when there is not exactly one output key. got ['answer', 'sources', 'source_documents']."}
part of code from class BaseQAWithSourcesChain that is possibly causing the error:
def _call( self, inputs: Dict[str, Any], run_manager: Optional[CallbackManagerForChainRun] = None, ) -> Dict[str, str]: _run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager() accepts_run_manager = ( "run_manager" in inspect.signature(self._get_docs).parameters ) if accepts_run_manager: docs = self._get_docs(inputs, run_manager=_run_manager) else: docs = self._get_docs(inputs) # type: ignore[call-arg]
answer = self.combine_documents_chain.run(
input_documents=docs, callbacks=_run_manager.get_child(), **inputs
)
answer, sources = self._split_sources(answer)
result: Dict[str, Any] = {
self.answer_key: answer,
self.sources_answer_key: sources,
}
if self.return_source_documents:
result["source_documents"] = docs
return result
additional context:- the error seems to be with calling the 'run' method. Is there a way to modify it to resolve the error
π€
Hello @sampratha28! π I'm Dosu, a friendly bot here to help you out with bugs and questions related to the langflow repository. While we wait for a human maintainer to join us, feel free to share any additional information or ask any questions you might have. Let's work together to get this issue sorted out! π
From the error message you provided, it seems like the issue is arising because the run
method is expecting exactly one output key, but it's receiving multiple keys: ['answer', 'sources', 'source_documents']
.
The run
method is part of the CombineDocsChain
class and is used to execute the chain. It's a wrapper around the run
method of the parent class, CustomChain
. This method is used to execute the chain with the provided arguments and keyword arguments. You can find more details about this in the src/backend/langflow/interface/chains/custom.py file.
The _call
method in the BaseQAWithSourcesChain
class is where the run
method is being called. From the code snippet you provided, it seems like the run
method is being called with input_documents=docs, callbacks=_run_manager.get_child(), **inputs
as arguments. The run
method then returns an answer
which is split into answer
and sources
by the _split_sources
method. If return_source_documents
is True
, source_documents
is also added to the result.
To resolve the error, you might need to modify the run
method to accept multiple output keys or adjust the _call
method to ensure that only one output key is being returned. However, without more context or access to the full codebase, it's hard to provide a definitive solution.
If you could provide more details about the run
method and its requirements, or the context in which the run
method is being called, it would be easier to pinpoint the exact issue and suggest a solution.
Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a π if this is helpful and π if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
@dosu-bot i am able to get response in the UI but not while using API call
π€
From the error message, it seems like the run
method is expecting exactly one output key, but it's receiving three: 'answer', 'sources', and 'source_documents'. This discrepancy is likely what's causing the error.
The run
method is called here:
answer = self.combine_documents_chain.run(
input_documents=docs, callbacks=_run_manager.get_child(), **inputs
)
And the outputs are split here:
answer, sources = self._split_sources(answer)
Then, they're added to the result dictionary:
result: Dict[str, Any] = {
self.answer_key: answer,
self.sources_answer_key: sources,
}
if self.return_source_documents:
result["source_documents"] = docs
It's not immediately clear why this would work in the UI but not in an API call. To help me understand the issue better, could you provide more information about how you're making the API call? Specifically, what inputs are you providing, and what does the full error message look like? Also, are there any differences in the environment or setup between the UI and the API call?
Additionally, could you share the code for the run
method and the _split_sources
method? This would help me understand what these methods are expecting and how they're handling the inputs and outputs.
Finally, if there are any logs or stack traces associated with the error, those could be very helpful in diagnosing the issue.
Looking forward to your response. Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a π if this is helpful and π if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.