Module: RubyLLM::BedrockInvoke::EventStream
- Included in:
- Protocol, Providers::BedrockInvoke
- Defined in:
- lib/ruby_llm/bedrock_invoke/event_stream.rb
Overview
Decodes AWS event-stream framing (application/vnd.amazon.eventstream) from InvokeModelWithResponseStream into plain Anthropic streaming events.
Each chunk event carries a PayloadPart whose base64 bytes field
decodes to one standard Anthropic SSE event (message_start,
content_block_delta, ...). Failures surface three ways, all handled
before the payload is trusted: frames with :message-type 'exception'
(typed via :exception-type, payload may be empty), frames with
:message-type 'error' (:error-code/:error-message headers, empty
payload), and exception-suffixed keys inside chunk payloads.
Constant Summary collapse
- EXCEPTION_STATUS =
{ 'throttlingException' => 429, 'validationException' => 400, 'modelTimeoutException' => 408, 'modelStreamErrorException' => 424, 'serviceUnavailableException' => 503, 'internalServerException' => 500 }.freeze
Instance Method Summary collapse
-
#each_event_stream_event(decoder, raw_chunk) ⇒ Object
Yields one decoded Anthropic event Hash per event in the raw chunk.
- #event_stream_decoder ⇒ Object
Instance Method Details
#each_event_stream_event(decoder, raw_chunk) ⇒ Object
Yields one decoded Anthropic event Hash per event in the raw chunk. Raises through ErrorMiddleware when the stream carries an exception event.
35 36 37 38 39 40 41 42 |
# File 'lib/ruby_llm/bedrock_invoke/event_stream.rb', line 35 def each_event_stream_event(decoder, raw_chunk, &) , eof = decoder.decode_chunk(raw_chunk) (, &) if until eof , eof = decoder.decode_chunk (, &) if end end |
#event_stream_decoder ⇒ Object
28 29 30 31 |
# File 'lib/ruby_llm/bedrock_invoke/event_stream.rb', line 28 def event_stream_decoder require 'aws-eventstream' ::Aws::EventStream::Decoder.new end |