Class: LLM::EventHandler
- Inherits:
-
Object
- Object
- LLM::EventHandler
- Defined in:
- lib/llm/shell/internal/llm.rb/lib/llm/eventhandler.rb
Instance Method Summary collapse
-
#body ⇒ LLM::Object
Returns a fully constructed response body.
- #initialize(parser) ⇒ LLM::EventHandler constructor
-
#on_chunk(event) ⇒ void
Callback for when any of chunk of data is received, regardless of whether it has a field name or not.
-
#on_data(event) ⇒ void
“data:” event callback.
Constructor Details
#initialize(parser) ⇒ LLM::EventHandler
10 11 12 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventhandler.rb', line 10 def initialize(parser) @parser = parser end |
Instance Method Details
#body ⇒ LLM::Object
Returns a fully constructed response body
42 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventhandler.rb', line 42 def body = @parser.body |
#on_chunk(event) ⇒ void
This method returns an undefined value.
Callback for when any of chunk of data is received, regardless of whether it has a field name or not. Primarily for ollama, which does emit Server-Sent Events (SSE).
32 33 34 35 36 37 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventhandler.rb', line 32 def on_chunk(event) return if event.end? chunk = JSON.parse(event.chunk) @parser.parse!(chunk) rescue JSON::ParserError end |
#on_data(event) ⇒ void
This method returns an undefined value.
“data:” event callback
18 19 20 21 22 23 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/eventhandler.rb', line 18 def on_data(event) return if event.end? chunk = JSON.parse(event.value) @parser.parse!(chunk) rescue JSON::ParserError end |