langchain_experimental.rl_chain.pick_best_chain.PickBest¶
class langchain_experimental.rl_chain.pick_best_chain.PickBest[source]¶
Bases: RLChain[PickBestEvent]
PickBest is a class designed to leverage the Vowpal Wabbit (VW) model for reinforcement learning with a context, with the goal of modifying the prompt before the LLM call.
Each invocation of the chain’s run() method should be equipped with a set of potential actions (ToSelectFrom) and will result in the selection of a specific action based on the BasedOn input. This chosen action then informs the LLM (Language Model) prompt for the subsequent response generation.
The standard operation flow of this Chain includes:
The Chain is invoked with inputs containing the BasedOn criteria and a list of potential actions (ToSelectFrom).
An action is selected based on the BasedOn input.
The LLM is called with the dynamic prompt, producing a response.
If a selection_scorer is provided, it is used to score the selection.
The internal Vowpal Wabbit model is updated with the BasedOn input, the chosen ToSelectFrom action, and the resulting score from the scorer.
The final response is returned.
Expected input dictionary format:
At least one variable encapsulated within BasedOn to serve as the selection criteria.
A single list variable within ToSelectFrom, representing potential actions for the VW model. This list can take the form of:
A list of strings, e.g., action = ToSelectFrom([“action1”, “action2”, “action3”])
A list of list of strings e.g. action = ToSelectFrom([[“action1”, “another identifier of action1”], [“action2”, “another identifier of action2”]])