Class: LLM::OpenAI::StreamParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ LLM::OpenAI::Chunk



14
15
16
17
18
# File 'lib/llm/providers/openai/stream_parser.rb', line 14

def initialize(stream)
  @body = {}
  @stream = stream
  @emits = {tools: []}
end

Instance Attribute Details

#bodyHash (readonly)

Returns the fully constructed response body

Returns:

  • (Hash)


10
11
12
# File 'lib/llm/providers/openai/stream_parser.rb', line 10

def body
  @body
end

Instance Method Details

#freevoid

This method returns an undefined value.

Frees internal parser state used during streaming.



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

def free
  @emits.clear
end

#parse!(chunk) ⇒ LLM::OpenAI::Chunk

Parameters:

  • chunk (Hash)

Returns:

  • (LLM::OpenAI::Chunk)


23
24
25
# File 'lib/llm/providers/openai/stream_parser.rb', line 23

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