Allowing Multiple Outputs in Langchain's LLMChain #19987
CD-rajveer
announced in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Checked
Feature request
The SequentialChain class can be modified to handle situations where multiple outputs are desired from the chained LLM models. We can achieve this by changing the
_run_output_key
method.With the modified
SequentialChain
we can use
new_chain.run
and access the outputs as a dictionary.Motivation
Proposal (If applicable)
This proposal outlines the implementation of a new feature in Langchain's LLMChain class to handle scenarios where multiple outputs are desired from chained Large Language Models (LLMs).
Current Limitation:
The current LLMChain class is designed to work with a single output variable. This limitation restricts its use in situations where multiple outputs are necessary from the chained LLMs.
Proposed Solution:
We propose modifying the LLMChain class to accommodate multiple outputs. This can be achieved by:
Modifying _run_output_key method:
Check the number of output keys defined in the chain (self.output_keys).
If there's only one output key, use the existing behavior for running the chain and returning the single output.
If there are multiple outputs:
Run each chain within the sequence.
Create a dictionary to store the outputs.
Use the chain's name as the key and the chain's output as the value in the dictionary.
Return the dictionary containing all outputs.
Updating run method usage:
The run method of the sequential chain (SequentialChain) can be modified to accept this change.
When calling run on a chain with multiple outputs, the results will be returned as a dictionary.
Beta Was this translation helpful? Give feedback.
All reactions