Class: GroqRuby::Streaming::EventParser

Inherits:
Object
  • Object
show all
Defined in:
lib/groq_ruby/streaming/event_parser.rb

Overview

Thin adapter over the upstream ‘event_stream_parser` gem. Feeds raw response chunks in and yields parsed `(event, data, id, retry)` tuples. Single-purpose: it owns the SSE parser state and nothing else.

Instance Method Summary collapse

Constructor Details

#initializeEventParser

Returns a new instance of EventParser.



9
10
11
# File 'lib/groq_ruby/streaming/event_parser.rb', line 9

def initialize
  @parser = ::EventStreamParser::Parser.new
end

Instance Method Details

#feed(chunk) {|event, data, id, reconnect_time| ... } ⇒ Object

Feed a raw chunk from the HTTP response. Yields each parsed event.

Yield Parameters:

  • event (String, nil)
  • data (String)
  • id (String, nil)
  • reconnect_time (Integer, nil)


18
19
20
# File 'lib/groq_ruby/streaming/event_parser.rb', line 18

def feed(chunk, &block)
  @parser.feed(chunk, &block)
end