Class: Legion::Extensions::Llm::Responses::StreamChunk
- Inherits:
-
Object
- Object
- Legion::Extensions::Llm::Responses::StreamChunk
- Defined in:
- lib/legion/extensions/llm/responses/stream_chunk.rb
Overview
Normalized streaming provider response chunk.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#internal_metadata ⇒ Object
readonly
Returns the value of attribute internal_metadata.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#thinking ⇒ Object
readonly
Returns the value of attribute thinking.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
-
#tool_calls ⇒ Object
readonly
Returns the value of attribute tool_calls.
Instance Method Summary collapse
-
#initialize(content: nil, thinking: nil, metadata: {}, model: nil, tool_calls: nil, tokens: nil, raw: nil) ⇒ StreamChunk
constructor
rubocop:disable Metrics/ParameterLists.
- #to_h ⇒ Object
- #to_internal_h ⇒ Object
Constructor Details
#initialize(content: nil, thinking: nil, metadata: {}, model: nil, tool_calls: nil, tokens: nil, raw: nil) ⇒ StreamChunk
rubocop:disable Metrics/ParameterLists
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 11 def initialize(content: nil, thinking: nil, metadata: {}, model: nil, tool_calls: nil, tokens: nil, raw: nil) # rubocop:disable Metrics/ParameterLists extraction = ThinkingExtractor.extract(content, metadata: ) @content = extraction.content @thinking = thinking || extraction.thinking @metadata = extraction. @internal_metadata = .to_h @model = model @tool_calls = tool_calls @tokens = tokens @raw = raw freeze end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
9 10 11 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 9 def content @content end |
#internal_metadata ⇒ Object (readonly)
Returns the value of attribute internal_metadata.
9 10 11 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 9 def @internal_metadata end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 9 def @metadata end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
9 10 11 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 9 def model @model end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
9 10 11 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 9 def raw @raw end |
#thinking ⇒ Object (readonly)
Returns the value of attribute thinking.
9 10 11 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 9 def thinking @thinking end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
9 10 11 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 9 def tokens @tokens end |
#tool_calls ⇒ Object (readonly)
Returns the value of attribute tool_calls.
9 10 11 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 9 def tool_calls @tool_calls end |
Instance Method Details
#to_h ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 26 def to_h { content: content, metadata: , model: model, tool_calls: tool_calls, tokens: tokens }.compact end |
#to_internal_h ⇒ Object
36 37 38 |
# File 'lib/legion/extensions/llm/responses/stream_chunk.rb', line 36 def to_internal_h to_h.merge(thinking: thinking, metadata: , raw: raw).compact end |