Async::OllamaSourceAsyncOllamaStreamingMessageParser

class StreamingMessageParser

Parses streaming message responses for the Ollama API, collecting message content.

Definitions

def initialize(...)

Initializes the parser with an empty message content.

Implementation

def initialize(...)
	super
	
	@content = String.new
	@message = {content: @content, role: "assistant"}
	@value[:message] = @message
end

def each

Iterates over each message line, yielding the message content.

Signature

returns Enumerator

Yields each message content string.

Implementation

def each
	super do |line|
		message = line.delete(:message)
		content = message.delete(:content)
		@content << content
		@message.merge!(message)
		@value.merge!(line)
		
		yield content
	end
end