Class: LLM::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/shell.rb,
lib/llm/shell/repl.rb,
lib/llm/shell/config.rb,
lib/llm/shell/command.rb,
lib/llm/shell/default.rb,
lib/llm/shell/options.rb,
lib/llm/shell/version.rb,
lib/llm/shell/markdown.rb,
lib/llm/shell/renderer.rb,
lib/llm/shell/formatter.rb,
lib/llm/shell/completion.rb,
lib/llm/shell/commands/help.rb,
lib/llm/shell/commands/show_chat.rb,
lib/llm/shell/commands/debug_mode.rb,
lib/llm/shell/commands/dir_import.rb,
lib/llm/shell/commands/enable_tool.rb,
lib/llm/shell/commands/file_import.rb,
lib/llm/shell/commands/clear_screen.rb,
lib/llm/shell/commands/disable_tool.rb,
lib/llm/shell/commands/show_version.rb,
lib/llm/shell/commands/system_prompt.rb

Defined Under Namespace

Modules: Tools Classes: Command, Completion, Config, Default, Formatter, Markdown, Options, REPL, Renderer

Constant Summary collapse

VERSION =
"0.10.0"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ LLM::Shell

Parameters:

  • opts (Hash)


98
99
100
101
102
103
# File 'lib/llm/shell.rb', line 98

def initialize(opts)
  @config  = Config.new(opts[:provider])
  @options = Options.new @config.merge(opts), Default.new(opts[:provider])
  @bot  = LLM::Bot.new(llm, options.bot)
  @repl = REPL.new(bot:, options:)
end

Class Method Details

.commandsArray<LLM::Command>

Returns:



58
59
60
# File 'lib/llm/shell.rb', line 58

def self.commands
  @commands ||= []
end

.find_command(name) ⇒ LLM::Command?

Returns an instance of LLM::Command, or nil.

Returns:



71
72
73
# File 'lib/llm/shell.rb', line 71

def self.find_command(name)
  commands.find { _1.name == name }
end

.home_configString

Returns the directory where configuration files are kept

Returns:

  • (String)


37
38
39
40
41
42
43
# File 'lib/llm/shell.rb', line 37

def self.home_config
  if ENV.key?("XDG_CONFIG_HOME")
    ENV["XDG_CONFIG_HOME"]
  else
    File.join Dir.home, ".config"
  end
end

.home_dataString

Returns the directory where commands and tools are kept

Returns:

  • (String)


48
49
50
51
52
53
54
# File 'lib/llm/shell.rb', line 48

def self.home_data
  if ENV.key?("XDG_DATA_HOME")
    File.join ENV["XDG_DATA_HOME"], ".llm-shell"
  else
    File.join Dir.home, ".local", "share", ".llm-shell"
  end
end

.pagervoid

This method returns an undefined value.

Opens a pager



84
85
86
# File 'lib/llm/shell.rb', line 84

def self.pager(...)
  IO.popen("less -FRX", "w", ...)
end

.patternRegexp

Returns:

  • (Regexp)


77
78
79
# File 'lib/llm/shell.rb', line 77

def self.pattern
  /\A<file path=(.+?)>/
end

.rootString

Returns the lib/ directory

Returns:

  • (String)


30
31
32
# File 'lib/llm/shell.rb', line 30

def self.root
  __dir__
end

.toolsArray<LLM::Tool>

Returns:



64
65
66
# File 'lib/llm/shell.rb', line 64

def self.tools
  @tools ||= []
end

Instance Method Details

#startvoid

This method returns an undefined value.

Start the shell



108
109
110
111
# File 'lib/llm/shell.rb', line 108

def start
  repl.setup
  repl.start
end