Runnable<RunInput extends Object?, CallOptions extends RunnableOptions, RunOutput extends Object?> constructor

const Runnable<RunInput extends Object?, CallOptions extends RunnableOptions, RunOutput extends Object?>({
  1. required CallOptions defaultOptions,
})

A Runnable is a generic unit of work that can be invoked, batched, streamed, and/or transformed. It is the basic building block of the LangChain Expression Language (LCEL).

It is implemented by most of the LangChain components (prompt templates, models, retrievers, output parsers, etc.) which makes it easy to define custom chains as well as making it possible to invoke them in a standard way.

The standard interface exposed includes:

  • stream stream back chunks of the response.
  • invoke call the chain on an input.
  • batch call the chain on a list of inputs.

There are also several useful primitives for working with runnables:

  • pipe allows you to chain runnables together (alternatively, you can use the | operator or the fromList static method.
  • fromMap allows you to run multiple runnables concurrently on the same input returning a map of the results.
  • passthrough takes the input it receives and passes it through as output.
  • mapInput allows you to map the input to a different value.
  • mapInputStream allows you to map the input stream to a different stream of values.
  • getItemFromMap allows you to get a value from the input.
  • getMapFromInput allows you to output a map with the given key and the input as value.
  • fromFunction allows you to run a Dart function as part of a chain.
  • fromRouter takes the input it receives and routes it to the runnable returned by the router function.
  • bind allows you to bind the runnable to a set of options.

Implementation

const Runnable({
  required this.defaultOptions,
});