BaseChain<MemoryType extends BaseMemory> class abstract

Base class for creating structured sequences of calls to components.

Chains should be used to encode a sequence of calls to components like models, document retrievers, other chains, etc., and provide a simple interface to this sequence.

The BaseChain interface makes it easy to create apps that are:

  • Stateful: add Memory to any Chain to give it state.
  • Observable: pass Callbacks to a Chain to execute additional functionality, like logging, outside the main sequence of component calls.
  • Composable: the Chain API is flexible enough that it is easy to combine Chains with other components, including other Chains.

The main methods exposed by chains are:

  • call Chains are callable. The call method is the primary way to execute a Chain. This takes inputs as a dictionary and returns a dictionary output.
  • run A convenience method that takes inputs and returns the output as a string. This method can only be used if the Chain has a single string output.
Inheritance
Implementers

Constructors

BaseChain({MemoryType? memory, ChainOptions? defaultOptions})
Base class for creating structured sequences of calls to components.
const

Properties

chainType String
Return the string type key uniquely identifying this class of chain.
no setter
defaultOptions ChainOptions
The default options to use when invoking the Runnable.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
inputKeys Set<String>
Input keys for this chain.
no setter
memory → MemoryType?
Memory to use for this chain.
final
outputKeys Set<String>
Output keys for this chain.
no setter
runOutputKey String
Output key from where the run method needs to take the return value.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

apply(List<ChainValues> inputs) Future<List<ChainValues>>
Call the chain on all inputs in the list.
batch(List<ChainValues> inputs, {List<ChainOptions>? options}) Future<List<ChainValues>>
Batches the invocation of the Runnable on the given inputs.
inherited
bind(ChainOptions options) RunnableBinding<ChainValues, ChainOptions, ChainValues>
Binds the Runnable to the given options.
inherited
call(dynamic input, {bool returnOnlyOutputs = false}) Future<ChainValues>
Runs the core logic of this chain with the given values. If memory is not null, it will be used to load and save values.
callInternal(ChainValues inputs) Future<ChainValues>
Call method to be implemented by subclasses (called by call). This is where the core logic of the chain should be implemented.
close() → void
Cleans up any resources associated with it the Runnable.
inherited
getCompatibleOptions(RunnableOptions? options) ChainOptions?
Returns the given options if they are compatible with the Runnable, otherwise returns null.
inherited
invoke(ChainValues input, {ChainOptions? options}) Future<ChainValues>
Runs the core logic of this chain with the given input.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pipe<NewRunOutput extends Object?, NewCallOptions extends RunnableOptions>(Runnable<ChainValues, NewCallOptions, NewRunOutput> next) RunnableSequence<ChainValues, NewRunOutput>
Pipes the output of this Runnable into another Runnable using a RunnableSequence.
inherited
run(dynamic input) Future<String>
Convenience method for executing chain when there's a single string output.
stream(ChainValues input, {ChainOptions? options}) Stream<ChainValues>
Streams the output of invoking the Runnable on the given input.
inherited
streamFromInputStream(Stream<ChainValues> inputStream, {ChainOptions? options}) Stream<ChainValues>
Streams the output of invoking the Runnable on the given inputStream.
inherited
toString() String
A string representation of this object.
inherited
withFallbacks(List<Runnable<ChainValues, RunnableOptions, ChainValues>> fallbacks) RunnableWithFallback<ChainValues, ChainValues>
Adds fallback runnables to be invoked if the primary runnable fails.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

defaultInputKey → const String
Default input key for the input of the chain.
defaultOutputKey → const String
Default output key for the output of the chain.