Class: LLM::Repl
- Inherits:
-
Object
- Object
- LLM::Repl
- Defined in:
- lib/llm/repl.rb,
lib/llm/repl/bar.rb,
lib/llm/repl/input.rb,
lib/llm/repl/status.rb,
lib/llm/repl/stream.rb,
lib/llm/repl/window.rb,
lib/llm/repl/markdown.rb,
lib/llm/repl/transcript.rb
Overview
The LLM::Repl class provides a small read-eval-print loop around an instance of LLM::Agent.
It can be used to keep talking to an agent after it has been set up or has performed a task. This can be useful when you want to confirm the agent handled the task correctly, or for it to correct course after a mistake was made.
Defined Under Namespace
Classes: Bar, Input, Markdown, Status, Stream, Transcript, Window
Instance Attribute Summary collapse
- #status ⇒ void writeonly
Instance Method Summary collapse
- #initialize(agent:, tools:, skills:) ⇒ LLM::Repl constructor
- #markdown(chars) ⇒ void
- #start ⇒ void
- #write(chars, attrs = nil) ⇒ void
Constructor Details
#initialize(agent:, tools:, skills:) ⇒ LLM::Repl
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/llm/repl.rb', line 33 def initialize(agent:, tools:, skills:) @agent = agent @provider = agent.llm.name @status = Status.new(@agent) @transcript = Transcript.new @input = Input.new(@agent, height: 3) @window = Window.new(@status, @transcript, @input) @thread = nil @queue = Queue.new @stream = Stream.new(self, @queue) @skills = skills.map do |path| ## # I'm not sure it would make sense to expose # the underlying context or not. In the meantime, # this works and meets the expectations of the # LLM::Skill class. ctx = agent.instance_variable_get(:@ctx) LLM::Skill.load(path).to_tool(ctx) end @tools = [agent.params[:tools], @skills, tools].flatten.compact end |
Instance Attribute Details
#status=(value) ⇒ void
This method returns an undefined value.
93 94 95 96 |
# File 'lib/llm/repl.rb', line 93 def status=(value) status.text = value window.redraw end |
Instance Method Details
#markdown(chars) ⇒ void
This method returns an undefined value.
85 86 87 88 |
# File 'lib/llm/repl.rb', line 85 def markdown(chars) transcript.markdown(chars) window.redraw end |
#start ⇒ void
This method returns an undefined value.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/llm/repl.rb', line 57 def start window.open do loop do case input.on_char(window, window.getch) when :exit then break when :submit then submit when :up, :down, :backspace, :char then window.redraw else window.redraw read! sleep 0.01 end end end end |
#write(chars, attrs = nil) ⇒ void
This method returns an undefined value.
77 78 79 80 |
# File 'lib/llm/repl.rb', line 77 def write(chars, attrs = nil) transcript.write(chars, attrs) window.redraw end |