Multipromtchain with RetrievalQA as destination chain #9397
Replies: 1 comment 2 replies
-
🤖 Hello, The error you're encountering is due to the fact that the To resolve this issue, you need to ensure that the input you're providing to the input_data = {
'query': {
'context': 'Your context here',
'question': 'Your question here'
}
} Then, you can pass this result = multi_prompt_chain(input_data) This should resolve the Additionally, if you have a situation where one or more destination chains are expecting a different input variable, you can create a custom chain that adapts the input variables for the destination chain. This custom chain will take the input variable from the router chain and convert it to the expected input variable for the destination chain. Here's an example of how you can create such a custom chain: from langchain.chains.base import Chain
class InputAdapterChain(Chain):
def __init__(self, destination_chain, input_key_map):
self.destination_chain = destination_chain
self.input_key_map = input_key_map
def run(self, inputs):
adapted_inputs = {self.input_key_map[k]: v for k, v in inputs.items()}
return self.destination_chain.run(adapted_inputs) Now, you can use this InputAdapterChain to wrap the PalChain and adapt the input variable: pal_chain = PalChain() # Assuming you have initialized the PalChain
input_key_map = {"input": "question"}
adapted_pal_chain = InputAdapterChain(pal_chain, input_key_map) Finally, use the adapted_pal_chain in your MultiPromptChain setup: chain = MultiPromptChain(router_chain=router_chain,
destination_chains=[adapted_pal_chain],
default_chain=default_chain,
verbose=True
) This way, the InputAdapterChain will convert the input variable from the router chain to the expected input variable for the PalChain, avoiding the ValueError you encountered. I hope this helps! Let me know if you have any other questions. 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. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have multiple RetrievalQA chains with different format instructions and prompt template, I am using MultiPromptChain from langchain to route it to the suitable chain, however I am facing error with the inputs, I tried changing the variable as 'input' in my prompt template but it doesn't help.
Here is the error that I am facing :
ValueError: Missing some input keys: {'query'}
Here is the implementation of my MultiPromptChain
`class CustomMultiPromptChain (MultiRouteChain):
`
and here's how I am initializing and using it :
`destination_chains = {}
for p_info in prompt_infos:
name = p_info["name"]
# prompt = p_info["prompt"]
chain_kwargs = p_info["kwargs"]
chain = RetrievalQA.from_chain_type(llm=ChatOpenAI(model = "gpt-4"), chain_type="stuff", retriever=retriever,
chain_type_kwargs=chain_kwargs)
destination_chains[name] = chain
`
Any kind of help/suggestion is appreciated.
Beta Was this translation helpful? Give feedback.
All reactions