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
24
# File 'lib/llm/repl/stream.rb', line 18

def initialize(repl, queue)
  @repl = repl
  @agent = @repl.agent
  @_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



62
63
64
# File 'lib/llm/repl/stream.rb', line 62

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



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

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

#on_retry(ex, attempt) ⇒ 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:

  • ex (Exception)
  • attempt (Integer)


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

def on_retry(ex, attempt)
  @_queue.push [:status, retry_error(ex, attempt)]
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:



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

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:



55
56
57
# File 'lib/llm/repl/stream.rb', line 55

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