Class: LLM::Repl::Stream Private

Inherits:
Stream
  • Object
show all
Defined in:
lib/llm/repl/stream.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The LLM::Repl::Stream class manages the stream for the LLM::Repl class. This class has defined hooks that receive text, tool calls, and tool returns.

Instance Method Summary collapse

Constructor Details

#initialize(repl, queue) ⇒ LLM::Repl::Stream

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:



14
15
16
17
18
# File 'lib/llm/repl/stream.rb', line 14

def initialize(repl, queue)
  @repl = repl
  @_queue = queue
  @buffer = +""
end

Instance Method Details

#empty!void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Empty the accumulated buffer



52
53
54
# File 'lib/llm/repl/stream.rb', line 52

def empty!
  @buffer.clear
end

#on_content(chars) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • chars (String)

    One or more chars



24
25
26
27
# File 'lib/llm/repl/stream.rb', line 24

def on_content(chars)
  @buffer << chars
  @_queue.push [:stream, @buffer]
end

#on_tool_call(tool, error) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:



33
34
35
36
37
38
39
# File 'lib/llm/repl/stream.rb', line 33

def on_tool_call(tool, error)
  if error
    @_queue.push [:status, "tool not found: #{tool.name}"]
  else
    @_queue.push [:status, "tool: #{tool.name}"]
  end
end

#on_tool_return(_tool, result) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:



45
46
47
# File 'lib/llm/repl/stream.rb', line 45

def on_tool_return(_tool, result)
  @_queue.push [:status, "tool done: #{result.name}"]
end