Class: OmniAI::Anthropic::Chat::Response::Stream::Builder
- Inherits:
-
Object
- Object
- OmniAI::Anthropic::Chat::Response::Stream::Builder
- Defined in:
- lib/omniai/anthropic/chat/response/stream.rb
Overview
Process the stream into chunks by event.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Instance Method Summary collapse
- #chunk ⇒ OmniAI::Chat::Chunk
-
#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.
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
21 22 23 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 21 def content @content end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 21 def id @id end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
21 22 23 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 21 def index @index end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
21 22 23 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 21 def model @model end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
21 22 23 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 21 def role @role end |
Instance Method Details
#chunk ⇒ OmniAI::Chat::Chunk
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 24 def chunk OmniAI::Chat::Response::Chunk.new(data: { 'id' => @id, 'model' => @model, 'choices' => [{ 'index' => @index, 'delta' => { 'role' => @role, 'content' => @content, }, }], }) end |
#content_block_delta(data) ⇒ Object
Handler for Type::CONTENT_BLOCK_DELTA
73 74 75 76 77 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 73 def content_block_delta(data) return unless data['delta']['type'].eql?('text_delta') @content = data['delta']['text'] end |
#content_block_start(data) ⇒ Object
Handler for Type::CONTENT_BLOCK_START
59 60 61 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 59 def content_block_start(data) @index = data['index'] end |
#content_block_stop(_data) ⇒ Object
Handler for Type::CONTENT_BLOCK_STOP
66 67 68 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 66 def content_block_stop(_data) @index = nil end |
#message_start(data) ⇒ Object
Handler for Type::MESSAGE_START
41 42 43 44 45 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 41 def (data) @id = data['id'] @model = data['model'] @role = data['role'] end |
#message_stop(_data) ⇒ Object
Handler for Type::MESSAGE_STOP
50 51 52 53 54 |
# File 'lib/omniai/anthropic/chat/response/stream.rb', line 50 def (_data) @id = nil @model = nil @role = nil end |