stream method

  1. @override
Stream<ChatResult> stream(
  1. PromptValue input, {
  2. FakeChatModelOptions? options,
})
override

Streams the output of invoking the Runnable on the given input.

  • input - the input to invoke the Runnable on.
  • options - the options to use when invoking the Runnable.

Implementation

@override
Stream<ChatResult> stream(
  final PromptValue input, {
  final FakeChatModelOptions? options,
}) {
  final res = responses[_i++ % responses.length].split('');
  return Stream.fromIterable(res).map(
    (final char) => ChatResult(
      id: 'fake-chat-model',
      output: AIChatMessage(content: char),
      finishReason: FinishReason.stop,
      metadata: {
        'model': options?.model ?? defaultOptions.model,
        ...?options?.metadata ?? defaultOptions.metadata,
      },
      usage: const LanguageModelUsage(),
      streaming: true,
    ),
  );
}