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 @options = @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 29 30 |
# File 'lib/llm/shell/repl.rb', line 23 def setup LLM::Shell.commands.each { |file| require file } Readline.completion_proc = Completion.to_proc chat .prompt, role: .default.role files.each { chat ["--- START: #{_1} ---", File.read(_1), "--- END: #{_1} ---"].join("\n") } bot..each(&:read!) clear_screen end |
#start ⇒ void
This method returns an undefined value.
Enters the main loop
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/llm/shell/repl.rb', line 35 def start loop do read eval 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 |