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

const RunnableBinding<RunInput extends Object?, CallOptions extends RunnableOptions, RunOutput extends Object?>({
  1. required Runnable<RunInput, CallOptions, RunOutput> bound,
  2. required CallOptions options,
})

A RunnableBinding allows you to run a Runnable object with CallOptions.

You can create a RunnableBinding using the Runnable.bind method.

When you call invoke on a RunnableBinding, it will invoke the Runnable with the CallOptions passed to bind.

Example: Attaching Stop Sequences

final openaiApiKey = Platform.environment['OPENAI_API_KEY'];
final model = ChatOpenAI(apiKey: openaiApiKey);

final promptTemplate = ChatPromptTemplate.fromTemplate(
  'Tell me a joke about {foo}',
);

final chain = promptTemplate | model.bind(ChatOpenAIOptions(stop: ['\n']));

final res = await chain.invoke({'foo': 'bears'});
print(res);
// ChatResult{
//   generations: [
//     ChatGeneration{
//       output: AIChatMessage{
//         content: Why don't bears wear shoes?,
//       },
//     },
//   ],
//   usage: ...,
//   modelOutput: ...,
// }

Implementation

const RunnableBinding({
  required this.bound,
  required this.options,
}) : super(defaultOptions: options);