Class: LLM::OpenAI::Responses::StreamParser

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/providers/openai/responses/stream_parser.rb

Constant Summary collapse

EMPTY_HASH =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ LLM::OpenAI::Responses::StreamParser

Parameters:



17
18
19
20
21
22
23
24
25
# File 'lib/llm/providers/openai/responses/stream_parser.rb', line 17

def initialize(stream)
  @body = {"output" => []}
  @stream = stream
  @emits = {tools: {}}
  @cached_output_index = nil
  @cached_output_item = nil
  @cached_content_index = nil
  @cached_content_part = nil
end

Instance Attribute Details

#bodyHash (readonly)

Returns the fully constructed response body

Returns:

  • (Hash)


12
13
14
# File 'lib/llm/providers/openai/responses/stream_parser.rb', line 12

def body
  @body
end

Instance Method Details

#freevoid

This method returns an undefined value.

Frees internal parser state used during streaming.



37
38
39
40
# File 'lib/llm/providers/openai/responses/stream_parser.rb', line 37

def free
  @emits.clear
  clear_cache!
end

#parse!(chunk) ⇒ LLM::OpenAI::Responses::StreamParser

Parameters:

  • chunk (Hash)

Returns:



30
31
32
# File 'lib/llm/providers/openai/responses/stream_parser.rb', line 30

def parse!(chunk)
  tap { handle_event(chunk) }
end