generateStream method
Stream<String>
generateStream(
- String prompt, {
- Iterable<
Attachment> attachments = const [],
override
Generates a stream of text based on the given prompt and attachments. This method does not interact with a chat or build on any chat history.
prompt is the input text to generate a response for.
attachments is an optional iterable of Attachment objects to include
with the prompt. These can be images, files, or links that provide
additional context for the LLM.
Returns a Stream of String containing the generated text chunks. This allows for streaming responses as they are generated by the LLM.
Implementation
@override
Stream<String> generateStream(
String prompt, {
Iterable<Attachment> attachments = const [],
}) async* {
if (prompt == 'FAILFAST') throw const LlmFailureException('Failing fast!');
await Future.delayed(const Duration(milliseconds: 1000));
yield '# Echo\n';
switch (prompt) {
case 'CANCEL':
throw const LlmCancelException();
case 'FAIL':
throw const LlmFailureException('User requested failure');
}
await Future.delayed(const Duration(milliseconds: 1000));
yield prompt;
yield '\n\n# Attachments\n${attachments.map((a) => a.toString())}';
}