sendMessageStream method

  1. @override
Stream<String> sendMessageStream(
  1. String prompt, {
  2. Iterable<Attachment> attachments = const [],
})
override

Generates a stream of text based on the given prompt and attachments. Interacts with a chat and builds on the history of the chat associated with the provider.

This method should be implemented to interact with the specific LLM service and generate text responses.

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> sendMessageStream(
  String prompt, {
  Iterable<Attachment> attachments = const [],
}) {
  final userMessage = ChatMessage.user(prompt, attachments);
  final llmMessage = ChatMessage.llm();
  _history.addAll([userMessage, llmMessage]);
  if (!_disposed) notifyListeners();

  return _appendResponseTo(llmMessage, _toAgentMessage(prompt, attachments));
}