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/walker.rb,
lib/llm/repl/window.rb,
lib/llm/repl/command.rb,
lib/llm/repl/markdown.rb,
lib/llm/repl/transcript.rb,
lib/llm/repl/commands/exit.rb,
lib/llm/repl/commands/help.rb,
lib/llm/repl/commands/compact.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, Command, Help, Input, Markdown, Status, Stream, Transcript, Walker, Window
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#status ⇒ Object
Returns the value of attribute status.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
-
#transcript ⇒ Object
readonly
Returns the value of attribute transcript.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #initialize(agent:, name: nil, tools: [], skills: [], path: nil) ⇒ LLM::Repl constructor
- #markdown(chars) ⇒ void
- #start ⇒ void
- #thinking_text ⇒ String
- #write(chars, attrs = nil) ⇒ void
Constructor Details
#initialize(agent:, name: nil, tools: [], skills: [], path: nil) ⇒ LLM::Repl
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/llm/repl.rb', line 44 def initialize(agent:, name: nil, tools: [], skills: [], path: nil) @path = path @name = name || "agent" @agent = configure(agent:, path:) @provider = agent.llm.name @status = Status.new(@agent) @transcript = Transcript.new @input = Input.new(self, 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
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def agent @agent end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def input @input end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def path @path end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def provider @provider end |
#status ⇒ Object
Returns the value of attribute status.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def status @status end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def stream @stream end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def thread @thread end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def tools @tools end |
#transcript ⇒ Object (readonly)
Returns the value of attribute transcript.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def transcript @transcript end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
28 29 30 |
# File 'lib/llm/repl.rb', line 28 def window @window end |
Instance Method Details
#markdown(chars) ⇒ void
This method returns an undefined value.
100 101 102 103 |
# File 'lib/llm/repl.rb', line 100 def markdown(chars) transcript.markdown(chars) window.redraw end |
#start ⇒ void
This method returns an undefined value.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/llm/repl.rb', line 70 def start window.open do catch(:exit) do loop do now = Process.clock_gettime(Process::CLOCK_MONOTONIC) case input.on_char(window, input.paste? ? window.read_paste : window.getch, now) when :submit then submit when Symbol then window.redraw else window.redraw read! sleep 0.01 end end end end end |
#thinking_text ⇒ String
115 116 117 |
# File 'lib/llm/repl.rb', line 115 def thinking_text "thinking • Esc to cancel" end |
#write(chars, attrs = nil) ⇒ void
This method returns an undefined value.
92 93 94 95 |
# File 'lib/llm/repl.rb', line 92 def write(chars, attrs = nil) transcript.write(chars, attrs) window.redraw end |