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 Attribute Summary collapse

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:



18
19
20
21
22
23
# File 'lib/llm/repl/stream.rb', line 18

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

Instance Attribute Details

#toolsHash<Symbol, LLM::Tool> (readonly)

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.

Returns:



13
14
15
# File 'lib/llm/repl/stream.rb', line 13

def tools
  @tools
end

Instance Method Details

#clearvoid

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.

Clear the accumulated buffer



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

def clear
  @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



29
30
31
32
# File 'lib/llm/repl/stream.rb', line 29

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

#on_tool_call(tool) ⇒ 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:



37
38
39
40
# File 'lib/llm/repl/stream.rb', line 37

def on_tool_call(tool)
  @tools[tool.name] = tool
  @_queue.push [:status, [" ", lambda, "#{tool.name}(#{format_args(tool)})"]]
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:



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

def on_tool_return(tool, result)
  @tools.delete(tool.name)
end