Class: LLM::Shell::REPL
- Inherits:
-
Object
- Object
- LLM::Shell::REPL
- Defined in:
- lib/llm/shell/repl.rb
Overview
The LLM::Shell::REPL class represents a loop that accepts user input, evaluates it via the LLM, and prints the response to stdout.
Instance Method Summary collapse
- #initialize(bot:, options:) ⇒ LLM::Shell::REPL constructor
-
#setup ⇒ void
Performs initial setup.
-
#start ⇒ void
Enters the main loop.
Constructor Details
#initialize(bot:, options:) ⇒ LLM::Shell::REPL
13 14 15 16 17 18 |
# File 'lib/llm/shell/repl.rb', line 13 def initialize(bot:, options:) @bot = bot @console = IO.console = @io = IO::Line.new($stdout) end |
Instance Method Details
#setup ⇒ void
This method returns an undefined value.
Performs initial setup
23 24 25 26 27 28 |
# File 'lib/llm/shell/repl.rb', line 23 def setup Reline.completion_proc = Completion.to_proc chat(.prompt, role: .default.role).flush unread.each(&:read!) clear_screen end |
#start ⇒ void
This method returns an undefined value.
Enters the main loop
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/llm/shell/repl.rb', line 33 def start loop do read eval while functions.any? emit rescue LLM::ResponseError => ex print Paint[ex.response.class, :red], "\n" print ex.response.body, "\n" rescue => ex print Paint[ex.class, :red], "\n" print ex., "\n" print ex.backtrace[0..5].join("\n") rescue Interrupt throw(:exit, 0) end end |