Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SequentialChain does not feed output/input variables #1866

Open
ronaldo-moco opened this issue May 8, 2024 · 4 comments
Open

SequentialChain does not feed output/input variables #1866

ronaldo-moco opened this issue May 8, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@ronaldo-moco
Copy link

Hello Everyone,

I am trying to connect two LLM chains sequentially.
The first one outputs chain1_result.
The second one expects chain1_result as a input.
I've included one SequentialChain component, linking the two chains.
The flow builds succesfully, but when i try to run the chat, it show the message 'Error: Missing some input keys: {'chain1_result'}'
Is there something that i'm missing?

Copy link

dosubot bot commented May 8, 2024

To address the issue of the SequentialChain not correctly passing the chain1_result from the first LLM chain to the second, ensure that the output of the first chain is explicitly mapped as the input to the second chain within the SequentialChain configuration. This involves specifying how the output from the first chain should be used as input for the second chain, which can be achieved through the set_input_mapping and set_output_mapping methods of the SequentialChain.

Here's a general approach to configure the mappings:

from langchain.sequential import SequentialChain

# Assuming chain1's output needs to be chain2's input
sequential_chain = SequentialChain(components=[chain1, chain2])
sequential_chain.set_input_mapping({
    "chain2_input_key": "chain1_output_key"  # Map chain1's output to chain2's input
})
sequential_chain.set_output_mapping({
    "final_output": "chain2_output_key"  # Map chain2's output to a final output key
})

# Execute the sequential chain with initial input
result = sequential_chain.invoke({"chain1_input_key": initial_input_value})

Replace "chain1_output_key", "chain2_input_key", and "chain2_output_key" with the actual keys used in your chains to ensure the output of the first chain is correctly identified and passed as input to the second chain.

This setup should resolve the error message indicating missing input keys by ensuring that the output from the first chain is correctly passed as input to the second chain. If you continue to face issues, it might be worth reviewing the handling of input and output keys within your chains to ensure they align with the expected configurations.

Details

Sources


About 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.

To continue the conversation, mention @dosu.

@dosubot dosubot bot added the bug Something isn't working label May 8, 2024
@ronaldo-moco
Copy link
Author

@dosu It doesnt work as intended, now i get this error message:
Error building node SequencialChain: 'SequentialChain' object has no attribute 'set_input_mapping'

Copy link

dosubot bot commented May 9, 2024

It appears there was a misunderstanding regarding the functionality provided by the SequentialChain class in the LangChain library, as it does not offer set_input_mapping and set_output_mapping methods, leading to the error you encountered. To connect two chains sequentially where the output of the first chain is used as the input for the second, you'll need to manually manage the flow of data between the chains.

Here's a step-by-step guide to manually handle the output from the first chain and use it as input for the second:

  1. Execute the First Chain: Run the first chain independently and capture its output.
  2. Pass Output to Second Chain: Take the output from the first chain and use it as the input for the second chain.

This approach requires you to explicitly manage the output and input keys, ensuring that the output from the first chain is correctly formatted and passed as the expected input for the second chain.

Without specific details on how your chain1 and chain2 are implemented, this general guidance should help you set up a manual sequence between the two chains. If you encounter further issues or if this solution doesn't meet your needs, providing more details about the chain1 and chain2 implementations could help in offering more specific advice.

Details

About 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.

To continue the conversation, mention @dosu.

@ronaldo-moco
Copy link
Author

@ogabrielluiz could you take a look at this? I'm not sure how to proceed since its just standard components...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant