Module: RubyLLM::Providers::Bedrock::Streaming::MessageProcessing

Defined in:
lib/ruby_llm/providers/bedrock/streaming/message_processing.rb

Overview

Module for processing streaming messages from AWS Bedrock.

Instance Method Summary collapse

Instance Method Details

#process_chunk(chunk) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/ruby_llm/providers/bedrock/streaming/message_processing.rb', line 9

def process_chunk(chunk, &)
  offset = 0
  offset = process_message(chunk, offset, &) while offset < chunk.bytesize
rescue StandardError => e
  RubyLLM.logger.debug "Error processing chunk: #{e.message}"
  RubyLLM.logger.debug "Chunk size: #{chunk.bytesize}"
end

#process_message(chunk, offset) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/ruby_llm/providers/bedrock/streaming/message_processing.rb', line 17

def process_message(chunk, offset, &)
  return chunk.bytesize unless can_read_prelude?(chunk, offset)

  message_info = extract_message_info(chunk, offset)
  return find_next_message(chunk, offset) unless message_info

  process_valid_message(chunk, offset, message_info, &)
end

#process_valid_message(chunk, offset, message_info) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/ruby_llm/providers/bedrock/streaming/message_processing.rb', line 26

def process_valid_message(chunk, offset, message_info, &)
  payload = extract_payload(chunk, message_info[:headers_end], message_info[:payload_end])
  return find_next_message(chunk, offset) unless valid_payload?(payload)

  process_payload(payload, &)
  offset + message_info[:total_length]
end