Class: OmniAI::Anthropic::Chat::Stream::Builder
- Inherits:
-
Object
- Object
- OmniAI::Anthropic::Chat::Stream::Builder
- Defined in:
- lib/omniai/anthropic/chat/stream.rb
Overview
Process the stream into chunks by event.
Instance Method Summary collapse
-
#content_block_delta(data) ⇒ Object
Handler for Type::CONTENT_BLOCK_DELTA.
-
#content_block_start(_data) ⇒ Object
Handler for Type::CONTENT_BLOCK_START.
-
#content_block_stop(_data) ⇒ Object
Handler for Type::CONTENT_BLOCK_STOP.
-
#message_start(data) ⇒ Object
Handler for Type::MESSAGE_START.
-
#message_stop(_data) ⇒ Object
Handler for Type::MESSAGE_STOP.
- #payload(context:) ⇒ OmniAI::Chat::Payload?
Instance Method Details
#content_block_delta(data) ⇒ Object
Handler for Type::CONTENT_BLOCK_DELTA
60 61 62 |
# File 'lib/omniai/anthropic/chat/stream.rb', line 60 def content_block_delta(data) @content = [{ 'type' => 'text', 'text' => data['delta']['text'] }] end |
#content_block_start(_data) ⇒ Object
Handler for Type::CONTENT_BLOCK_START
46 47 48 |
# File 'lib/omniai/anthropic/chat/stream.rb', line 46 def content_block_start(_data) @content = nil end |
#content_block_stop(_data) ⇒ Object
Handler for Type::CONTENT_BLOCK_STOP
53 54 55 |
# File 'lib/omniai/anthropic/chat/stream.rb', line 53 def content_block_stop(_data) @content = nil end |
#message_start(data) ⇒ Object
Handler for Type::MESSAGE_START
32 33 34 |
# File 'lib/omniai/anthropic/chat/stream.rb', line 32 def (data) @message = data['message'] end |
#message_stop(_data) ⇒ Object
Handler for Type::MESSAGE_STOP
39 40 41 |
# File 'lib/omniai/anthropic/chat/stream.rb', line 39 def (_data) @message = nil end |
#payload(context:) ⇒ OmniAI::Chat::Payload?
21 22 23 24 25 26 27 |
# File 'lib/omniai/anthropic/chat/stream.rb', line 21 def payload(context:) return unless @content OmniAI::Chat::Payload.deserialize(@message.merge({ 'content' => @content, }), context:) end |