Class: Async::Ollama::StreamingResponseParser

Inherits:
StreamingParser
  • Object
show all
Defined in:
lib/async/ollama/wrapper.rb

Overview

Parses streaming responses for the Ollama API, collecting the response string.

Instance Method Summary collapse

Methods inherited from StreamingParser

#join, #read

Constructor Details

#initializeStreamingResponseParser

Initializes the parser with an empty response string.



68
69
70
71
72
73
# File 'lib/async/ollama/wrapper.rb', line 68

def initialize(...)
  super
  
  @response = String.new
  @value[:response] = @response
end

Instance Method Details

#eachObject

Iterates over each response line, yielding the response string.



77
78
79
80
81
82
83
84
85
# File 'lib/async/ollama/wrapper.rb', line 77

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