Class: LLM::EventHandler
- Inherits:
-
Object
- Object
- LLM::EventHandler
- Defined in:
- 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/eventhandler.rb', line 10 def initialize(parser) @parser = parser end |
Instance Method Details
#body ⇒ LLM::Object
Returns a fully constructed response body
44 |
# File 'lib/llm/eventhandler.rb', line 44 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).
33 34 35 36 37 38 39 |
# File 'lib/llm/eventhandler.rb', line 33 def on_chunk(event) return if event.end? chunk = LLM.json.load(event.chunk) return unless chunk @parser.parse!(chunk) rescue *LLM.json.parser_error end |