Class: Ollama::StreamEvent
- Inherits:
-
Struct
- Object
- Struct
- Ollama::StreamEvent
- Defined in:
- lib/ollama/stream_event.rb
Overview
A typed event emitted during a streaming chat response. Provides clean separation between reasoning, answer tokens, tool calls, and terminal events — enabling UI rendering, JSONL tracing, and agent orchestration without mixing reasoning into the final answer.
Event types:
:thought_start — reasoning block begins
:thought_delta — incremental reasoning token
:thought_end — reasoning block complete
:answer_delta — incremental final-answer token
:tool_call_start — tool call ready (data = ToolCall hash)
:tool_call_delta — incremental tool call token (partial streaming)
:complete — stream finished (data = Ollama::Response)
:error — stream error (data = exception)
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#model ⇒ Object
Returns the value of attribute model.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #answer? ⇒ Boolean
- #terminal? ⇒ Boolean
- #thought? ⇒ Boolean
-
#to_jsonl ⇒ Object
Serialize to a JSONL line for trace logging.
- #tool_call? ⇒ Boolean
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data
18 19 20 |
# File 'lib/ollama/stream_event.rb', line 18 def data @data end |
#model ⇒ Object
Returns the value of attribute model
18 19 20 |
# File 'lib/ollama/stream_event.rb', line 18 def model @model end |
#type ⇒ Object
Returns the value of attribute type
18 19 20 |
# File 'lib/ollama/stream_event.rb', line 18 def type @type end |
Instance Method Details
#answer? ⇒ Boolean
20 |
# File 'lib/ollama/stream_event.rb', line 20 def answer? = type == :answer_delta |
#terminal? ⇒ Boolean
22 |
# File 'lib/ollama/stream_event.rb', line 22 def terminal? = %i[complete error].include?(type) |
#thought? ⇒ Boolean
19 |
# File 'lib/ollama/stream_event.rb', line 19 def thought? = %i[thought_start thought_delta thought_end].include?(type) |
#to_jsonl ⇒ Object
Serialize to a JSONL line for trace logging.
25 26 27 28 29 |
# File 'lib/ollama/stream_event.rb', line 25 def to_jsonl require "json" data_val = data.respond_to?(:to_h) ? data.to_h : data JSON.generate({ type: type, model: model, data: data_val }) end |
#tool_call? ⇒ Boolean
21 |
# File 'lib/ollama/stream_event.rb', line 21 def tool_call? = %i[tool_call_start tool_call_delta].include?(type) |