#Trouble with Inputs in MultiPromptChain Routing - Missing Input Keys Issue

6 messages · Page 1 of 1 (latest)

arctic bridge
#

Hello fellow developers,

I'm currently working on a project where I'm using the MultiPromptChain from langchain to route inputs to different chains based on specific conditions. However, I'm facing an issue with inputs that's been quite puzzling. I'm hoping someone can provide some guidance to help me resolve this.

Problem Description:
I have a scenario where I'm using multiple RetrievalQA chains, each with different formatting instructions and prompt templates. To handle this, I'm utilizing the MultiPromptChain from langchain to determine which chain to route the inputs to. However, when I attempt to execute the chains, I'm encountering the following error:

Error:
ValueError: Missing some input keys: {'query'}

My Implementation:
Here's how I've set up my CustomMultiPromptChain class and how I'm initializing and using it:
`class CustomMultiPromptChain (MultiRouteChain):
destination_chains: Mapping[str, Chain]
"""Map of name to candidate chains that inputs can be routed to. Not restricted to LLM"""
destination_chains = {}
for p_info in prompt_infos:
name = p_info["name"]
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

chain = CustomMultiPromptChain(
router_chain=router_chain,
destination_chains=destination_chains,
default_chain=default_chain,
verbose=True,
)
chain({"input": input})`

Steps Taken:
I've verified the expected input keys for each chain in destination_chains.
I've tried changing the input variable from 'input' to 'query' in my call to the chain instance.

Any help, suggestions, or insights would be highly appreciated. Thank you for taking the time to read through this and assist me in resolving this issue!

azure tapir
#

I don't understand your code. Are the lines after destination_chains = {} part of the CustomMultiPromptChain class?

#

Hmm, I guess not.

#

If you add destination_chains as a new variable in your subclass it'll alias the one in the super class. Why do you need to add destination_chains if it is already defined in MultiRouteChain?

arctic bridge
#

sorry for the confusion, the part after the implementation of CustomMultiPromptChain is the part of main function

#

`prompt_infos = [
{
"name": "location",
"description": "Good for extracting locations related information",
"kwargs" : {"prompt": locationPrompt}
},
{
"name": "bid",
"description": "Good for extracting bid related information",
"kwargs" : {"prompt": bidPrompt}
},
{
"name": "task",
"description": "Good for extracting task related information",
"kwargs" : {"prompt": taskPrompt}
},
{
"name": "miscellaneous",
"description": "Good for extracting amy other information",
"kwargs" : {"prompt": miscPrompt}
}
]

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

destinations = [f"{p['name']}: {p['description']}" for p in prompt_infos]
destinations_str = "\n".join(destinations)

router_template = MULTI_PROMPT_ROUTER_TEMPLATE.format(destinations=destinations_str)

router_prompt = PromptTemplate(
    template=router_template,
    input_variables=["input"],
    output_parser=RouterOutputParser(),
)

llm = OpenAI()

router_chain = LLMRouterChain.from_llm(llm, router_prompt)
chain = CustomMultiPromptChain(
    router_chain=router_chain,
    destination_chains=destination_chains,
    default_chain=default_chain,
    verbose=True,
)

print(chain({"input": "Extract location related information")`