Class: Llmshim::StreamEvent
- Inherits:
-
Object
- Object
- Llmshim::StreamEvent
- Defined in:
- lib/llmshim/types.rb
Overview
A typed SSE event from POST /v1/chat/stream.
type is one of: "content", "reasoning", "tool_call", "usage", "done",
"error". All variant fields are exposed through raw and the helper
accessors below; unknown fields remain reachable via raw.
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Original parsed data Hash for this event.
-
#type ⇒ Object
readonly
Event type string (String).
Instance Method Summary collapse
- #[](key) ⇒ Object
- #arguments ⇒ Object
- #content? ⇒ Boolean
- #done? ⇒ Boolean
- #error? ⇒ Boolean
-
#id ⇒ Object
tool_call events.
-
#initialize(type, raw) ⇒ StreamEvent
constructor
A new instance of StreamEvent.
-
#message ⇒ Object
error events.
- #name ⇒ Object
- #reasoning? ⇒ Boolean
-
#text ⇒ Object
content / reasoning events.
- #tool_call? ⇒ Boolean
-
#usage ⇒ Object
usage events.
- #usage? ⇒ Boolean
Constructor Details
#initialize(type, raw) ⇒ StreamEvent
Returns a new instance of StreamEvent.
102 103 104 105 |
# File 'lib/llmshim/types.rb', line 102 def initialize(type, raw) @type = type @raw = raw || {} end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Original parsed data Hash for this event.
100 101 102 |
# File 'lib/llmshim/types.rb', line 100 def raw @raw end |
#type ⇒ Object (readonly)
Event type string (String).
98 99 100 |
# File 'lib/llmshim/types.rb', line 98 def type @type end |
Instance Method Details
#[](key) ⇒ Object
161 162 163 |
# File 'lib/llmshim/types.rb', line 161 def [](key) raw[key.to_s] end |
#arguments ⇒ Object
145 146 147 |
# File 'lib/llmshim/types.rb', line 145 def arguments raw["arguments"] end |
#content? ⇒ Boolean
107 108 109 |
# File 'lib/llmshim/types.rb', line 107 def content? type == "content" end |
#done? ⇒ Boolean
123 124 125 |
# File 'lib/llmshim/types.rb', line 123 def done? type == "done" end |
#error? ⇒ Boolean
127 128 129 |
# File 'lib/llmshim/types.rb', line 127 def error? type == "error" end |
#id ⇒ Object
tool_call events
137 138 139 |
# File 'lib/llmshim/types.rb', line 137 def id raw["id"] end |
#message ⇒ Object
error events
157 158 159 |
# File 'lib/llmshim/types.rb', line 157 def raw["message"] end |
#name ⇒ Object
141 142 143 |
# File 'lib/llmshim/types.rb', line 141 def name raw["name"] end |
#reasoning? ⇒ Boolean
111 112 113 |
# File 'lib/llmshim/types.rb', line 111 def reasoning? type == "reasoning" end |
#text ⇒ Object
content / reasoning events
132 133 134 |
# File 'lib/llmshim/types.rb', line 132 def text raw["text"] end |
#tool_call? ⇒ Boolean
115 116 117 |
# File 'lib/llmshim/types.rb', line 115 def tool_call? type == "tool_call" end |
#usage ⇒ Object
usage events
150 151 152 153 154 |
# File 'lib/llmshim/types.rb', line 150 def usage return nil unless usage? Usage.from_hash(raw) end |
#usage? ⇒ Boolean
119 120 121 |
# File 'lib/llmshim/types.rb', line 119 def usage? type == "usage" end |