Replies: 1 comment 1 reply
-
🤖 Hello, Based on the context provided, it seems like you're trying to route different inputs to different destination chains using the To handle this, 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 input_key_map = {"input": "team"}
adapted_team_chain = InputAdapterChain(team_chain, input_key_map) Finally, use the adapted chains in your destination_chains["team"] = adapted_team_chain
chain = MultiPromptChain(
router_chain=router_chain,
destination_chains=destination_chains,
default_chain=default_chain,
verbose=True,
) This way, the This solution was suggested in a similar issue in the LangChain repository: Issue: How to handle RouterChain when 1 or more destination chain(s) which is expecting a different input variable? 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.
-
This is my sample code:
My problem is that sometimes I need output from the router in a different format depending on the destination chain. Is there a way to handle this?
In my case for
question3
I get this error:Is there a more standard way to achieve my goal?
Beta Was this translation helpful? Give feedback.
All reactions