Class: LLM::EventStream::Event
- Inherits:
-
Object
- Object
- LLM::EventStream::Event
- Defined in:
- lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb
Constant Summary collapse
- FIELD_REGEXP =
/[^:]+/- VALUE_REGEXP =
/(?<=: ).+/
Instance Attribute Summary collapse
-
#chunk ⇒ String
readonly
Returns the full chunk.
-
#field ⇒ Symbol
readonly
Returns the field name.
-
#value ⇒ String
readonly
Returns the field value.
Instance Method Summary collapse
-
#data? ⇒ Boolean
Returns true when the event represents a “data” chunk.
-
#end? ⇒ Boolean
Returns true when a chunk represents the end of the stream.
-
#event? ⇒ Boolean
Returns true when the event represents an “event” chunk.
-
#id? ⇒ Boolean
Returns true when the event represents an “id” chunk.
- #initialize(chunk) ⇒ LLM::EventStream::Event constructor
-
#retry? ⇒ Boolean
Returns true when the event represents a “retry” chunk.
Constructor Details
#initialize(chunk) ⇒ LLM::EventStream::Event
28 29 30 31 32 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb', line 28 def initialize(chunk) @field = chunk[FIELD_REGEXP] @value = chunk[VALUE_REGEXP] @chunk = chunk end |
Instance Attribute Details
#chunk ⇒ String (readonly)
Returns the full chunk
23 24 25 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb', line 23 def chunk @chunk end |
#field ⇒ Symbol (readonly)
Returns the field name
13 14 15 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb', line 13 def field @field end |
#value ⇒ String (readonly)
Returns the field value
18 19 20 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb', line 18 def value @value end |
Instance Method Details
#data? ⇒ Boolean
Returns true when the event represents a “data” chunk
44 45 46 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb', line 44 def data? @field == "data" end |
#end? ⇒ Boolean
Returns true when a chunk represents the end of the stream
65 66 67 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb', line 65 def end? @value == "[DONE]" end |
#event? ⇒ Boolean
Returns true when the event represents an “event” chunk
51 52 53 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb', line 51 def event? @field == "event" end |
#id? ⇒ Boolean
Returns true when the event represents an “id” chunk
37 38 39 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb', line 37 def id? @field == "id" end |
#retry? ⇒ Boolean
Returns true when the event represents a “retry” chunk
58 59 60 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb', line 58 def retry? @field == "retry" end |